From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: johan@herland.net, jrnieder@gmail.com, bebarino@gmail.com,
avarab@gmail.com, gitster@pobox.com
Subject: [PATCHv3 21/21] Provide 'git notes get-ref' to easily retrieve current notes ref
Date: Sat, 9 Oct 2010 03:16:44 +0200 [thread overview]
Message-ID: <1286587004-3765-22-git-send-email-johan@herland.net> (raw)
In-Reply-To: <Message-Id: <1286586528-3473-1-git-send-email-johan@herland.net>
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>
---
Documentation/git-notes.txt | 5 +++++
builtin/notes.c | 23 +++++++++++++++++++++++
t/t3301-notes.sh | 19 +++++++++++++++++++
3 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 466885a..58dc378 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -19,6 +19,7 @@ SYNOPSIS
'git notes' merge --reset [-v | -q]
'git notes' remove [<object>]
'git notes' prune [-n | -v]
+'git notes' get-ref
DESCRIPTION
@@ -109,6 +110,10 @@ remove::
prune::
Remove all notes for non-existing/unreachable objects.
+get-ref::
+ Print the current notes ref. This provides an easy way to
+ retrieve the current notes ref (e.g. from scripts).
+
OPTIONS
-------
-f::
diff --git a/builtin/notes.c b/builtin/notes.c
index abf26e5..5d8c8e8 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -31,6 +31,7 @@ static const char * const git_notes_usage[] = {
"git notes merge --reset [-v | -q]",
"git notes [--ref <notes_ref>] remove [<object>]",
"git notes [--ref <notes_ref>] prune [-n | -v]",
+ "git notes [--ref <notes_ref>] get-ref",
NULL
};
@@ -82,6 +83,11 @@ static const char * const git_notes_prune_usage[] = {
NULL
};
+static const char * const git_notes_get_ref_usage[] = {
+ "git notes get-ref",
+ NULL
+};
+
static const char note_template[] =
"\n"
"#\n"
@@ -1002,6 +1008,21 @@ static int prune(int argc, const char **argv, const char *prefix)
return 0;
}
+static int get_ref(int argc, const char **argv, const char *prefix)
+{
+ struct option options[] = { OPT_END() };
+ argc = parse_options(argc, argv, prefix, options,
+ git_notes_get_ref_usage, 0);
+
+ if (argc) {
+ error("too many parameters");
+ usage_with_options(git_notes_get_ref_usage, options);
+ }
+
+ puts(default_notes_ref());
+ return 0;
+}
+
int cmd_notes(int argc, const char **argv, const char *prefix)
{
int result;
@@ -1040,6 +1061,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
result = remove_cmd(argc, argv, prefix);
else if (!strcmp(argv[0], "prune"))
result = prune(argc, argv, prefix);
+ else if (!strcmp(argv[0], "get-ref"))
+ result = get_ref(argc, argv, prefix);
else {
result = error("Unknown subcommand: %s", argv[0]);
usage_with_options(git_notes_usage, options);
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 4bf4e52..f5b72c7 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1058,4 +1058,23 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
test_must_fail git notes copy one two three
'
+test_expect_success 'git notes get-ref (no overrides)' '
+ git config --unset core.notesRef &&
+ unset GIT_NOTES_REF &&
+ test "$(git notes get-ref)" = "refs/notes/commits"
+'
+
+test_expect_success 'git notes get-ref (core.notesRef)' '
+ git config core.notesRef refs/notes/foo &&
+ test "$(git notes get-ref)" = "refs/notes/foo"
+'
+
+test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
+ test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
+'
+
+test_expect_success 'git notes get-ref (--ref)' '
+ test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
+'
+
test_done
--
1.7.3.1.104.g92b87a
prev parent reply other threads:[~2010-10-09 1:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Message-Id: <1286586528-3473-1-git-send-email-johan@herland.net>
2010-10-09 1:11 ` [PATCHv3 05/21] notes.h/c: Clarify the handling of notes objects that are == null_sha1 Johan Herland
2010-10-09 1:11 ` [PATCHv3 06/21] notes.h/c: Propagate combine_notes_fn return value to add_note() and beyond Johan Herland
2010-10-09 1:11 ` [PATCHv3 07/21] (trivial) t3303: Indent with tabs instead of spaces for consistency Johan Herland
2010-10-09 1:11 ` [PATCHv3 08/21] notes.c: Use two newlines (instead of one) when concatenating notes Johan Herland
2010-10-09 1:11 ` [PATCHv3 09/21] builtin/notes.c: Split notes ref DWIMmery into a separate function Johan Herland
2010-10-09 1:13 ` [PATCHv3 10/21] git notes merge: Initial implementation handling trivial merges only Johan Herland
2010-10-09 1:13 ` [PATCHv3 11/21] builtin/notes.c: Refactor creation of notes commits Johan Herland
2010-10-09 1:13 ` [PATCHv3 12/21] git notes merge: Handle real, non-conflicting notes merges Johan Herland
2010-10-09 1:13 ` [PATCHv3 13/21] git notes merge: Add automatic conflict resolvers (ours, theirs, union) Johan Herland
2010-10-09 1:13 ` [PATCHv3 14/21] Documentation: Preliminary docs on 'git notes merge' Johan Herland
2010-10-09 1:15 ` [PATCHv3 15/21] git notes merge: Manual conflict resolution, part 1/2 Johan Herland
2010-10-09 1:15 ` [PATCHv3 16/21] git notes merge: Manual conflict resolution, part 2/2 Johan Herland
2010-10-09 1:15 ` [PATCHv3 17/21] git notes merge: List conflicting notes in notes merge commit message Johan Herland
2010-10-09 1:15 ` [PATCHv3 18/21] git notes merge: --commit should fail if underlying notes ref has moved Johan Herland
2010-10-09 1:15 ` [PATCHv3 19/21] git notes merge: Add another auto-resolving strategy: "cat_sort_uniq" Johan Herland
2010-10-09 1:16 ` [PATCHv3 20/21] git notes merge: Add testcases for merging notes trees at different fanouts Johan Herland
2010-10-09 1:16 ` Johan Herland [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1286587004-3765-22-git-send-email-johan@herland.net \
--to=johan@herland.net \
--cc=avarab@gmail.com \
--cc=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).