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

[PATCH] git add: respect core.filemode even with unmerged entries in the index

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 28, 2007, 17:02 UTC
Message-ID
<Pine.LNX.4.64.0706281653260.4438@racer.site>
In-Reply-To
<4683CA7A.7F8070D7@eudaptics.com>

When a merge left unmerged entries, git add failed to pick up the file mode from the index, when core.filemode == 0.

Noticed by Johannes Sixt.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Thu, 28 Jun 2007, Johannes Sixt wrote:
	> Johannes Sixt wrote:
	> 
	> The deficiency is not in merge-recursive, but in 'git add'. The 
	> problem is that after a conflicted merge of an executable file 
	> 'git add' loses the +x bit even if core.filemode=false.
	How's that?
 read-cache.c   |    6 ++++++
 t/t3700-add.sh |   14 ++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 4362b11..a74e4a7 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -382,6 +382,12 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
 		struct cache_entry *ent;
 		int pos = index_name_pos(istate, path, namelen);
 
+		/* might be unmerged */
+		if (pos < 0 && 1-pos < istate->cache_nr &&
+				namelen == ce_namelen(istate->cache[1-pos]) &&
+				!memcmp(path, istate->cache[1-pos]->name,
+					namelen))
+			pos = 1-pos;
 		ent = (0 <= pos) ? istate->cache[pos] : NULL;
 		ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
 	}
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index ad8cc7d..d75970b 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -110,4 +110,18 @@ test_expect_success 'check correct prefix detection' '
 	git add 1/2/a 1/3/b 1/2/c
 '
 
+test_expect_success 'git add and filemode=0 with unmerged entries' '
+	echo 1 > stage1 &&
+	echo 2 > stage2 &&
+	echo 3 > stage3 &&
+	for s in 1 2 3
+	do
+		echo "100755 $(git hash-object -w stage$s) $s	file"
+	done | git update-index --index-info &&
+	git config core.filemode 0 &&
+	echo new > file &&
+	git add file &&
+	git ls-files --stage | grep "^100755 .* 0	file$"
+'
+
 test_done
-- 
1.5.2.2.3228.g16a27
Previous: Johannes SixtNext: Johannes Sixt
Message 14 of 26 in “most commonly used git commands?”
  1. Michael S. TsirkinJun 25, 2007
  2. Junio C HamanoJun 25, 2007
  3. Michael S. TsirkinJun 25, 2007
  4. Junio C HamanoJun 25, 2007
  5. Martin LanghoffJun 28, 2007
  6. Josh TriplettJun 28, 2007
  7. Johannes SchindelinJun 25, 2007
  8. Alex RiesenJun 28, 2007
  9. Johannes SchindelinJun 28, 2007
  10. Johannes SixtJun 28, 2007
  11. Johannes SchindelinJun 28, 2007
  12. Johannes SixtJun 28, 2007
  13. Johannes SixtJun 28, 2007
  14. git add: respect core.filemode even with unmerged entries in the indexJohannes Schindelin, Jun 28, 2007
  15. Johannes SixtJun 29, 2007
  16. Johannes SchindelinJun 29, 2007
  17. Junio C HamanoJun 29, 2007
  18. git add: respect core.filemode with unmerged entriesJohannes Schindelin, Jun 29, 2007
  19. Junio C HamanoJun 29, 2007
  20. Johannes SchindelinJun 29, 2007
  21. Alex RiesenJun 30, 2007
  22. Johannes SchindelinJun 30, 2007
  23. Alex RiesenJun 30, 2007
  24. Jan HudecJul 1, 2007
  25. Alex RiesenJul 1, 2007
  26. Josh TriplettJun 28, 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.