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

[PATCH 2/2] Adds support to git-commit-script for an optional .nextmsg file. [rev 3]

From
Jon Seymour <jon.seymour@gmail.com>
Date
Jun 15, 2005, 07:36 UTC
Message-ID
<20050615073600.25144.qmail@blackcubes.dyndns.org>

If ${GIT_DIR}/.nextmsg exists, the text will be copied into the .editmsg file together with a sentinel line prior to invoking the editor.

After editing, the edited text (but not the status lines) are saved back to the ${GIT_DIR}/.nextmsg file.

If the sentinel line still exists in .editmsg after editing, the file is truncated, thereby causing the commit to abort (per previous behaviour).

The ${GIT_DIR}/.nextmsg file is deleted if, and only if, the commit was successful.

The behaviour of git-commit-script is unchanged with respect to the previous versions if ${GIT_DIR}/.nextmsg does not exist.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>

--- This patch set is a complete replacement for:

     [PATCH 1/1] Add support for an optional .nextmsg file to git-commit-script

I have incorporated most of Junio's feedback, except the prompting suggestion and the suggested restructuring is slightly different.

[rev 2] fixed 2 errors with handling of .nextmsg file [rev 3] whitespace fixups

---
 git-commit-script |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/git-commit-script b/git-commit-script
--- a/git-commit-script
+++ b/git-commit-script
@@ -26,12 +26,41 @@ EOF
 	git-status-script
 }
 
+merge_next_message()
+{
+	status=$1
+	next=$2
+	mv -f $status .status.$$ || exit 1
+	cat >$status <<EOF
+$SENTINEL
+#---
+$(cat $next)
+#---
+$(cat .status.$$)
+EOF
+	rm .status.$$
+}
+
+save_next_message()
+{
+	status=$1
+	next=$2
+	grep -v "^#" < $status > $next
+	if grep "^$SENTINEL" < $status >/dev/null; then
+		:> $status
+		echo "commit aborted - you must delete the SENTINEL line to confirm the commit"
+	fi
+}
+
 edit_message() {
 	status=$1
 	msg=$2
+	next=$3
 
 	:> $msg
+	[ -f "$next" ] && merge_next_message "$status" "$next"
 	${VISUAL:-${EDITOR:-vi}} "$status"
+	[ -f "$next" ] && save_next_message "$status" "$next"
 	grep -v '^#' < $status | git-stripspace >$msg
 	[ -s $msg ]
 	return $?
@@ -67,8 +96,9 @@ if ! print_status > .editmsg; then
 	exit 1
 fi
 
-if edit_message .editmsg .cmitmsg; then
+if edit_message .editmsg .cmitmsg ${GIT_DIR}/.nextmsg ; then
 	exec_commit .cmitmsg
 	[ -f .editmsg ] && rm .editmsg
 	[ -f .cmitmsg ] && rm .cmitmsg
+	[ -f ${GIT_DIR}/.nextmsg ] && rm ${GIT_DIR}/.nextmsg
 fi
------------
Message 1 of 1 in “Adds support to git-commit-script for an optional .nextmsg file. [rev 3]”
  1. 2/2 Adds support to git-commit-script for an optional .nextmsg file. [rev 3]Jon Seymour, Jun 15, 2005

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.