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

[PATCH 4/4] git update-index --cacheinfo can be used to select a stage when there are merged and unmerged entries

From
Jaime Soriano Pastor <jsorianopastor@gmail.com>
Date
Aug 20, 2014, 11:26 UTC
Message-ID
<af54b2b3e80a6ff76b07ea129ead43079ef06a7a.1408533065.git.jsorianopastor@gmail.com>
In-Reply-To
<cover.1408533065.git.jsorianopastor@gmail.com>
Signed-off-by: Jaime Soriano Pastor <jsorianopastor@gmail.com>
---
 builtin/update-index.c                     |  1 +
 cache.h                                    |  1 +
 read-cache.c                               |  3 ++-
 t/t9904-unmerged-file-with-merged-entry.sh | 14 +++++++++++---
 4 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ebea285..509fae7 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -239,6 +239,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
 		ce->ce_flags |= CE_VALID;
 	option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
 	option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
+	option |= ADD_CACHE_OK_TO_REPLACE_MERGED;
 	if (add_cache_entry(ce, option))
 		return error("%s: cannot add to the index - missing --add option?",
 			     path);
diff --git a/cache.h b/cache.h
index c708062..ecac41c 100644
--- a/cache.h
+++ b/cache.h
@@ -474,6 +474,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name
 #define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
 #define ADD_CACHE_JUST_APPEND 8		/* Append only; tree.c::read_tree() */
 #define ADD_CACHE_NEW_ONLY 16		/* Do not replace existing ones */
+#define ADD_CACHE_OK_TO_REPLACE_MERGED 32 /* Ok to replace even if a merged entry exists */
 extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
 extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
 extern int remove_index_entry_at(struct index_state *, int pos);
diff --git a/read-cache.c b/read-cache.c
index d549d0b..c4ddefe 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -933,6 +933,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
 	int pos;
 	int ok_to_add = option & ADD_CACHE_OK_TO_ADD;
 	int ok_to_replace = option & ADD_CACHE_OK_TO_REPLACE;
+	int ok_to_replace_merged = option & ADD_CACHE_OK_TO_REPLACE_MERGED;
 	int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
 	int new_only = option & ADD_CACHE_NEW_ONLY;
 	int replaced = 0;
@@ -955,7 +956,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
 	 */
 	if (pos < istate->cache_nr && ce_stage(ce) == 0) {
 		while (ce_same_name(istate->cache[pos], ce)) {
-			if (replaced)
+			if (replaced && !ok_to_replace_merged)
 				die("Merged and unmerged entries found for "
 				    "'%s', check 'git ls-files -s \"%s\"'",
 				    ce->name, ce->name);
diff --git a/t/t9904-unmerged-file-with-merged-entry.sh b/t/t9904-unmerged-file-with-merged-entry.sh
index 945bc1c..9138821 100755
--- a/t/t9904-unmerged-file-with-merged-entry.sh
+++ b/t/t9904-unmerged-file-with-merged-entry.sh
@@ -28,11 +28,11 @@ setup_stage_state() {
 
 test_expect_success 'setup - two branches with conflicting files' '
 	setup_repository &&
-	setup_stage_state &&
+	git merge master
 	git ls-files -s conflict > output &&
-	test_line_count = 4 output &&
+	test_line_count = 3 output &&
 	git ls-files -s conflict2 > output &&
-	test_line_count = 4 output &&
+	test_line_count = 3 output &&
 	rm output
 '
 
@@ -83,4 +83,12 @@ test_expect_success 'git reset --hard' '
 	test_cmp expected current
 '
 
+test_expect_success 'git update-index --cacheinfo to select a stage to use' '
+	setup_stage_state &&
+	git cat-file blob :1:conflict > conflict &&
+	git update-index --cacheinfo 100644,`git hash-object conflict`,conflict
+	git ls-files -s conflict > output &&
+	test_line_count = 1 output
+'
+
 test_done
-- 
2.0.4.4.gaf54b2b
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 51 in “read-cache.c: Ensure unmerged entries are removed”
  1. read-cache.c: Ensure unmerged entries are removedJaime Soriano Pastor, Aug 12, 2014
  2. read-cache.c: Ensure unmerged entries are removedJaime Soriano Pastor, Aug 12, 2014
  3. Junio C HamanoAug 12, 2014
  4. Jaime Soriano PastorAug 13, 2014
  5. Junio C HamanoAug 13, 2014
  6. Jaime Soriano PastorAug 15, 2014
  7. Junio C HamanoAug 15, 2014
  8. Jaime Soriano PastorAug 16, 2014
  9. Junio C HamanoAug 18, 2014
  10. Jaime Soriano PastorAug 18, 2014
  11. 0/4 Handling unmerged files with merged entriesJaime Soriano Pastor, Aug 20, 2014
  12. 1/4 read_index_unmerged doesn't loop forever if merged stage exists for unmerged fileJaime Soriano Pastor, Aug 20, 2014
  13. 2/4 Error out when adding a file with merged and unmerged entriesJaime Soriano Pastor, Aug 20, 2014
  14. 3/4 Added tests for the case of merged and unmerged entries for the same fileJaime Soriano Pastor, Aug 20, 2014
  15. Junio C HamanoAug 20, 2014
  16. Jaime Soriano PastorAug 21, 2014
  17. Junio C HamanoAug 21, 2014
  18. 4/4 git update-index --cacheinfo can be used to select a stage when there are merged and unmerged entriesJaime Soriano Pastor, Aug 20, 2014
  19. Junio C HamanoAug 20, 2014
  20. Jaime Soriano PastorAug 21, 2014
  21. Junio C HamanoAug 20, 2014
  22. Jaime Soriano PastorAug 21, 2014
  23. Check order when reading indexJaime Soriano Pastor, Aug 21, 2014
  24. Jaime Soriano PastorAug 21, 2014
  25. Duy NguyenAug 21, 2014
  26. Junio C HamanoAug 21, 2014
  27. 1/2 Check order when reading indexJaime Soriano Pastor, Aug 24, 2014
  28. 2/2 Loop index increases monotonically when reading unmerged entriesJaime Soriano Pastor, Aug 24, 2014
  29. Jaime Soriano PastorAug 24, 2014
  30. Junio C HamanoAug 25, 2014
  31. Junio C HamanoAug 25, 2014
  32. Jeff KingAug 25, 2014
  33. Junio C HamanoAug 25, 2014
  34. Jaime Soriano PastorAug 26, 2014
  35. Jeff KingAug 26, 2014
  36. Junio C HamanoAug 26, 2014
  37. Jaime Soriano PastorAug 26, 2014
  38. Junio C HamanoAug 26, 2014
  39. 1/2 read_index_from(): catch out of order entries when reading an index fileJaime Soriano Pastor, Aug 27, 2014
  40. 2/2 read_index_unmerged(): remove unnecessary loop index adjustmentJaime Soriano Pastor, Aug 27, 2014
  41. Eric SunshineAug 29, 2014
  42. read_index_from(): catch out of order entries when reading an index fileJaime Soriano Pastor, Aug 29, 2014
  43. Junio C HamanoAug 29, 2014
  44. Jaime Soriano PastorAug 27, 2014
  45. Junio C HamanoAug 27, 2014
  46. Jaime Soriano PastorAug 27, 2014
  47. Jaime Soriano PastorAug 25, 2014
  48. Johannes SixtAug 21, 2014
  49. Junio C HamanoAug 21, 2014
  50. Junio C HamanoAug 12, 2014
  51. Jaime Soriano PastorAug 13, 2014

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.