Skip to content

Commit 2e54cc2

Browse files
committed
Add test for git directories owned by different users
1 parent 6a3bb96 commit 2e54cc2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

testing/test_git.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import shutil
3+
import subprocess
24
import sys
35
from datetime import date
46
from datetime import datetime
@@ -92,6 +94,42 @@ def test_parse_call_order(wd):
9294
git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE)
9395

9496

97+
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/707")
98+
def test_not_owner(wd):
99+
git_dir = opj(wd.cwd)
100+
original_stat = os.stat(git_dir)
101+
if not shutil.which("sudo"):
102+
pytest.skip("sudo executable not found")
103+
104+
proc = subprocess.run(
105+
["sudo", "chown", "-R", "12345", git_dir], stdin=subprocess.DEVNULL
106+
)
107+
if proc.returncode != 0:
108+
pytest.skip("Failed to change ownership, is passwordless sudo available?")
109+
try:
110+
subprocess.run(
111+
["sudo", "chmod", "a+r", git_dir], stdin=subprocess.DEVNULL, check=True
112+
)
113+
subprocess.run(
114+
["sudo", "chgrp", "-R", "12345", git_dir],
115+
stdin=subprocess.DEVNULL,
116+
check=True,
117+
)
118+
assert git.parse(str(wd.cwd))
119+
finally:
120+
# Restore the ownership
121+
subprocess.run(
122+
["sudo", "chown", "-R", str(original_stat.st_uid), git_dir],
123+
stdin=subprocess.DEVNULL,
124+
check=True,
125+
)
126+
subprocess.run(
127+
["sudo", "chgrp", "-R", str(original_stat.st_gid), git_dir],
128+
stdin=subprocess.DEVNULL,
129+
check=True,
130+
)
131+
132+
95133
def test_version_from_git(wd):
96134
assert wd.version == "0.1.dev0"
97135

0 commit comments

Comments
 (0)