summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py14
-rw-r--r--subcmds/checkout.py45
2 files changed, 59 insertions, 0 deletions
diff --git a/project.py b/project.py
index 8ed61551..24254676 100644
--- a/project.py
+++ b/project.py
@@ -733,6 +733,20 @@ class Project(object):
733 else: 733 else:
734 raise GitError('%s checkout %s ' % (self.name, rev)) 734 raise GitError('%s checkout %s ' % (self.name, rev))
735 735
736 def CheckoutBranch(self, name):
737 """Checkout a local topic branch.
738 """
739
740 # Be sure the branch exists
741 try:
742 tip_rev = self.bare_git.rev_parse(R_HEADS + name)
743 except GitError:
744 return False;
745
746 # Do the checkout
747 cmd = ['checkout', name, '--']
748 return GitCommand(self, cmd, capture_stdout=True).Wait() == 0
749
736 def AbandonBranch(self, name): 750 def AbandonBranch(self, name):
737 """Destroy a local topic branch. 751 """Destroy a local topic branch.
738 """ 752 """
diff --git a/subcmds/checkout.py b/subcmds/checkout.py
new file mode 100644
index 00000000..7ce9d341
--- /dev/null
+++ b/subcmds/checkout.py
@@ -0,0 +1,45 @@
1#
2# Copyright (C) 2009 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
17from command import Command
18
19class Checkout(Command):
20 common = True
21 helpSummary = "Checkout a branch for development"
22 helpUsage = """
23%prog <branchname> [<project>...]
24
25This subcommand checks out an existing branch and
26is equivalent to the following git command run on
27every project or the list of specified projects:
28
29"git checkout <branchname>"
30"""
31
32 def Execute(self, opt, args):
33 if not args:
34 self.Usage()
35
36 retValue = 0;
37
38 branch = args[0]
39 for project in self.GetProjects(args[1:]):
40 if not project.CheckoutBranch(branch):
41 retValue = 1;
42 print >>sys.stderr, "error: checking out branch '%s' in %s failed" % (branch, project.name)
43
44 if (retValue != 0):
45 sys.exit(retValue);