diff options
author | John L. Villalovos <john.l.villalovos@intel.com> | 2015-01-29 21:58:12 -0800 |
---|---|---|
committer | John L. Villalovos <john.l.villalovos@intel.com> | 2015-02-03 13:49:51 -0800 |
commit | 126e298214df0ce364b9dae0aec12b7b02f627ce (patch) | |
tree | 0a11ceb83a40dd2d7f5353cab84ac81d0269b87b | |
parent | 24245e00946b43d086d8bd55cf4facd00479959a (diff) | |
download | git-repo-126e298214df0ce364b9dae0aec12b7b02f627ce.tar.gz |
Handle case where 'git remote prune' needs to be run
Handle the case when this error occurs:
error: some local refs could not be updated; try running
'git remote prune origin' to remove any old, conflicting branches
This is usually caused by a reference getting changed from a file to a
directory.
For example:
Initially someone creates a branch 'foo' and it is stored as:
.git/refs/remotes/origin/foo
Then later on it is decided to change the layout structure where 'foo'
is a directory with branches below it:
.git/refs/remotes/origin/foo/master
The problem occurs when someone still has
'.git/refs/remotes/origin/foo' on their system and does a repo sync.
When this occurs the error message for needing to do a
'git remote prune origin' occurs.
Now when doing a 'git fetch' if the error message from git says that a
'git remote prune' is needed, it will do the prune and then retry the
fetch.
Change-Id: I4c6f5aa6bd932f0ef7a39134400bedd52e82f633
Signed-off-by: John L. Villalovos <john.l.villalovos@intel.com>
-rw-r--r-- | project.py | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -1871,10 +1871,22 @@ class Project(object): | |||
1871 | 1871 | ||
1872 | ok = False | 1872 | ok = False |
1873 | for _i in range(2): | 1873 | for _i in range(2): |
1874 | ret = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy).Wait() | 1874 | gitcmd = GitCommand(self, cmd, bare=True, capture_stderr=True, |
1875 | ssh_proxy=ssh_proxy) | ||
1876 | ret = gitcmd.Wait() | ||
1875 | if ret == 0: | 1877 | if ret == 0: |
1876 | ok = True | 1878 | ok = True |
1877 | break | 1879 | break |
1880 | # If needed, run the 'git remote prune' the first time through the loop | ||
1881 | elif (not _i and | ||
1882 | "error:" in gitcmd.stderr and | ||
1883 | "git remote prune" in gitcmd.stderr): | ||
1884 | prunecmd = GitCommand(self, ['remote', 'prune', name], bare=True, | ||
1885 | capture_stderr=True, ssh_proxy=ssh_proxy) | ||
1886 | if prunecmd.Wait(): | ||
1887 | print(prunecmd.stderr, file=sys.stderr) | ||
1888 | break | ||
1889 | continue | ||
1878 | elif current_branch_only and is_sha1 and ret == 128: | 1890 | elif current_branch_only and is_sha1 and ret == 128: |
1879 | # Exit code 128 means "couldn't find the ref you asked for"; if we're in sha1 | 1891 | # Exit code 128 means "couldn't find the ref you asked for"; if we're in sha1 |
1880 | # mode, we just tried sync'ing from the upstream field; it doesn't exist, thus | 1892 | # mode, we just tried sync'ing from the upstream field; it doesn't exist, thus |