Skip to content

Commit 4f655e2

Browse files
jacob-kellergitster
authored andcommitted
notes: teach git-notes about notes.<name>.mergeStrategy option
Teach notes about a new "notes.<name>.mergeStrategy" option for configuring the notes merge strategy when merging into refs/notes/<name>. This option allows for the selection of merge strategy for particular notes refs, rather than all notes ref merges, as user may not want cat_sort_uniq for all refs, but only some. Note that the <name> is the local reference we are merging into, not the remote ref we merged from. The assumption is that users will mostly want to configure separate local ref merge strategies rather than strategies depending on which remote ref they merge from. notes.<name>.mergeStrategy overrides the general behavior as it is more specific. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2d68d9 commit 4f655e2

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,12 @@ notes.mergeStrategy::
18921892
`cat_sort_uniq`. Defaults to `manual`. See "NOTES MERGE STRATEGIES"
18931893
section of linkgit:git-notes[1] for more information on each strategy.
18941894

1895+
notes.<name>.mergeStrategy::
1896+
Which merge strategy to choose when doing a notes merge into
1897+
refs/notes/<name>. This overrides the more general
1898+
"notes.mergeStrategy". See the "NOTES MERGE STRATEGIES" section in
1899+
linkgit:git-notes[1] for more information on the available strategies.
1900+
18951901
notes.displayRef::
18961902
The (fully qualified) refname from which to show notes when
18971903
showing commit messages. The value of this variable can be set

Documentation/git-notes.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ notes.mergeStrategy::
322322
+
323323
This setting can be overridden by passing the `--strategy` option.
324324

325+
notes.<name>.mergeStrategy::
326+
Which merge strategy to choose when doing a notes merge into
327+
refs/notes/<name>. This overrides the more general
328+
"notes.mergeStrategy". See the "NOTES MERGE STRATEGIES" section above
329+
for more information on each available strategy.
330+
325331
notes.displayRef::
326332
Which ref (or refs, if a glob or specified more than once), in
327333
addition to the default set by `core.notesRef` or

builtin/notes.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,19 @@ static int merge(int argc, const char **argv, const char *prefix)
816816
usage_with_options(git_notes_merge_usage, options);
817817
}
818818
} else {
819-
git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy);
819+
struct strbuf merge_key = STRBUF_INIT;
820+
const char *short_ref = NULL;
821+
822+
if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref))
823+
die("BUG: local ref %s is outside of refs/notes/",
824+
o.local_ref);
825+
826+
strbuf_addf(&merge_key, "notes.%s.mergeStrategy", short_ref);
827+
828+
if (git_config_get_notes_strategy(merge_key.buf, &o.strategy))
829+
git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy);
830+
831+
strbuf_release(&merge_key);
820832
}
821833

822834
strbuf_addf(&msg, "notes: Merged notes from %s into %s",

t/t3309-notes-merge-auto-resolve.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
383383
verify_notes y y
384384
'
385385

386+
test_expect_success 'merge z into y with "ours" per-ref configuration option => Non-conflicting 3-way merge' '
387+
git -c notes.y.mergeStrategy="ours" notes merge z &&
388+
verify_notes y ours
389+
'
390+
391+
test_expect_success 'reset to pre-merge state (y)' '
392+
git update-ref refs/notes/y refs/notes/y^1 &&
393+
# Verify pre-merge state
394+
verify_notes y y
395+
'
396+
386397
cat <<EOF | sort >expect_notes_theirs
387398
9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
388399
5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -534,6 +545,34 @@ test_expect_success 'reset to pre-merge state (y)' '
534545
verify_notes y y
535546
'
536547

548+
test_expect_success 'merge z into y with "union" strategy overriding per-ref configuration => Non-conflicting 3-way merge' '
549+
git -c notes.y.mergeStrategy="theirs" notes merge --strategy=union z &&
550+
verify_notes y union
551+
'
552+
553+
test_expect_success 'reset to pre-merge state (y)' '
554+
git update-ref refs/notes/y refs/notes/y^1 &&
555+
# Verify pre-merge state
556+
verify_notes y y
557+
'
558+
559+
test_expect_success 'merge z into y with "union" per-ref overriding general configuration => Non-conflicting 3-way merge' '
560+
git -c notes.y.mergeStrategy="union" -c notes.mergeStrategy="theirs" notes merge z &&
561+
verify_notes y union
562+
'
563+
564+
test_expect_success 'reset to pre-merge state (y)' '
565+
git update-ref refs/notes/y refs/notes/y^1 &&
566+
# Verify pre-merge state
567+
verify_notes y y
568+
'
569+
570+
test_expect_success 'merge z into y with "manual" per-ref only checks specific ref configuration => Conflicting 3-way merge' '
571+
test_must_fail git -c notes.z.mergeStrategy="union" notes merge z &&
572+
git notes merge --abort &&
573+
verify_notes y y
574+
'
575+
537576
cat <<EOF | sort >expect_notes_union2
538577
d682107b8bf7a7aea1e537a8d5cb6a12b60135f1 $commit_sha15
539578
5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14

0 commit comments

Comments
 (0)