Skip to content

Commit dcf783a

Browse files
trastgitster
authored andcommitted
notes: add shorthand --ref to override GIT_NOTES_REF
Adds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated. It also DWIMs a refs/notes/ prefix. Signed-off-by: Thomas Rast <[email protected]> Acked-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6360d34 commit dcf783a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Documentation/git-notes.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ OPTIONS
116116
Like '-C', but with '-c' the editor is invoked, so that
117117
the user can further edit the note message.
118118

119+
--ref <ref>::
120+
Manipulate the notes tree in <ref>. This overrides both
121+
GIT_NOTES_REF and the "core.notesRef" configuration. The ref
122+
is taken to be in `refs/notes/` if it is not qualified.
123+
119124
Author
120125
------
121126
Written by Johannes Schindelin <[email protected]> and

builtin-notes.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
447447
int given_object = 0, i = 1, retval = 0;
448448
struct msg_arg msg = { 0, 0, STRBUF_INIT };
449449
const char *rewrite_cmd = NULL;
450+
const char *override_notes_ref = NULL;
450451
struct option options[] = {
451452
OPT_GROUP("Notes options"),
452453
OPT_CALLBACK('m', "message", &msg, "MSG",
@@ -459,6 +460,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
459460
"reuse specified note object", parse_reuse_arg),
460461
OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
461462
OPT_BOOLEAN(0, "stdin", &from_stdin, "read objects from stdin"),
463+
OPT_STRING(0, "ref", &override_notes_ref, "notes_ref",
464+
"use notes from <notes_ref>"),
462465
OPT_STRING(0, "for-rewrite", &rewrite_cmd, "command",
463466
"load rewriting config for <command> (implies --stdin)"),
464467
OPT_END()
@@ -468,6 +471,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
468471

469472
argc = parse_options(argc, argv, prefix, options, git_notes_usage, 0);
470473

474+
if (override_notes_ref) {
475+
struct strbuf sb = STRBUF_INIT;
476+
if (!prefixcmp(override_notes_ref, "refs/notes/"))
477+
/* we're happy */;
478+
else if (!prefixcmp(override_notes_ref, "notes/"))
479+
strbuf_addstr(&sb, "refs/");
480+
else
481+
strbuf_addstr(&sb, "refs/notes/");
482+
strbuf_addstr(&sb, override_notes_ref);
483+
setenv("GIT_NOTES_REF", sb.buf, 1);
484+
strbuf_release(&sb);
485+
}
486+
471487
if (argc && !strcmp(argv[0], "list"))
472488
list = 1;
473489
else if (argc && !strcmp(argv[0], "add"))

0 commit comments

Comments
 (0)