Chromium Code Reviews| Index: git_reparent_branch.py | 
| diff --git a/git_reparent_branch.py b/git_reparent_branch.py | 
| new file mode 100755 | 
| index 0000000000000000000000000000000000000000..3f3914f0589e5768ce90b53bf186037b2609bce9 | 
| --- /dev/null | 
| +++ b/git_reparent_branch.py | 
| @@ -0,0 +1,42 @@ | 
| +#!/usr/bin/env python | 
| +# Copyright 2014 The Chromium Authors. All rights reserved. | 
| +# Use of this source code is governed by a BSD-style license that can be | 
| +# found in the LICENSE file. | 
| + | 
| 
 
agable
2014/03/21 01:14:21
docstring
 
 | 
| +import sys | 
| + | 
| +from git_common import upstream, current_branch, run | 
| +from git_common import get_or_create_merge_base | 
| + | 
| +import subprocess2 | 
| + | 
| +def main(argv): | 
| + # TODO(iannucci): Add --verbose | 
| + # TODO(iannucci): Merge-base-tag before altering parent info. | 
| + # TODO(iannucci): Allow specification of the branch-to-reparent | 
| + | 
| + assert len(argv) == 2, "Must supply new parent" | 
| 
 
agable
2014/03/21 01:14:21
use argparse
 
 | 
| + branch = current_branch() | 
| + new_parent = argv[1] | 
| + cur_parent = upstream(branch) | 
| + assert branch != 'HEAD', 'Must be on the branch you want to reparent' | 
| + assert cur_parent != new_parent | 
| + | 
| + get_or_create_merge_base(branch, cur_parent) | 
| + | 
| + print "Reparenting %s to track %s (was %s)" % (branch, new_parent, cur_parent) | 
| + run('branch', '--set-upstream-to', new_parent, branch) | 
| + try: | 
| + subprocess2.check_call(['git', 'rebase-update']) | 
| + except: | 
| + print "Resetting parent back to %s" % (cur_parent) | 
| 
 
agable
2014/03/21 01:14:21
Print failure message in between; otherwise not cl
 
iannucci
2014/03/22 04:17:35
The rebase-update command already prints a lot of
 
 | 
| + run('branch', '--set-upstream-to', cur_parent, branch) | 
| + raise | 
| + | 
| + return 0 | 
| + | 
| + | 
| +if __name__ == '__main__': | 
| + sys.exit(main(sys.argv)) | 
| + | 
| + |