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

[PATCH 2/2] diff [--cached] HEAD: catch updates to the current branch behind your back.

From
Junio C Hamano <junkio@cox.net>
Date
Apr 11, 2007, 20:58 UTC
Message-ID
<7vabxeocgm.fsf@assigned-by-dhcp.cox.net>

This makes "git-diff [--cached] HEAD" issue a warning message when it detects that your index is not based on the tip of the current branch (e.g. updated by gremlins running git-send-pack from elsewhere to update it, or from another working tree that shares the same $GIT_DIR/refs with your working tree).

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * This is on top of 'next', which contains 'jc/checkout' aka
   "index base" topic.
 diff-lib.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index 5c5b05b..940c18a 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -657,6 +657,14 @@ int run_diff_index(struct rev_info *revs, int cached)
 	const char *tree_name;
 	int match_missing = 0;
 
+	/* Check for gremlins */
+	if (active_cache_base_valid &&
+	    revs->pending.objects->item->type == OBJ_COMMIT &&
+	    revs->pending.objects->name &&
+	    !strcmp(revs->pending.objects->name, "HEAD") &&
+	    hashcmp(active_cache_base, revs->pending.objects->item->sha1))
+		revs->diffopt.warning = "WARNING: HEAD and index BASE do not match";
+
 	/* 
 	 * Backward compatibility wart - "diff-index -m" does
 	 * not mean "do not ignore merges", but totally different.
-- 
1.5.1.777.gd14d3
Message 1 of 1 in “diff [--cached] HEAD: catch updates to the current branch behind your back.”
  1. 2/2 diff [--cached] HEAD: catch updates to the current branch behind your back.Junio C Hamano, Apr 11, 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.