summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-09-11 18:43:17 -0400
committerMike Frysinger <vapier@google.com>2019-11-16 19:55:02 +0000
commit6da17751ca4e3b90834ca763f448ddc39b32651b (patch)
tree4962f9913b689de734d3d11e981d3a2e18841504 /project.py
parent2ba5a1e96347e735b12998c057a6c1eed79712e9 (diff)
downloadgit-repo-6da17751ca4e3b90834ca763f448ddc39b32651b.tar.gz
prune: handle branches that track missing branches
Series of steps: * Create a local "b1" branch with `repo start b1` that tracks a remote branch (totally fine) * Manually create a local "b2" branch with `git branch --track b1 b2` that tracks the local "b1" (uh-oh...) * Delete the local "b1" branch manually or via `repo prune` (....) * Try to process the "b2" branch with `repo prune` Since b2 tracks a branch that no longer exists, everything blows up at this point as we try to probe the non-existent ref. Instead, we should flag this as unknown and leave it up to the user to resolve. This probably could come up if a local branch was tracking a remote branch that was deleted from the server, and users ran something like `repo sync --prune` which cleaned up the remote refs. Bug: https://crbug.com/gerrit/11485 Change-Id: I6b6b6041943944b8efa6e2ad0b8b10f13a75a5c2 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/236793 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Reviewed-by: Kirtika Ruchandani <kirtika@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'project.py')
-rwxr-xr-xproject.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/project.py b/project.py
index 5ffa5424..7811d6ba 100755
--- a/project.py
+++ b/project.py
@@ -134,6 +134,7 @@ class DownloadedChange(object):
134 134
135class ReviewableBranch(object): 135class ReviewableBranch(object):
136 _commit_cache = None 136 _commit_cache = None
137 _base_exists = None
137 138
138 def __init__(self, project, branch, base): 139 def __init__(self, project, branch, base):
139 self.project = project 140 self.project = project
@@ -147,14 +148,19 @@ class ReviewableBranch(object):
147 @property 148 @property
148 def commits(self): 149 def commits(self):
149 if self._commit_cache is None: 150 if self._commit_cache is None:
150 self._commit_cache = self.project.bare_git.rev_list('--abbrev=8', 151 args = ('--abbrev=8', '--abbrev-commit', '--pretty=oneline', '--reverse',
151 '--abbrev-commit', 152 '--date-order', not_rev(self.base), R_HEADS + self.name, '--')
152 '--pretty=oneline', 153 try:
153 '--reverse', 154 self._commit_cache = self.project.bare_git.rev_list(*args)
154 '--date-order', 155 except GitError:
155 not_rev(self.base), 156 # We weren't able to probe the commits for this branch. Was it tracking
156 R_HEADS + self.name, 157 # a branch that no longer exists? If so, return no commits. Otherwise,
157 '--') 158 # rethrow the error as we don't know what's going on.
159 if self.base_exists:
160 raise
161
162 self._commit_cache = []
163
158 return self._commit_cache 164 return self._commit_cache
159 165
160 @property 166 @property
@@ -173,6 +179,23 @@ class ReviewableBranch(object):
173 R_HEADS + self.name, 179 R_HEADS + self.name,
174 '--') 180 '--')
175 181
182 @property
183 def base_exists(self):
184 """Whether the branch we're tracking exists.
185
186 Normally it should, but sometimes branches we track can get deleted.
187 """
188 if self._base_exists is None:
189 try:
190 self.project.bare_git.rev_parse('--verify', not_rev(self.base))
191 # If we're still here, the base branch exists.
192 self._base_exists = True
193 except GitError:
194 # If we failed to verify, the base branch doesn't exist.
195 self._base_exists = False
196
197 return self._base_exists
198
176 def UploadForReview(self, people, 199 def UploadForReview(self, people,
177 auto_topic=False, 200 auto_topic=False,
178 draft=False, 201 draft=False,