From 0cb1b3f687da4634e431953ef84fee59dd3f5d59 Mon Sep 17 00:00:00 2001 From: Julius Gustavsson Date: Thu, 17 Jun 2010 17:55:02 +0200 Subject: [PATCH] sync: Try fetching a tag as a last resort before giving up If a tagged commit is not reachable by the fetch refspec configured for the git (usually refs/heads/*) it will not be downloaded by 'git fetch'. The tag can however be downloaded with 'git fetch --tags' or 'git fetch tag '. This patch fixes the situation when a tag is not found after a 'git fetch'. Repo will issue 'git fetch tag ' before giving up completely. Change-Id: I87796a5e1d51fcf398f346a274b7a069df37599a Signed-off-by: Shawn O. Pearce --- project.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/project.py b/project.py index 1bcd9596..956f45bf 100644 --- a/project.py +++ b/project.py @@ -283,7 +283,7 @@ class Project(object): return os.path.exists(os.path.join(g, 'rebase-apply')) \ or os.path.exists(os.path.join(g, 'rebase-merge')) \ or os.path.exists(os.path.join(w, '.dotest')) - + def IsDirty(self, consider_untracked=True): """Is the working directory modified in some way? """ @@ -416,7 +416,7 @@ class Project(object): try: f = df[p] except KeyError: f = None - + if i: i_status = i.status.upper() else: i_status = '-' @@ -601,6 +601,18 @@ class Project(object): if not self._RemoteFetch(): return False + #Check that the requested ref was found after fetch + # + try: + self.GetRevisionId() + except ManifestInvalidRevisionError: + # if the ref is a tag. We can try fetching + # the tag manually as a last resort + # + rev = self.revisionExpr + if rev.startswith(R_TAGS): + self._RemoteFetch(None, rev[len(R_TAGS):]) + if self.worktree: self._InitMRef() else: @@ -982,7 +994,7 @@ class Project(object): ## Direct Git Commands ## - def _RemoteFetch(self, name=None): + def _RemoteFetch(self, name=None, tag=None): if not name: name = self.remote.name @@ -994,6 +1006,9 @@ class Project(object): if not self.worktree: cmd.append('--update-head-ok') cmd.append(name) + if tag is not None: + cmd.append('tag') + cmd.append(tag) return GitCommand(self, cmd, bare = True,