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 <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed Aug 17, 2015 at 14:33 UTC 4f655e22b76fed49b0c32bcdcd899934215b9a6d
4 files changed +64 -1
Documentation/config.txt
+6
@@ -1892,6 +1892,12 @@ notes.mergeStrategy::
1892 `cat_sort_uniq`. Defaults to `manual`. See "NOTES MERGE STRATEGIES"
1893 section of linkgit:git-notes[1] for more information on each strategy.
1894
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 +
1901 notes.displayRef::
1902 The (fully qualified) refname from which to show notes when
1903 showing commit messages. The value of this variable can be set
Documentation/git-notes.txt
+6
@@ -322,6 +322,12 @@ notes.mergeStrategy::
322 +
323 This setting can be overridden by passing the `--strategy` option.
324
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 +
331 notes.displayRef::
332 Which ref (or refs, if a glob or specified more than once), in
333 addition to the default set by `core.notesRef` or
builtin/notes.c
+13 -1
@@ -816,7 +816,19 @@ static int merge(int argc, const char **argv, const char *prefix)
816 usage_with_options(git_notes_merge_usage, options);
817 }
818 } 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);
832 }
833
834 strbuf_addf(&msg, "notes: Merged notes from %s into %s",
t/t3309-notes-merge-auto-resolve.sh
+39
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
383 verify_notes y y
384 '
385
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 +
397 cat <<EOF | sort >expect_notes_theirs
398 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
399 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -534,6 +545,34 @@ test_expect_success 'reset to pre-merge state (y)' '
545 verify_notes y y
546 '
547
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 +
576 cat <<EOF | sort >expect_notes_union2
577 d682107b8bf7a7aea1e537a8d5cb6a12b60135f1 $commit_sha15
578 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14