Skip to content

Commit 6827d4a

Browse files
committed
Add support for running self-tests when 9pm is a submodule
When working on 9PM while it is used as a GIT submodule in another project, .git is not a directory. Handle this case by looking up the actual .git directory: $ ls -la .git -rw-rw-r-- 1 bob bob 31 dec 1 2023 .git $ cat .git gitdir: ../../.git/modules/9pm Signed-off-by: Joachim Wiberg <[email protected]>
1 parent ee1666e commit 6827d4a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

9pm.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,20 @@ def setup_env(args):
773773
os.environ["NINEPM_CONFIG"] = args.config
774774

775775
def run_git_cmd(path, command):
776-
gitdir = os.path.join(path, '.git')
776+
git_path = os.path.join(path, '.git')
777777

778-
if not os.path.isdir(gitdir):
779-
vcprint(pcolor.orange, f"warning, no .git dir in path ({path})")
778+
if os.path.isfile(git_path):
779+
with open(git_path, 'r') as f:
780+
line = f.read().strip()
781+
if line.startswith('gitdir: '):
782+
gitdir = os.path.join(path, line[8:])
783+
else:
784+
vcprint(pcolor.orange, f"warning, invalid .git file format ({path})")
785+
return ""
786+
elif os.path.isdir(git_path):
787+
gitdir = git_path
788+
else:
789+
vcprint(pcolor.orange, f"warning, no .git dir or file in path ({path})")
780790
return ""
781791

782792
try:

0 commit comments

Comments
 (0)