git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 4/4] notes: refuse to edit notes outside refs/notes/
Date: Sat, 14 Feb 2009 20:15:06 +0100	[thread overview]
Message-ID: <ac3c2ce272e8e7f3000349f682a5a4843aea34e6.1234638466.git.trast@student.ethz.ch> (raw)
In-Reply-To: <b36bbe2f7f0ede6a2caa47190ada868dd4c0099c.1234638466.git.trast@student.ethz.ch>

The current git-notes has no safety valves whatsoever, and will
happily edit notes in, e.g., refs/remotes/.  This is dangerous, as
they will be overwritten during the next fetch of the remote they
belong to.

Since it is supposed to be a plumbing frontend for the notes feature,
simply forbid editing notes with GIT_NOTES_REF pointing anywhere but
refs/notes/*.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

This is the only patch of substance in this series :-)

I'm not sure if anyone uses a notes ref outside of refs/notes/ yet, so
this may actually break some people's setups already.  But now that we
(at least me :-) offer notes for download in public repos, I can see
people accidentally edit a remote notes ref.


 git-notes.sh     |    4 ++++
 t/t3301-notes.sh |    8 ++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/git-notes.sh b/git-notes.sh
index 6859470..6ec33c9 100755
--- a/git-notes.sh
+++ b/git-notes.sh
@@ -16,6 +16,10 @@ die "Invalid commit: $@"
 
 case "$ACTION" in
 edit)
+	if [ "${GIT_NOTES_REF#refs/notes/}" = "$GIT_NOTES_REF" ]; then
+		die "Refusing to edit notes in $GIT_NOTES_REF (outside of refs/notes/)"
+	fi
+
 	MESSAGE="$GIT_DIR"/new-notes-$COMMIT
 	trap '
 		test -f "$MESSAGE" && rm "$MESSAGE"
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index b99271e..1503e79 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -35,6 +35,14 @@ test_expect_success 'need valid notes ref' '
 	! GIT_NOTES_REF=/ git notes show
 '
 
+test_expect_success 'refusing to edit in refs/heads/' '
+	! MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit
+'
+
+test_expect_success 'refusing to edit in refs/remotes/' '
+	! MSG=1 GIT_NOTES_REF=refs/remotes/bogus git notes edit
+'
+
 # 1 indicates caught gracefully by die, 128 means git-show barked
 test_expect_success 'handle empty notes gracefully' '
 	git notes show ; test 1 = $?
-- 
1.6.2.rc0.288.g6852b

  parent reply	other threads:[~2009-02-14 19:17 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-14 19:15 [PATCH 1/4] notes: only clean up message file when editing Thomas Rast
2009-02-14 19:15 ` [PATCH 2/4] notes: use GIT_EDITOR and core.editor over VISUAL/EDITOR Thomas Rast
2009-02-14 19:29   ` Johannes Schindelin
2009-02-14 19:15 ` [PATCH 3/4] t3301: fix confusing test for valid notes ref Thomas Rast
2009-02-14 19:32   ` Johannes Schindelin
2009-02-14 19:15 ` Thomas Rast [this message]
2009-02-14 19:33   ` [PATCH 4/4] notes: refuse to edit notes outside refs/notes/ Johannes Schindelin
2009-02-14 19:56     ` Thomas Rast
2009-02-14 20:23       ` [PATCH v2 1/5] notes: only clean up message file when editing Thomas Rast
2009-02-15  7:54         ` Junio C Hamano
2009-02-14 20:23       ` [PATCH v2 2/5] notes: use GIT_EDITOR and core.editor over VISUAL/EDITOR Thomas Rast
2009-02-14 20:23       ` [PATCH v2 3/5] t3301: fix confusing quoting in test for valid notes ref Thomas Rast
2009-02-14 20:23       ` [PATCH v2 4/5] t3301: use test_must_fail instead of ! Thomas Rast
2009-02-14 21:26         ` Johannes Schindelin
2009-02-15  7:52         ` Junio C Hamano
2009-02-15 16:11           ` Thomas Rast
2009-02-15 18:18             ` Jeff King
2009-02-15 22:07               ` Thomas Rast
2009-02-17  9:29               ` Mike Ralphson
2009-02-17 16:34                 ` Jeff King
2009-02-17 18:00                   ` Mike Ralphson
2009-02-17 20:27                     ` Jeff King
2009-02-18  6:41                       ` Jeff King
2009-02-18 10:14                         ` Johannes Schindelin
2009-02-18 10:16                           ` Jeff King
2009-02-18 11:53                             ` Johannes Schindelin
2009-02-19  0:37                               ` Jeff King
2009-02-19  0:46                                 ` Johannes Schindelin
2009-02-19  0:46                                   ` Jeff King
2009-02-17  8:44           ` Thomas Rast
2009-02-17  8:46             ` Thomas Rast
2009-02-17 16:56               ` Brandon Casey
2009-02-17 22:20                 ` Junio C Hamano
2009-02-17 22:53                   ` [PATCH] test suite: correct export var=val usage Jay Soffian
2009-02-17 23:47                     ` Johannes Schindelin
2009-02-18  0:37                       ` Jay Soffian
2009-02-17 22:54                   ` Jay Soffian
2009-02-17 22:57                   ` Jay Soffian
2009-02-18 10:06                     ` Wincent Colaiuta
2009-02-18 13:19                       ` Jay Soffian
2009-02-18 13:29                         ` Jay Soffian
2009-02-18 13:34                           ` Johannes Schindelin
2009-02-18 16:56                           ` Wincent Colaiuta
2009-02-18 17:05                             ` Thomas Rast
2009-02-18 20:55                   ` [PATCH v2] " Jay Soffian
2009-02-14 20:23       ` [PATCH v2 5/5] notes: refuse to edit notes outside refs/notes/ Thomas Rast
2009-02-14 19:29 ` [PATCH 1/4] notes: only clean up message file when editing Johannes Schindelin

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ac3c2ce272e8e7f3000349f682a5a4843aea34e6.1234638466.git.trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    /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.
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 NNTP newsgroup(s).