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

[PATCH 1/2] git-commit: Disallow unchanged tree in non-merge mode

From
Dmitry V. Levin <ldv@altlinux.org>
Date
Sep 5, 2007, 23:49 UTC
Message-ID
<20070905234941.GA643@nomad.office.altlinux.org>
Do not commit an unchanged tree in non-merge mode.

While regular mode is already handled by git-runstatus, this cheap check allows to avoid costly git-runstatus later. Also, amend mode needs special attention, because git-runstatus return value is ignored. The idea is that amend should not commit an unchanged tree, one should just remove the top commit using git-reset instead.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 git-commit.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 1d04f1f..800f96c 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -629,6 +629,16 @@ then
 		tree=$(GIT_INDEX_FILE="$TMP_INDEX" git write-tree) &&
 		rm -f "$TMP_INDEX"
 	fi &&
+	if test -n "$current" -a ! -f "$GIT_DIR/MERGE_HEAD"
+	then
+		current_tree="$(git cat-file commit "$current${amend:+^}" 2>/dev/null |
+				sed -e '/^tree \+/!d' -e 's///' -e q)"
+		if test "$tree" = "$current_tree"
+		then
+			echo >&2 "nothing to commit${amend:+ (use \"git reset HEAD^\" to remove the top commit)}"
+			false
+		fi
+	fi &&
 	commit=$(git commit-tree $tree $PARENTS <"$GIT_DIR/COMMIT_MSG") &&
 	rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
 	git update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
-- 
ldv
Next: Shawn O. Pearce
Message 1 of 13 in “git-commit: Disallow unchanged tree in non-merge mode”
  1. 1/2 git-commit: Disallow unchanged tree in non-merge modeDmitry V. Levin, Sep 5, 2007
  2. Shawn O. PearceSep 6, 2007
  3. Dmitry V. LevinSep 6, 2007
  4. Linus TorvaldsSep 14, 2007
  5. 1/2 Fix "git diff" setup codeLinus Torvalds, Sep 14, 2007
  6. 2/2 Fix the rename detection limit checkingLinus Torvalds, Sep 14, 2007
  7. Linus TorvaldsSep 14, 2007
  8. Linus TorvaldsSep 14, 2007
  9. Junio C HamanoSep 14, 2007
  10. Linus TorvaldsSep 14, 2007
  11. Junio C HamanoSep 14, 2007
  12. Linus TorvaldsSep 14, 2007
  13. Junio C HamanoSep 14, 2007

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.