Skip to content

Commit 2ac25e9

Browse files
committed
commit: separate paths from revisions in git argv
`pkgdev commit main` failed with "ambiguous argument 'main': both revision and filename" whenever a committed path shared its name with a ref. Pass -- before the paths, and --end-of-options before HEAD, so a path is always read as a path. Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent feaa457 commit 2ac25e9

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎NEWS.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ pkgdev 0.2.19 (unreleased)
1414
- bugs: fix a package being filed as its own dependency, when an unsolvable
1515
``|| ( ... )`` is answered by the package's own slot (Arthur Zamarin, #208)
1616

17+
**pkgdev commit:**
18+
19+
- commit: a path argument sharing its name with a ref, e.g. ``pkgdev commit
20+
main``, no longer fails as an ambiguous git argument (Arthur Zamarin)
21+
1722
pkgdev 0.2.18 (2026-09-05)
1823
--------------------------
1924

‎src/pkgdev/scripts/pkgdev_commit.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def __init__(self, tmpdir, *args, **kwargs):
302302
def _extract_historical(repo, path: str, keys: Iterable[str]):
303303
"""Extract the packages as they are in HEAD into a directory."""
304304
old_files = subprocess.Popen(
305-
["git", "archive", "HEAD", *keys],
305+
["git", "archive", "--end-of-options", "HEAD", *keys],
306306
stdout=subprocess.PIPE,
307307
stderr=subprocess.PIPE,
308308
cwd=repo.location,
@@ -637,7 +637,7 @@ def _generate_mapping(self):
637637
"""Generate mapping for staged changes."""
638638
# stage changes as requested
639639
if self._options.git_add_arg:
640-
git.run("add", self._options.git_add_arg, self._options.cwd)
640+
git.run("add", self._options.git_add_arg, "--", self._options.cwd)
641641

642642
# determine staged changes forcing rename search
643643
p = git.run(
@@ -647,7 +647,9 @@ def _generate_mapping(self):
647647
"--name-status",
648648
"--cached",
649649
"-z",
650+
"--end-of-options",
650651
"HEAD",
652+
"--",
651653
*self._options.git_args_paths,
652654
stdout=subprocess.PIPE,
653655
)
@@ -922,6 +924,7 @@ def update_manifests(options, out, err, changes):
922924
"--porcelain=v1",
923925
"-u",
924926
"-z",
927+
"--",
925928
"*.ebuild",
926929
cwd=repo.location,
927930
stdout=subprocess.PIPE,
@@ -972,7 +975,7 @@ def _commit(options, out, err):
972975

973976
# stage modified files
974977
if options.git_add_files:
975-
git.run("add", *options.git_add_files, cwd=repo.location)
978+
git.run("add", "--", *options.git_add_files, cwd=repo.location)
976979

977980
# scan staged changes for QA issues if requested
978981
if options.scan:

‎src/pkgdev/scripts/pkgdev_manifest.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ def _restrict_targets(repo, targets):
103103
def _restrict_modified_files(repo):
104104
ebuild_re = re.compile(r"^[ MTARC?]{2} (?P<path>[^/]+/[^/]+/[^/]+\.ebuild)$")
105105
p = git.run(
106-
"status", "--porcelain=v1", "-z", "*.ebuild", cwd=repo.location, stdout=subprocess.PIPE
106+
"status",
107+
"--porcelain=v1",
108+
"-z",
109+
"--",
110+
"*.ebuild",
111+
cwd=repo.location,
112+
stdout=subprocess.PIPE,
107113
)
108114

109115
restrictions = []

‎tests/scripts/test_pkgdev_commit.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,24 @@ def test_empty_repo(self, capsys, repo, make_git_repo):
240240
assert not out
241241
assert err.strip() == "pkgdev commit: error: no staged changes exist"
242242

243+
def test_path_matching_ref_name(self, repo, make_git_repo):
244+
"""A path argument sharing its name with a ref is still a path."""
245+
git_repo = make_git_repo(repo.location, commit=True)
246+
# 'main' names both the branch and the file being committed
247+
path = pjoin(git_repo.path, "main")
248+
with open(path, "w") as f:
249+
f.write("data\n")
250+
git_repo.add_all("main", commit=False)
251+
252+
with (
253+
patch("sys.argv", self.args + ["-m", "add main", "main"]),
254+
pytest.raises(SystemExit) as excinfo,
255+
chdir(git_repo.path),
256+
):
257+
self.script()
258+
assert excinfo.value.code == 0
259+
assert git_repo.log(["--pretty=tformat:%s", "-1"]) == ["main: add main"]
260+
243261
def test_git_message_opts(self, repo, make_git_repo, tmp_path):
244262
"""Verify message-related options are passed through to `git commit`."""
245263
git_repo = make_git_repo(repo.location, commit=True)

0 commit comments

Comments
 (0)