git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 5/5] notes: refuse to edit notes outside refs/notes/

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 14, 2009, 20:23 UTC
Message-ID
<aecacfd80a8b68dfe3090b303c95b42fa1169e76.1234642638.git.trast@student.ethz.ch>
In-Reply-To
<200902142056.42198.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 porcelain 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>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
Same as v1, except for s/plumbing/porcelain/ in the commit message.
 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 764fad5..f68d8ee 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -35,6 +35,14 @@ test_expect_success 'need valid notes ref' '
 	MSG=2 GIT_NOTES_REF=/ test_must_fail 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.296.ge2122
Previous: Jay SoffianNext: Johannes Schindelin
Message 46 of 47 in “notes: only clean up message file when editing”
  1. 1/4 notes: only clean up message file when editingThomas Rast, Feb 14, 2009
  2. 2/4 notes: use GIT_EDITOR and core.editor over VISUAL/EDITORThomas Rast, Feb 14, 2009
  3. Johannes SchindelinFeb 14, 2009
  4. 3/4 t3301: fix confusing test for valid notes refThomas Rast, Feb 14, 2009
  5. Johannes SchindelinFeb 14, 2009
  6. 4/4 notes: refuse to edit notes outside refs/notes/Thomas Rast, Feb 14, 2009
  7. Johannes SchindelinFeb 14, 2009
  8. Thomas RastFeb 14, 2009
  9. 1/5 notes: only clean up message file when editingThomas Rast, Feb 14, 2009
  10. Junio C HamanoFeb 15, 2009
  11. 2/5 notes: use GIT_EDITOR and core.editor over VISUAL/EDITORThomas Rast, Feb 14, 2009
  12. 3/5 t3301: fix confusing quoting in test for valid notes refThomas Rast, Feb 14, 2009
  13. 4/5 t3301: use test_must_fail instead of !Thomas Rast, Feb 14, 2009
  14. Johannes SchindelinFeb 14, 2009
  15. Junio C HamanoFeb 15, 2009
  16. Thomas RastFeb 15, 2009
  17. Jeff KingFeb 15, 2009
  18. Thomas RastFeb 15, 2009
  19. Mike RalphsonFeb 17, 2009
  20. Jeff KingFeb 17, 2009
  21. Mike RalphsonFeb 17, 2009
  22. Jeff KingFeb 17, 2009
  23. Jeff KingFeb 18, 2009
  24. Johannes SchindelinFeb 18, 2009
  25. Jeff KingFeb 18, 2009
  26. Johannes SchindelinFeb 18, 2009
  27. Jeff KingFeb 19, 2009
  28. Johannes SchindelinFeb 19, 2009
  29. Jeff KingFeb 19, 2009
  30. Thomas RastFeb 17, 2009
  31. Thomas RastFeb 17, 2009
  32. Brandon CaseyFeb 17, 2009
  33. Junio C HamanoFeb 17, 2009
  34. test suite: correct export var=val usageJay Soffian, Feb 17, 2009
  35. Johannes SchindelinFeb 17, 2009
  36. Jay SoffianFeb 18, 2009
  37. test suite: correct export var=val usageJay Soffian, Feb 17, 2009
  38. test suite: correct export var=val usageJay Soffian, Feb 17, 2009
  39. Wincent ColaiutaFeb 18, 2009
  40. Jay SoffianFeb 18, 2009
  41. Jay SoffianFeb 18, 2009
  42. Johannes SchindelinFeb 18, 2009
  43. Wincent ColaiutaFeb 18, 2009
  44. Thomas RastFeb 18, 2009
  45. test suite: correct export var=val usageJay Soffian, Feb 18, 2009
  46. 5/5 notes: refuse to edit notes outside refs/notes/Thomas Rast, Feb 14, 2009
  47. Johannes SchindelinFeb 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.