Ensure HEAD is correct when skipping remote fetch

A recent optimization (2fb6466f79) skips
performing a remote fetch if we already know we have the sha1 we want.
However, that optimization skipped initialization steps that ensure HEAD
points to the correct sha1.  This change makes sure not to skip those
steps.

Here is an example of how to test this change:

"""""""""
url=<manifest url>
branch1=<branch name>
branch2=<branch name>
project=<project with revision set to different sha1 in each branch>

repo init -u $url -b $branch1 --mirror
repo sync $project
first=$(cd $project.git; git rev-parse HEAD)

repo init -b $branch2
repo sync $project
second=$(cd platform/build.git; git rev-parse HEAD)

if [[ $first == $second ]]
then
    echo 'problem!'
else
    echo 'no problem!'
fi
"""""""""
This commit is contained in:
Conley Owens 2014-05-01 13:09:57 -07:00
parent f2af756425
commit 666d534636

View File

@ -1103,16 +1103,11 @@ class Project(object):
elif self.manifest.default.sync_c:
current_branch_only = True
is_sha1 = False
if ID_RE.match(self.revisionExpr) is not None:
is_sha1 = True
if is_sha1 and self._CheckForSha1():
# Don't need to fetch since we already have this revision
return True
if not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir,
has_sha1 = ID_RE.match(self.revisionExpr) and self._CheckForSha1()
if (not has_sha1 #Need to fetch since we don't already have this revision
and not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir,
current_branch_only=current_branch_only,
no_tags=no_tags):
no_tags=no_tags)):
return False
if self.worktree: