summaryrefslogtreecommitdiffstats
path: root/subcmds/rebase.py
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@android.com>2010-04-01 10:42:33 -0400
committerShawn O. Pearce <sop@google.com>2010-07-15 16:35:31 -0700
commit9e426aa43231073c4a98dae3f6c16d67ab6f3b59 (patch)
treeca0591e5569e398853ddab2a873098a505f5f96b /subcmds/rebase.py
parent08a3f68d38eec81dfa66f9ea05080c37c863f322 (diff)
downloadgit-repo-9e426aa43231073c4a98dae3f6c16d67ab6f3b59.tar.gz
rebase: Automatically rebase branch on upstrea
Usage: repo rebase [[-i] <project>...] Rebases the current topic branch of the specified (or all) projects against the appropriate upstream. Note: Interactive rebase is currently only supported when exactly one project is specified on the command line. Change-Id: I7376e35f27a6585149def82938c1ca99f36db2c4 Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'subcmds/rebase.py')
-rw-r--r--subcmds/rebase.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/subcmds/rebase.py b/subcmds/rebase.py
new file mode 100644
index 00000000..44cdd2eb
--- /dev/null
+++ b/subcmds/rebase.py
@@ -0,0 +1,75 @@
1#
2# Copyright (C) 2010 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import sys
17
18from command import Command
19from git_command import GitCommand
20from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
21from error import GitError
22
23class Rebase(Command):
24 common = True
25 helpSummary = "Rebase local branches on upstream branch"
26 helpUsage = """
27%prog {[<project>...] | -i <project>...}
28"""
29 helpDescription = """
30'%prog' uses git rebase to move local changes in the current topic branch to
31the HEAD of the upstream history, useful when you have made commits in a topic
32branch but need to incorporate new upstream changes "underneath" them.
33"""
34
35 def _Options(self, p):
36 p.add_option('-i', '--interactive',
37 dest="interactive", action="store_true",
38 help="interactive rebase (single project only)")
39
40 def Execute(self, opt, args):
41 all = self.GetProjects(args)
42 one_project = len(all) == 1
43
44 if opt.interactive and not one_project:
45 print >>sys.stderr, 'error: interactive rebase not supported with multiple projects'
46 return -1
47
48 for project in all:
49 cb = project.CurrentBranch
50 if not cb:
51 if one_project:
52 print >>sys.stderr, "error: project %s has a detatched HEAD" % project.name
53 return -1
54 # ignore branches with detatched HEADs
55 continue
56
57 upbranch = project.GetBranch(cb)
58 if not upbranch.LocalMerge:
59 if one_project:
60 print >>sys.stderr, "error: project %s does not track any remote branches" % project.name
61 return -1
62 # ignore branches without remotes
63 continue
64
65 upstream = project.GetRevisionId()
66
67 args = ["rebase"]
68 if opt.interactive:
69 args.append("-i")
70 args.append(upstream)
71
72 print '# project %s: rebasing branch %s -> %s (%s)' % (
73 project.relpath, cb, upbranch.LocalMerge, upstream[0:7])
74 if GitCommand(project, args).Wait() != 0:
75 return -1