| Index: pipa/build/gitdeps.py
|
| diff --git a/pipa/build/gitdeps.py b/pipa/build/gitdeps.py
|
| index 605a7112a757fc2c3ba44d8048ebce71f52731cf..0d97843e768eae5944ea5ce420a6a1f82fd7d5af 100644
|
| --- a/pipa/build/gitdeps.py
|
| +++ b/pipa/build/gitdeps.py
|
| @@ -274,11 +274,34 @@ def _GetGitOrigin(path):
|
| return None
|
|
|
|
|
| -def _GetGitHead(path):
|
| - """Returns the hash of the head of the git repo in |path|. Raises an IOError
|
| - if |path| doesn't exist or is not a git repo.
|
| +def _GetGitHead(repo):
|
| + """Returns the hash of the head of the git repo local checkout.
|
| +
|
| + Raises:
|
| + IOError: if repo's checkout directory doesn't exist or not a git repository.
|
| + """
|
| + with open(os.path.join(repo.checkout_dir, '.git', 'HEAD'), 'rb') as head:
|
| + return head.read().strip()
|
| +
|
| +
|
| +def _GetGitFetchHead(repo):
|
| + """Returns the hash of the latest fetched revision.
|
| +
|
| + Raises:
|
| + IOError: if repo's checkout directory doesn't exist or not a git repository.
|
| + KeyError: if the fetched head of the remote repository is not found in the
|
| + local checkout.
|
| """
|
| - return open(os.path.join(path, '.git', 'HEAD'), 'rb').read().strip()
|
| + path = os.path.join(repo.checkout_dir, '.git', 'FETCH_HEAD')
|
| + with open(path, 'rb') as heads_file:
|
| + for line in heads_file.readlines():
|
| + if not line.strip():
|
| + continue
|
| + head, repo_url = line.strip().split()
|
| + if repo_url == repo.repository:
|
| + return head
|
| + raise KeyError('Did not find fetched head for %s in %s' %
|
| + (repo.repository, path))
|
|
|
|
|
| def _NormalizeGitPath(path):
|
| @@ -390,21 +413,24 @@ def _UpdateCheckout(path, repo, dry_run):
|
| |dry_run| is False.
|
| """
|
| try:
|
| - # Try a checkout first. If this fails then we'll actually need to fetch
|
| - # the revision.
|
| - _LOGGER.info('Trying to checkout revision %s.', repo.revision)
|
| - _Shell('git', 'checkout', repo.revision, cwd=path,
|
| - dry_run=dry_run)
|
| - return
|
| + # If the repo has a revision specified, try a checkout first. If this fails
|
| + # then we'll actually need to fetch.
|
| + if _GIT_SHA1_RE.match(repo.revision):
|
| + _LOGGER.info('Trying to checkout revision %s.', repo.revision)
|
| + _Shell('git', 'checkout', repo.revision, cwd=path,
|
| + dry_run=dry_run)
|
| + return
|
| except RuntimeError:
|
| pass
|
|
|
| # Fetch the revision and then check it out. Let output go to screen rather
|
| # than be buffered.
|
| - _LOGGER.info('Fetching and checking out revision %s.', repo.revision)
|
| + _LOGGER.info('Fetching revision %s.', repo.revision)
|
| _Shell('git', 'fetch', '--depth=1', 'origin', repo.revision,
|
| cwd=path, dry_run=dry_run, stdout=None, stderr=None)
|
| - _Shell('git', 'checkout', repo.revision, cwd=path,
|
| + new_rev = _GetGitFetchHead(repo) if repo.revision == 'HEAD' else repo.revision
|
| + _LOGGER.info('Checking out revision %s.', new_rev)
|
| + _Shell('git', 'checkout', new_rev, cwd=path,
|
| dry_run=dry_run, stdout=None, stderr=None)
|
|
|
|
|
| @@ -515,7 +541,7 @@ def _InstallRepository(options, repo):
|
| create_checkout = False
|
|
|
| # Get the checked out revision.
|
| - revhash = _GetGitHead(repo.checkout_dir)
|
| + revhash = _GetGitHead(repo)
|
| if revhash == repo.revision:
|
| _LOGGER.debug('Checkout is already up to date.')
|
| update_checkout = False
|
|
|