Provide 'git notes get-ref' to easily retrieve current notes ref
Script may use 'git notes get-ref' to easily retrieve the current notes ref. Suggested-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Nov 9, 2010 at 22:49 UTC
618cd75707580819f19a5f01dba406ac72219c78
3 files changed
+47
Documentation/git-notes.txt
+5
@@ -19,6 +19,7 @@ SYNOPSIS
19
'git notes' merge --abort [-v | -q]
20
'git notes' remove [<object>]
21
'git notes' prune [-n | -v]
22
+'git notes' get-ref
23
24
25
DESCRIPTION
@@ -109,6 +110,10 @@ remove::
110
prune::
111
Remove all notes for non-existing/unreachable objects.
112
113
+get-ref::
114
+ Print the current notes ref. This provides an easy way to
115
+ retrieve the current notes ref (e.g. from scripts).
116
+
117
OPTIONS
118
-------
119
-f::
builtin/notes.c
+23
@@ -31,6 +31,7 @@ static const char * const git_notes_usage[] = {
31
"git notes merge --abort [-v | -q]",
32
"git notes [--ref <notes_ref>] remove [<object>]",
33
"git notes [--ref <notes_ref>] prune [-n | -v]",
34
+ "git notes [--ref <notes_ref>] get-ref",
35
NULL
36
};
37
@@ -82,6 +83,11 @@ static const char * const git_notes_prune_usage[] = {
83
NULL
84
};
85
86
+static const char * const git_notes_get_ref_usage[] = {
87
+ "git notes get-ref",
88
+ NULL
89
+};
90
+
91
static const char note_template[] =
92
"\n"
93
"#\n"
@@ -1002,6 +1008,21 @@ static int prune(int argc, const char **argv, const char *prefix)
1008
return 0;
1009
}
1010
1011
+static int get_ref(int argc, const char **argv, const char *prefix)
1012
+{
1013
+ struct option options[] = { OPT_END() };
1014
+ argc = parse_options(argc, argv, prefix, options,
1015
+ git_notes_get_ref_usage, 0);
1016
+
1017
+ if (argc) {
1018
+ error("too many parameters");
1019
+ usage_with_options(git_notes_get_ref_usage, options);
1020
+ }
1021
+
1022
+ puts(default_notes_ref());
1023
+ return 0;
1024
+}
1025
+
1026
int cmd_notes(int argc, const char **argv, const char *prefix)
1027
{
1028
int result;
@@ -1040,6 +1061,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
1061
result = remove_cmd(argc, argv, prefix);
1062
else if (!strcmp(argv[0], "prune"))
1063
result = prune(argc, argv, prefix);
1064
+ else if (!strcmp(argv[0], "get-ref"))
1065
+ result = get_ref(argc, argv, prefix);
1066
else {
1067
result = error("Unknown subcommand: %s", argv[0]);
1068
usage_with_options(git_notes_usage, options);
t/t3301-notes.sh
+19
@@ -1058,4 +1058,23 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1058
test_must_fail git notes copy one two three
1059
'
1060
1061
+test_expect_success 'git notes get-ref (no overrides)' '
1062
+ git config --unset core.notesRef &&
1063
+ unset GIT_NOTES_REF &&
1064
+ test "$(git notes get-ref)" = "refs/notes/commits"
1065
+'
1066
+
1067
+test_expect_success 'git notes get-ref (core.notesRef)' '
1068
+ git config core.notesRef refs/notes/foo &&
1069
+ test "$(git notes get-ref)" = "refs/notes/foo"
1070
+'
1071
+
1072
+test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1073
+ test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1074
+'
1075
+
1076
+test_expect_success 'git notes get-ref (--ref)' '
1077
+ test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1078
+'
1079
+
1080
test_done