Skip to content

Commit f8f4d9b

Browse files
committed
cmd/git(fix[GitNotesManager.merge]): Handle commit/abort forms correctly
why: Git's `notes merge` has three mutually exclusive forms that were not properly supported - the API required notes_ref always, but --commit and --abort forms take no ref argument. what: - Make notes_ref optional (None default) - Add validation for mutual exclusivity of commit, abort, and notes_ref - Only append notes_ref when provided and not using commit/abort - Prevent strategy from being used with commit/abort
1 parent 911dd2c commit f8f4d9b

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

src/libvcs/cmd/git.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7383,7 +7383,7 @@ def prune(
73837383

73847384
def merge(
73857385
self,
7386-
notes_ref: str,
7386+
notes_ref: str | None = None,
73877387
*,
73887388
strategy: str | None = None,
73897389
commit: bool = False,
@@ -7396,16 +7396,24 @@ def merge(
73967396
) -> str:
73977397
"""Merge notes from another ref.
73987398
7399+
Git notes merge has three mutually exclusive forms:
7400+
7401+
1. ``git notes merge [-s <strategy>] <notes-ref>`` - Start a merge
7402+
2. ``git notes merge --commit`` - Finalize in-progress merge
7403+
3. ``git notes merge --abort`` - Abort in-progress merge
7404+
73997405
Parameters
74007406
----------
74017407
notes_ref :
7402-
Notes ref to merge from.
7408+
Notes ref to merge from. Required for starting a merge,
7409+
must be None when using commit or abort.
74037410
strategy :
74047411
Merge strategy (manual, ours, theirs, union, cat_sort_uniq).
7412+
Only valid when starting a merge with notes_ref.
74057413
commit :
7406-
Finalize in-progress merge.
7414+
Finalize in-progress merge. Cannot be combined with abort or notes_ref.
74077415
abort :
7408-
Abort in-progress merge.
7416+
Abort in-progress merge. Cannot be combined with commit or notes_ref.
74097417
quiet :
74107418
Suppress output.
74117419
verbose :
@@ -7419,6 +7427,22 @@ def merge(
74197427
>>> 'error' in result.lower() or 'fatal' in result.lower() or result == ''
74207428
True
74217429
"""
7430+
# Validate mutual exclusivity
7431+
if commit and abort:
7432+
msg = "Cannot specify both commit and abort"
7433+
raise ValueError(msg)
7434+
7435+
if commit or abort:
7436+
if notes_ref is not None:
7437+
msg = "Cannot specify notes_ref with --commit or --abort"
7438+
raise ValueError(msg)
7439+
if strategy is not None:
7440+
msg = "Cannot specify strategy with --commit or --abort"
7441+
raise ValueError(msg)
7442+
elif notes_ref is None:
7443+
msg = "notes_ref is required when not using --commit or --abort"
7444+
raise ValueError(msg)
7445+
74227446
local_flags: list[str] = []
74237447

74247448
if strategy is not None:
@@ -7432,7 +7456,8 @@ def merge(
74327456
if verbose:
74337457
local_flags.append("-v")
74347458

7435-
local_flags.append(notes_ref)
7459+
if notes_ref is not None:
7460+
local_flags.append(notes_ref)
74367461

74377462
return self.run(
74387463
"merge",

0 commit comments

Comments
 (0)