launcher: avoid crash when executing out of checkout

When developing repo itself, it helps to run repo directly out of it
and to run bisection tools.  The current _SetDefaultsTo logic fails
in that situation though as it wants a branch, but the source isn't
checked out to one.  Now that we support tracking commits via the
--repo-rev setting, fall back to using the current HEAD commit.

Change-Id: I37d79fd9f7bea87d212421ebed6c8267ec95145f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/260192
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jonathan Nieder <jrn@google.com>
This commit is contained in:
Mike Frysinger 2020-03-24 02:43:46 -04:00
parent e257d56665
commit cdb344c0e7

18
repo
View File

@ -1102,12 +1102,18 @@ def _SetDefaultsTo(gitdir):
global REPO_REV global REPO_REV
REPO_URL = gitdir REPO_URL = gitdir
try: ret = run_git('--git-dir=%s' % gitdir, 'symbolic-ref', 'HEAD', check=False)
ret = run_git('--git-dir=%s' % gitdir, 'symbolic-ref', 'HEAD') if ret.returncode:
REPO_REV = ret.stdout.strip() # If we're not tracking a branch (bisect/etc...), then fall back to commit.
except CloneFailure: print('repo: warning: %s has no current branch; using HEAD' % gitdir,
print('fatal: %s has no current branch' % gitdir, file=sys.stderr) file=sys.stderr)
sys.exit(1) try:
ret = run_git('rev-parse', 'HEAD', cwd=gitdir)
except CloneFailure:
print('fatal: %s has invalid HEAD' % gitdir, file=sys.stderr)
sys.exit(1)
REPO_REV = ret.stdout.strip()
def main(orig_args): def main(orig_args):