summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-03-24 02:43:46 -0400
committerMike Frysinger <vapier@google.com>2020-03-25 04:56:16 +0000
commitcdb344c0e7a92e478d738e29a995726c98ae1ffb (patch)
tree4e792f93edd1c0ce025cece6b7689664c18b78b2
parente257d5666568a9621b7dfece313c705e41e17070 (diff)
downloadgit-repo-cdb344c0e7a92e478d738e29a995726c98ae1ffb.tar.gz
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>
-rwxr-xr-xrepo18
1 files changed, 12 insertions, 6 deletions
diff --git a/repo b/repo
index 12904c3e..39162eff 100755
--- a/repo
+++ b/repo
@@ -1102,12 +1102,18 @@ def _SetDefaultsTo(gitdir):
1102 global REPO_REV 1102 global REPO_REV
1103 1103
1104 REPO_URL = gitdir 1104 REPO_URL = gitdir
1105 try: 1105 ret = run_git('--git-dir=%s' % gitdir, 'symbolic-ref', 'HEAD', check=False)
1106 ret = run_git('--git-dir=%s' % gitdir, 'symbolic-ref', 'HEAD') 1106 if ret.returncode:
1107 REPO_REV = ret.stdout.strip() 1107 # If we're not tracking a branch (bisect/etc...), then fall back to commit.
1108 except CloneFailure: 1108 print('repo: warning: %s has no current branch; using HEAD' % gitdir,
1109 print('fatal: %s has no current branch' % gitdir, file=sys.stderr) 1109 file=sys.stderr)
1110 sys.exit(1) 1110 try:
1111 ret = run_git('rev-parse', 'HEAD', cwd=gitdir)
1112 except CloneFailure:
1113 print('fatal: %s has invalid HEAD' % gitdir, file=sys.stderr)
1114 sys.exit(1)
1115
1116 REPO_REV = ret.stdout.strip()
1111 1117
1112 1118
1113def main(orig_args): 1119def main(orig_args):