git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: jon.seymour@gmail.com
Subject: [PATCH 2/2] Adds support to git-commit-script for an optional .nextmsg file. [rev 3]
Date: Wed, 15 Jun 2005 17:36:00 +1000	[thread overview]
Message-ID: <20050615073600.25144.qmail@blackcubes.dyndns.org> (raw)


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
------------

                 reply	other threads:[~2005-06-15  7:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20050615073600.25144.qmail@blackcubes.dyndns.org \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.org \
    /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).