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

git-applymbox: verify that index is clean

From
Linus Torvalds <torvalds@osdl.org>
Date
Aug 18, 2005, 22:31 UTC
Message-ID
<Pine.LNX.4.58.0508181527100.3412@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.58.0508181503200.3412@g5.osdl.org>

This makes git-applymbox verify that the index matches the current HEAD before it starts applying patches.

Otherwise, you might have updated the index with unrelated changes, and the first patch will commit not just the patch from the mbox, but also any changes you had in your index.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
----

This was brough on by: Tony Luck's problem, which _might_ be due to index file change contents that got committed together with a real patch. This will make it much harder to make that particular mistake.

On Thu, 18 Aug 2005, Linus Torvalds wrote:
>
> (git-applymbox _does_ verify that the files that it patches are up-to-date 
> in the index, but it does _not_ verify that the index matches the current 
> HEAD. I guess I could add a sanity check for that...)
diff --git a/tools/git-applymbox b/tools/git-applymbox
--- a/tools/git-applymbox
+++ b/tools/git-applymbox
@@ -18,6 +18,8 @@
 ## use a Signoff_file, because applypatch wants to append the sign-off
 ## message to msg-clean every time it is run.
 
+. git-sh-setup-script || die "Not a git archive"
+
 keep_subject= query_apply= continue= resume=t
 while case "$#" in 0) break ;; esac
 do
@@ -39,6 +41,12 @@ case "$continue" in
 	shift
 esac
 
+files=$(git-diff-cache --cached --name-only HEAD) || exit
+if [ "$files" ]; then
+   echo "Dirty index: cannot apply patches (dirty: $files)" >&2
+   exit 1
+fi
+
 case "$query_apply" in
 t)	touch .dotest/.query_apply
 esac
Previous: Linus TorvaldsNext: Junio C Hamano
Message 3 of 4 in “git-whatchanged -p anomoly?”
  1. Luck, TonyAug 18, 2005
  2. Linus TorvaldsAug 18, 2005
  3. git-applymbox: verify that index is cleanLinus Torvalds, Aug 18, 2005
  4. Junio C HamanoAug 18, 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.