Skip to content

Commit 90b30b4

Browse files
committed
app.py: improve get_git_hash to work on different working dirs
1 parent 10dc73c commit 90b30b4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

app.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ def run_git(cmd, cwd):
9797
app.logger.info("Running git: %s" % ' '.join(cmd))
9898
return subprocess.run(cmd, cwd=cwd, shell=False)
9999

100-
def get_git_hash(branch):
101-
app.logger.info("Running git rev-parse %s in %s" % (branch, sourcedir))
102-
return subprocess.check_output(['git', 'rev-parse', branch], cwd=sourcedir, encoding='utf-8', shell=False).rstrip()
100+
def get_git_hash(branch, cwd):
101+
app.logger.info("Running git rev-parse %s in %s" % (branch, cwd))
102+
return subprocess.check_output(['git', 'rev-parse', branch], cwd=cwd, encoding='utf-8', shell=False).rstrip()
103103

104-
def on_branch(branch):
105-
git_hash_target = get_git_hash(branch)
104+
def on_branch(branch, cwd):
105+
git_hash_target = get_git_hash(branch, cwd)
106106
app.logger.info("Expected branch git-hash '%s'" % git_hash_target)
107-
git_hash_current = get_git_hash('HEAD')
107+
git_hash_current = get_git_hash('HEAD', cwd)
108108
app.logger.info("Current branch git-hash '%s'" % git_hash_current)
109109
return git_hash_target == git_hash_current
110110

@@ -119,7 +119,7 @@ def checkout_branch(targetBranch, s_dir, fetch_and_reset=False, temp_branch_name
119119
app.logger.error("Checkout requested for an invalid branch")
120120
return None
121121
remote = targetBranch.split('/', 1)[0]
122-
if not on_branch(targetBranch):
122+
if not on_branch(targetBranch, cwd=s_dir):
123123
app.logger.info("Checking out to %s branch" % targetBranch)
124124
run_git(['git', 'checkout', targetBranch], cwd=s_dir)
125125
if fetch_and_reset:
@@ -128,7 +128,7 @@ def checkout_branch(targetBranch, s_dir, fetch_and_reset=False, temp_branch_name
128128
if temp_branch_name is not None:
129129
delete_branch(temp_branch_name, s_dir=s_dir) # delete temp branch if it already exists
130130
run_git(['git', 'checkout', '-b', temp_branch_name, targetBranch], cwd=s_dir) # creates new temp branch
131-
git_hash = get_git_hash('HEAD')
131+
git_hash = get_git_hash('HEAD', cwd=s_dir)
132132
return git_hash
133133

134134
def clone_branch(targetBranch, sourcedir, out_dir, temp_branch_name):
@@ -584,7 +584,7 @@ def generate():
584584
os.path.join(outdir_parent, 'extra_hwdef.dat'))
585585
os.remove(os.path.join(outdir_parent, 'extra_hwdef.dat'))
586586

587-
new_git_hash = get_git_hash(chosen_branch)
587+
new_git_hash = get_git_hash(chosen_branch, sourcedir)
588588
git_hash_short = new_git_hash[:10]
589589
app.logger.info('Git hash = ' + new_git_hash)
590590
selected_features_dict['git_hash_short'] = git_hash_short

0 commit comments

Comments
 (0)