Skip to content

Commit

Permalink
Merge pull request #584 from launchableinc/fix-sub-process-exception
Browse files Browse the repository at this point in the history
Set shell=True to pass stdout to next command
  • Loading branch information
Konboi authored Jul 18, 2023
2 parents 6b1b4bd + ae0cc90 commit 92651bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions launchable/commands/record/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ def _get_branch_name(repo_dist: str) -> str:

branch_name = ""
try:
refs = subprocess.check_output(
"git show-ref | grep '^'$(git rev-parse HEAD)",
cwd=repo_dist).decode().split("\n")
head = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=repo_dist).decode().strip()
show_ref = subprocess.check_output(["git", "show-ref"], cwd=repo_dist).decode()
refs = [ref for ref in show_ref.split("\n") if head in ref]

if len(refs) > 0:
# e.g) ed6de84bde58d51deebe90e01ddfa5fa78899b1c refs/heads/branch-name
branch_name = refs[0].split("/")[-1]
Expand Down
8 changes: 5 additions & 3 deletions tests/commands/record/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ def test_submodule(self, mock_check_output):
mock_check_output.side_effect = [
# the first call is git rev-parse HEAD
('c50f5de0f06fe16afa4fd1dd615e4903e40b42a2').encode(),
# the second call is git rev-parse --abbrev-ref HEAD
('ed6de84bde58d51deebe90e01ddfa5fa78899b1c refs/head/main\ned6de84bde58d51deebe90e01ddfa5fa78899b1c refs/remotes/origin/main\n').encode(), # noqa: E501
# the third call is git submodule status --recursive
# the second call is git rev-parse HEAD for detect branch name
('c50f5de0f06fe16afa4fd1dd615e4903e40b42a2').encode(),
# the third call is git show-ref for detect branch name
('c50f5de0f06fe16afa4fd1dd615e4903e40b42a2 refs/head/main\nc50f5de0f06fe16afa4fd1dd615e4903e40b42a2 refs/remotes/origin/main\n').encode(), # noqa: E501
# the forth call is git submodule status --recursive
(
' 491e03096e2234dab9a9533da714fb6eff5dcaa7 foo (v1.51.0-560-g491e030)\n'
' 8bccab48338219e73c3118ad71c8c98fbd32a4be bar-zot (v1.32.0-516-g8bccab4)\n'
Expand Down

0 comments on commit 92651bb

Please sign in to comment.