diff options
author | Wink Saville <wink@google.com> | 2009-04-10 13:01:24 -0700 |
---|---|---|
committer | Wink Saville <wink@google.com> | 2009-04-10 13:01:24 -0700 |
commit | 02d7945eb836f33f63b94fb2a556c844faf0ef8d (patch) | |
tree | 5cbcbfd147616337aebec9d72b0fd0de3bf34b64 | |
parent | 8f82a4f828c2765cc4585f9d749f5155f06fd9e9 (diff) | |
download | git-repo-02d7945eb836f33f63b94fb2a556c844faf0ef8d.tar.gz |
Add checkout command.
Teach repo how to checkout a branch in all projects or a list
of specific projects.
Bug: REPO-21
-rw-r--r-- | project.py | 14 | ||||
-rw-r--r-- | subcmds/checkout.py | 45 |
2 files changed, 59 insertions, 0 deletions
@@ -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 | |||
16 | import sys | ||
17 | from command import Command | ||
18 | |||
19 | class Checkout(Command): | ||
20 | common = True | ||
21 | helpSummary = "Checkout a branch for development" | ||
22 | helpUsage = """ | ||
23 | %prog <branchname> [<project>...] | ||
24 | |||
25 | This subcommand checks out an existing branch and | ||
26 | is equivalent to the following git command run on | ||
27 | every 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); | ||