This script allows you to edit and show commit notes easily. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- .gitignore | 1 + Makefile | 2 +- git-notes.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletions(-) create mode 100755 git-notes.sh diff --git a/.gitignore b/.gitignore index 20ee642..125613f 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ git-mktag git-mktree git-name-rev git-mv +git-notes git-pack-redundant git-pack-objects git-pack-refs diff --git a/Makefile b/Makefile index 119d949..10a9342 100644 --- a/Makefile +++ b/Makefile @@ -213,7 +213,7 @@ SCRIPT_SH = \ git-merge-resolve.sh git-merge-ours.sh \ git-lost-found.sh git-quiltimport.sh git-submodule.sh \ git-filter-branch.sh \ - git-stash.sh + git-stash.sh git-notes.sh SCRIPT_PERL = \ git-add--interactive.perl \ diff --git a/git-notes.sh b/git-notes.sh new file mode 100755 index 0000000..e0ad0b9 --- /dev/null +++ b/git-notes.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +USAGE="(edit | show) [commit]" +. git-sh-setup + +test -n "$3" && usage + +test -z "$GIT_NOTES_REF" && GIT_NOTES_REF="$(git config core.notesref)" +test -z "$GIT_NOTES_REF" && + die "No notes ref set." + +COMMIT=$(git rev-parse --verify --default HEAD "$2") +NAME=$(echo $COMMIT | sed "s/^../&\//") + +case "$1" in +edit) + MESSAGE="$GIT_DIR"/new-notes + GIT_NOTES_REF= git log -1 $COMMIT | sed "s/^/#/" > "$MESSAGE" + + GIT_INDEX_FILE="$MESSAGE".idx + export GIT_INDEX_FILE + + CURRENT_HEAD=$(git show-ref $GIT_NOTES_REF | cut -f 1 -d ' ') + if [ -z "$CURRENT_HEAD" ]; then + PARENT= + else + PARENT="-p $OLDTIP" + git read-tree $GIT_NOTES_REF || die "Could not read index" + git cat-file blob :$NAME >> "$MESSAGE" 2> /dev/null + fi + + ${VISUAL:-${EDITOR:-vi}} "$MESSAGE" + + grep -v ^# < "$MESSAGE" | git stripspace > "$MESSAGE".processed + mv "$MESSAGE".processed "$MESSAGE" + if [ -z "$(cat "$MESSAGE")" ]; then + test -z "$CURRENT_HEAD" && + die "Will not initialise with empty tree" + git update-index --force-remove $NAME || + die "Could not update index" + else + BLOB=$(git hash-object -w "$MESSAGE") || + die "Could not write into object database" + git update-index --add --cacheinfo 0644 $BLOB $NAME || + die "Could not write index" + fi + + TREE=$(git write-tree) || die "Could not write tree" + NEW_HEAD=$(: | git commit-tree $TREE $PARENT) || + die "Could not annotate" + case "$CURRENT_HEAD" in + '') git update-ref $GIT_NOTES_REF $NEW_HEAD ;; + *) git update-ref $GIT_NOTES_REF $NEW_HEAD $CURRENT_HEAD;; + esac +;; +show) + git show "$GIT_NOTES_REF":$NAME +;; +*) + usage +esac -- 1.5.3.rc1.2718.gd2dc9-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html