@matheusbsbs / matheus-bagliano / commits / 055a597525
Fork 0

Add a script to edit/inspect notes

The script 'git notes' allows you to edit and show commit notes, by calling either git notes show <commit> or git notes edit <commit> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 20, 2008 at 13:05 UTC 055a5975258f37eecdfcf609a472ab4957a59263
6 files changed +179
.gitignore
+1
@@ -82,6 +82,7 @@ git-mktag
82 git-mktree
83 git-name-rev
84 git-mv
85 +git-notes
86 git-pack-redundant
87 git-pack-objects
88 git-pack-refs
Documentation/git-notes.txt new
+46
@@ -0,0 +1,46 @@
1 +git-notes(1)
2 +============
3 +
4 +NAME
5 +----
6 +git-notes - Add/inspect commit notes
7 +
8 +SYNOPSIS
9 +--------
10 +[verse]
11 +'git-notes' (edit | show) [commit]
12 +
13 +DESCRIPTION
14 +-----------
15 +This command allows you to add notes to commit messages, without
16 +changing the commit. To discern these notes from the message stored
17 +in the commit object, the notes are indented like the message, after
18 +an unindented line saying "Notes:".
19 +
20 +To disable commit notes, you have to set the config variable
21 +core.notesRef to the empty string. Alternatively, you can set it
22 +to a different ref, something like "refs/notes/bugzilla". This setting
23 +can be overridden by the environment variable "GIT_NOTES_REF".
24 +
25 +
26 +SUBCOMMANDS
27 +-----------
28 +
29 +edit::
30 + Edit the notes for a given commit (defaults to HEAD).
31 +
32 +show::
33 + Show the notes for a given commit (defaults to HEAD).
34 +
35 +
36 +Author
37 +------
38 +Written by Johannes Schindelin <johannes.schindelin@gmx.de>
39 +
40 +Documentation
41 +-------------
42 +Documentation by Johannes Schindelin
43 +
44 +GIT
45 +---
46 +Part of the gitlink:git[7] suite
Makefile
+1
@@ -258,6 +258,7 @@ SCRIPT_SH += git-merge-octopus.sh
258 SCRIPT_SH += git-merge-one-file.sh
259 SCRIPT_SH += git-merge-resolve.sh
260 SCRIPT_SH += git-mergetool.sh
261 +SCRIPT_SH += git-notes.sh
262 SCRIPT_SH += git-parse-remote.sh
263 SCRIPT_SH += git-pull.sh
264 SCRIPT_SH += git-quiltimport.sh
command-list.txt
+1
@@ -73,6 +73,7 @@ git-mktag plumbingmanipulators
73 git-mktree plumbingmanipulators
74 git-mv mainporcelain common
75 git-name-rev plumbinginterrogators
76 +git-notes mainporcelain
77 git-pack-objects plumbingmanipulators
78 git-pack-redundant plumbinginterrogators
79 git-pack-refs ancillarymanipulators
git-notes.sh new
+65
@@ -0,0 +1,65 @@
1 +#!/bin/sh
2 +
3 +USAGE="(edit | show) [commit]"
4 +. git-sh-setup
5 +
6 +test -n "$3" && usage
7 +
8 +test -z "$1" && usage
9 +ACTION="$1"; shift
10 +
11 +test -z "$GIT_NOTES_REF" && GIT_NOTES_REF="$(git config core.notesref)"
12 +test -z "$GIT_NOTES_REF" && GIT_NOTES_REF="refs/notes/commits"
13 +
14 +COMMIT=$(git rev-parse --verify --default HEAD "$@") ||
15 +die "Invalid commit: $@"
16 +
17 +MESSAGE="$GIT_DIR"/new-notes-$COMMIT
18 +trap '
19 + test -f "$MESSAGE" && rm "$MESSAGE"
20 +' 0
21 +
22 +case "$ACTION" in
23 +edit)
24 + GIT_NOTES_REF= git log -1 $COMMIT | sed "s/^/#/" > "$MESSAGE"
25 +
26 + GIT_INDEX_FILE="$MESSAGE".idx
27 + export GIT_INDEX_FILE
28 +
29 + CURRENT_HEAD=$(git show-ref "$GIT_NOTES_REF" | cut -f 1 -d ' ')
30 + if [ -z "$CURRENT_HEAD" ]; then
31 + PARENT=
32 + else
33 + PARENT="-p $CURRENT_HEAD"
34 + git read-tree "$GIT_NOTES_REF" || die "Could not read index"
35 + git cat-file blob :$COMMIT >> "$MESSAGE" 2> /dev/null
36 + fi
37 +
38 + ${VISUAL:-${EDITOR:-vi}} "$MESSAGE"
39 +
40 + grep -v ^# < "$MESSAGE" | git stripspace > "$MESSAGE".processed
41 + mv "$MESSAGE".processed "$MESSAGE"
42 + if [ -s "$MESSAGE" ]; then
43 + BLOB=$(git hash-object -w "$MESSAGE") ||
44 + die "Could not write into object database"
45 + git update-index --add --cacheinfo 0644 $BLOB $COMMIT ||
46 + die "Could not write index"
47 + else
48 + test -z "$CURRENT_HEAD" &&
49 + die "Will not initialise with empty tree"
50 + git update-index --force-remove $COMMIT ||
51 + die "Could not update index"
52 + fi
53 +
54 + TREE=$(git write-tree) || die "Could not write tree"
55 + NEW_HEAD=$(echo Annotate $COMMIT | git commit-tree $TREE $PARENT) ||
56 + die "Could not annotate"
57 + git update-ref -m "Annotate $COMMIT" \
58 + "$GIT_NOTES_REF" $NEW_HEAD $CURRENT_HEAD
59 +;;
60 +show)
61 + git show "$GIT_NOTES_REF":$COMMIT
62 +;;
63 +*)
64 + usage
65 +esac
t/t3301-notes.sh new
+65
@@ -0,0 +1,65 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Johannes E. Schindelin
4 +#
5 +
6 +test_description='Test commit notes'
7 +
8 +. ./test-lib.sh
9 +
10 +cat > fake_editor.sh << \EOF
11 +echo "$MSG" > "$1"
12 +echo "$MSG" >& 2
13 +EOF
14 +chmod a+x fake_editor.sh
15 +VISUAL=./fake_editor.sh
16 +export VISUAL
17 +
18 +test_expect_success 'cannot annotate non-existing HEAD' '
19 + ! MSG=3 git notes edit
20 +'
21 +
22 +test_expect_success setup '
23 + : > a1 &&
24 + git add a1 &&
25 + test_tick &&
26 + git commit -m 1st &&
27 + : > a2 &&
28 + git add a2 &&
29 + test_tick &&
30 + git commit -m 2nd
31 +'
32 +
33 +test_expect_success 'need valid notes ref' '
34 + ! MSG=1 GIT_NOTES_REF='/' git notes edit &&
35 + ! MSG=2 GIT_NOTES_REF='/' git notes show
36 +'
37 +
38 +test_expect_success 'create notes' '
39 + git config core.notesRef refs/notes/commits &&
40 + MSG=b1 git notes edit &&
41 + test ! -f .git/new-notes &&
42 + test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
43 + test b1 = $(git notes show) &&
44 + git show HEAD^ &&
45 + ! git notes show HEAD^
46 +'
47 +
48 +cat > expect << EOF
49 +commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
50 +Author: A U Thor <author@example.com>
51 +Date: Thu Apr 7 15:14:13 2005 -0700
52 +
53 + 2nd
54 +
55 +Notes:
56 + b1
57 +EOF
58 +
59 +test_expect_success 'show notes' '
60 + ! (git cat-file commit HEAD | grep b1) &&
61 + git log -1 > output &&
62 + git diff expect output
63 +'
64 +
65 +test_done