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

[PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically

From
APAndy Parkins <andyparkins@gmail.com>
Date
Nov 30, 2006, 15:01 UTC
Message-ID
<200611301501.43436.andyparkins@gmail.com>
In-Reply-To
<fcaeb9bf0611300532x77c7fc8aq2ba77ff57b81cc05@mail.gmail.com>
Raimund Bauer offered this suggestion (paraphrased):

"Maybe we could do git-commit -a _only_ if the index matches HEAD, and otherwise keep current behavior? So people who don't care about the index won't get tripped up, and when you do have a dirty index, you get told about it?"

Johannes Schindelin pointed out that this isn't the right thing to do for an --amend, so that is checked for. Additionally, it's probably not the right thing to do if any files are specified with "--only" or "--include", so they turn this behaviour off as well.

Nguyen Thai Ngoc Duy asked that git-commit let you know it's done this by adding an extra comment to the commit message.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 git-commit.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 81c3a0c..b391257 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -265,6 +265,16 @@ $1"
 done
 case "$edit_flag" in t) no_edit= ;; esac
 
+# Clever commit - if this commit would do nothing, then make it an "all"
+# commit
+if [ -z "$(git-diff-index --cached --name-only HEAD)" \
+	-a -z "$amend" -a -z "$only" -a -z "$also" ]; then
+	echo "# There was nothing to commit but changes were detected in the" > $GIT_DIR/SQUASH_MSG
+	echo "# working tree. 'git commit -a' mode activated." >> $GIT_DIR/SQUASH_MSG
+	echo "#" >> $GIT_DIR/SQUASH_MSG
+	all=t
+fi
+
 ################################################################
 # Sanity check options
 
-- 
1.4.4.1.g3ece-dirty
Previous: Jakub NarebskiNext: Salikh Zakirov
Message 4 of 7 in “Make git-commit cleverer - have it figure out whether it needs -a automatically”
  1. Make git-commit cleverer - have it figure out whether it needs -a automaticallyAndy Parkins, Nov 30, 2006
  2. Nguyen Thai Ngoc DuyNov 30, 2006
  3. Jakub NarebskiNov 30, 2006
  4. Make git-commit cleverer - have it figure out whether it needs -a automaticallyAndy Parkins, Nov 30, 2006
  5. Salikh ZakirovNov 30, 2006
  6. Jakub NarebskiNov 30, 2006
  7. Andy ParkinsDec 1, 2006

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.