From 90340618a0cbbd66525685bb9f56fb045e70609e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 10 Nov 2020 03:29:51 -0500 Subject: [PATCH] cros-repo: minor improvements --- .bin/cros-repo | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.bin/cros-repo b/.bin/cros-repo index 474b1aa..567347f 100755 --- a/.bin/cros-repo +++ b/.bin/cros-repo @@ -45,7 +45,10 @@ def expand_branch(opts): branches = [x.split()[-1].split('/')[-1] for x in ret.stdout.splitlines()] ret = [] for branch in branches: - if fnmatch.fnmatch(branch.lower(), f'*{opts.branch.lower()}*'): + if branch.lower() == opts.branch.lower(): + ret = [branch] + break + elif fnmatch.fnmatch(branch.lower(), f'*{opts.branch.lower()}*'): ret.append(branch) if not ret: print(f'error: could not match branch {opts.branch}', file=sys.stderr) @@ -59,8 +62,8 @@ def expand_branch(opts): return ret[0] -def set_git_config(opts): - """Set .git/config settings in all the repos.""" +def get_repo_topdir(opts): + """Find the top dir of this repo client checkout.""" topdir = os.getcwd() while True: rdir = os.path.join(topdir, '.repo') @@ -68,6 +71,13 @@ def set_git_config(opts): break topdir = os.path.dirname(topdir) assert topdir != '/' + return topdir + + +def set_git_config(opts): + """Set .git/config settings in all the repos.""" + topdir = get_repo_topdir(opts) + rdir = os.path.join(topdir, '.repo') def gcfg(path, *args): cmd = ['git', f'--git-dir={path}', 'config', 'user.email'] + list(args) @@ -96,7 +106,7 @@ def init_repo(opts): cmd += ['-u', EXT_MANIFEST] cmd += ['--repo-url', REPO_URL] - if opts.ref: + if opts.ref and os.path.realpath(opts.ref) != os.path.realpath(get_repo_topdir(opts)): cmd += ['--reference', opts.ref] if opts.manifest: -- 2.39.5