diff options
| author | Shawn O. Pearce <sop@google.com> | 2009-04-18 15:15:24 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2009-04-18 15:15:24 -0700 |
| commit | 552ac89929db1794200290550dccdd7f3078d13f (patch) | |
| tree | 1da257e391ce65db9ba34fb954ebb9f95a1648ff | |
| parent | 89e717d9481c0c69292a39f85599f5df8277b004 (diff) | |
| download | git-repo-552ac89929db1794200290550dccdd7f3078d13f.tar.gz | |
Modify 'repo abandon' to be more like 'repo checkout' and 'repo start'
Signed-off-by: Shawn O. Pearce <sop@google.com>
| -rw-r--r-- | project.py | 40 | ||||
| -rw-r--r-- | subcmds/abandon.py | 23 |
2 files changed, 51 insertions, 12 deletions
| @@ -862,18 +862,38 @@ class Project(object): | |||
| 862 | def AbandonBranch(self, name): | 862 | def AbandonBranch(self, name): |
| 863 | """Destroy a local topic branch. | 863 | """Destroy a local topic branch. |
| 864 | """ | 864 | """ |
| 865 | try: | 865 | rev = R_HEADS + name |
| 866 | tip_rev = self.bare_git.rev_parse(R_HEADS + name) | 866 | all = self.bare_ref.all |
| 867 | except GitError: | 867 | if rev not in all: |
| 868 | return | 868 | # Doesn't exist; assume already abandoned. |
| 869 | # | ||
| 870 | return True | ||
| 871 | |||
| 872 | head = self.work_git.GetHead() | ||
| 873 | if head == rev: | ||
| 874 | # We can't destroy the branch while we are sitting | ||
| 875 | # on it. Switch to a detached HEAD. | ||
| 876 | # | ||
| 877 | head = all[head] | ||
| 869 | 878 | ||
| 870 | if self.CurrentBranch == name: | 879 | rev = self.GetRemote(self.remote.name).ToLocal(self.revision) |
| 871 | self._Checkout( | 880 | if rev in all: |
| 872 | self.GetRemote(self.remote.name).ToLocal(self.revision), | 881 | revid = all[rev] |
| 873 | quiet=True) | 882 | elif IsId(rev): |
| 883 | revid = rev | ||
| 884 | else: | ||
| 885 | revid = None | ||
| 874 | 886 | ||
| 875 | cmd = ['branch', '-D', name] | 887 | if revid and head == revid: |
| 876 | GitCommand(self, cmd, capture_stdout=True).Wait() | 888 | _lwrite(os.path.join(self.worktree, '.git', HEAD), |
| 889 | '%s\n' % revid) | ||
| 890 | else: | ||
| 891 | self._Checkout(rev, quiet=True) | ||
| 892 | |||
| 893 | return GitCommand(self, | ||
| 894 | ['branch', '-D', name], | ||
| 895 | capture_stdout = True, | ||
| 896 | capture_stderr = True).Wait() == 0 | ||
| 877 | 897 | ||
| 878 | def PruneHeads(self): | 898 | def PruneHeads(self): |
| 879 | """Prune any topic branches already merged into upstream. | 899 | """Prune any topic branches already merged into upstream. |
diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 4f976d7b..8af61327 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | import sys | 16 | import sys |
| 17 | from command import Command | 17 | from command import Command |
| 18 | from git_command import git | 18 | from git_command import git |
| 19 | from progress import Progress | ||
| 19 | 20 | ||
| 20 | class Abandon(Command): | 21 | class Abandon(Command): |
| 21 | common = True | 22 | common = True |
| @@ -38,5 +39,23 @@ It is equivalent to "git branch -D <branchname>". | |||
| 38 | print >>sys.stderr, "error: '%s' is not a valid name" % nb | 39 | print >>sys.stderr, "error: '%s' is not a valid name" % nb |
| 39 | sys.exit(1) | 40 | sys.exit(1) |
| 40 | 41 | ||
| 41 | for project in self.GetProjects(args[1:]): | 42 | nb = args[0] |
| 42 | project.AbandonBranch(nb) | 43 | err = [] |
| 44 | all = self.GetProjects(args[1:]) | ||
| 45 | |||
| 46 | pm = Progress('Abandon %s' % nb, len(all)) | ||
| 47 | for project in all: | ||
| 48 | pm.update() | ||
| 49 | if not project.AbandonBranch(nb): | ||
| 50 | err.append(project) | ||
| 51 | pm.end() | ||
| 52 | |||
| 53 | if err: | ||
| 54 | if len(err) == len(all): | ||
| 55 | print >>sys.stderr, 'error: no project has branch %s' % nb | ||
| 56 | else: | ||
| 57 | for p in err: | ||
| 58 | print >>sys.stderr,\ | ||
| 59 | "error: %s/: cannot abandon %s" \ | ||
| 60 | % (p.relpath, nb) | ||
| 61 | sys.exit(1) | ||
