Skip to content

Commit 5e4e467

Browse files
troglobitrical
authored andcommitted
Fix annoying warnings when running in a container
This is a follow-up to 07f28a4 which added support for figuring out the GIT revision when 9pm is a submodule in another proejct. However, that project in turn may be a git worktree, where the actual .git directory is elsewhere, and when said project is running its tests from a Docker container, things get worse. It is very likely that the actual .git directory is unreachable from within the container. This patch hides the following annoying warnings: warning, git command failed (Command '['git', '--git-dir', '/home/jocke/src/x-misc/test/9pm/../../../infix/.git/worktrees/x-misc/modules/9pm', 'rev-parse', 'HEAD']' returned non-zero exit status 128.) 9PM - Simplicity is the ultimate sophistication warning, git command failed (Command '['git', '--git-dir', '/home/jocke/src/infix/.git/worktrees/x-misc', 'rev-parse', 'HEAD']' returned non-zero exit status 128.) Testing Infix Running suite 0001 all.yaml Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 5530cb4 commit 5e4e467

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

9pm.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,20 +700,21 @@ def run_git_cmd(path, command):
700700
with open(git_path, 'r') as f:
701701
line = f.read().strip()
702702
if line.startswith('gitdir: '):
703-
gitdir = os.path.join(path, line[8:])
703+
git_path = os.path.join(path, line[8:])
704+
if not os.path.exists(git_path):
705+
return ""
704706
else:
705707
vcprint(pcolor.orange, f"warning, invalid .git file format ({path})")
706708
return ""
707-
elif os.path.isdir(git_path):
708-
gitdir = git_path
709-
else:
709+
710+
if not os.path.isdir(git_path):
710711
vcprint(pcolor.orange, f"warning, no .git dir or file in path ({path})")
711712
return ""
712713

713714
try:
714-
vcprint(pcolor.faint, f"Running: git --git-dir {gitdir} {command}")
715+
vcprint(pcolor.faint, f"Running: git --git-dir {git_path} {command}")
715716
result = subprocess.check_output(
716-
['git', '--git-dir', gitdir] + command,
717+
['git', '--git-dir', git_path] + command,
717718
stderr=subprocess.STDOUT
718719
).decode('utf-8').strip()
719720
except Exception as e:

0 commit comments

Comments
 (0)