mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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:
parent
e257d56665
commit
cdb344c0e7
12
repo
12
repo
@ -1102,13 +1102,19 @@ def _SetDefaultsTo(gitdir):
|
||||
global REPO_REV
|
||||
|
||||
REPO_URL = gitdir
|
||||
ret = run_git('--git-dir=%s' % gitdir, 'symbolic-ref', 'HEAD', check=False)
|
||||
if ret.returncode:
|
||||
# If we're not tracking a branch (bisect/etc...), then fall back to commit.
|
||||
print('repo: warning: %s has no current branch; using HEAD' % gitdir,
|
||||
file=sys.stderr)
|
||||
try:
|
||||
ret = run_git('--git-dir=%s' % gitdir, 'symbolic-ref', 'HEAD')
|
||||
REPO_REV = ret.stdout.strip()
|
||||
ret = run_git('rev-parse', 'HEAD', cwd=gitdir)
|
||||
except CloneFailure:
|
||||
print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
|
||||
print('fatal: %s has invalid HEAD' % gitdir, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
REPO_REV = ret.stdout.strip()
|
||||
|
||||
|
||||
def main(orig_args):
|
||||
cmd, opt, args = _ParseArguments(orig_args)
|
||||
|
Loading…
Reference in New Issue
Block a user