Skip to contentSkip to conversation

Fix confusing behaviour of update-cache --refresh on unmerged paths.

PATCH New Junio C Hamano 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix confusing behaviour of update-cache --refresh on unmerged paths.

The "update-cache --refresh" command attempts refresh_entry() on unmerged path, which results in as many "needs update" messages as there are unmerged stages for that path. This does not do any harm to the working directory, but it is confusing.

    $ ls -al
    total 16
    drwxrwsr-x   3 junio src 4096 Apr 17 23:00 ./
    drwxrwsr-x  10 junio src 4096 Apr 17 22:58 ../
    drwxr-sr-x   3 junio src 4096 Apr 17 22:59 .git/
    -rw-rw-r--   1 junio src  363 Apr 17 23:00 TT
    $ show-files --stage
    100644 e14bafaadce6c34768ba2ff8b3c6419e8839e7d2 1 TT
    100644 99ef1b30fc6d6ea186d6eac62619e1afd65ad64e 2 TT
    100644 033b9385f7a29882a6b4b34f67b20e2304d3489d 3 TT
    $ ../++linus/update-cache --refresh
    TT: needs update
    TT: needs update
    TT: needs update
    $ ../update-cache --refresh
    TT: needs merge

Here is a fix.

---

 update-cache.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

update-cache.c: 5742c6ca084a7761ad728651d85509736e2ebc7c

update-cache.c +11 -2
@@ -196,9 +196,18 @@ static void refresh_cache(void)
 	int i;
 
 	for (i = 0; i < active_nr; i++) {
-		struct cache_entry *ce = active_cache[i];
-		struct cache_entry *new = refresh_entry(ce);
+		struct cache_entry *ce, *new;
+		ce = active_cache[i];
+		if (ce_stage(ce)) {
+			printf("%s: needs merge\n", ce->name);
+			while ((i < active_nr) &&
+			       ! strcmp(active_cache[i]->name, ce->name))
+				i++;
+			i--;
+			continue;
+		}
 
+		new = refresh_entry(ce);
 		if (!new) {
 			printf("%s: needs update\n", ce->name);
 			continue;