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

[PATCH] builtin-merge: refresh the index before calling a strategy

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Oct 3, 2008, 13:02 UTC
Message-ID
<1223038951-25190-1-git-send-email-vmiklos@frugalware.org>
In-Reply-To
<20080928151135.GF23137@genesis.frugalware.org>

In case a file is touched but has no real changes then we just have to update the index and should not error out.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Sun, Sep 28, 2008 at 05:11:35PM +0200, Miklos Vajna <vmiklos@frugalware.org> wrote:
> Thanks for the reproducer, I'll write a proper testcase for this and
> try to
> provide a fix for it as well.
Try this one.
 builtin-merge.c  |   10 ++++++++++
 t/t7600-merge.sh |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index 4c9ed5d..6c9dfe6 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -548,6 +548,16 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
 	int i = 0, ret;
 	struct commit_list *j;
 	struct strbuf buf;
+	int index_fd;
+	struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+
+	index_fd = hold_locked_index(lock, 1);
+	refresh_cache(REFRESH_QUIET);
+	if (active_cache_changed &&
+			(write_cache(index_fd, active_cache, active_nr) ||
+			 commit_locked_index(lock)))
+		return error("Unable to write index.");
+	rollback_lock_file(lock);
 
 	if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
 		int clean;
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 98cfc53..61db3c3 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -520,4 +520,13 @@ test_expect_success 'merge --no-ff --no-commit && commit' '
 
 test_debug 'gitk --all'
 
+test_expect_success 'refresh the index before merging' '
+	git reset --hard c1 &&
+	sleep 1 &&
+	touch file &&
+	git merge c3
+'
+
+test_debug 'gitk --all'
+
 test_done
-- 
1.6.0.2
Previous: Miklos Vajna
Message 11 of 11 in “having to pull twice”
  1. Michael P. SoulierSep 25, 2008
  2. Shawn O. PearceSep 25, 2008
  3. Thomas RastSep 25, 2008
  4. Alex RiesenSep 25, 2008
  5. Michael P. SoulierSep 25, 2008
  6. Miklos VajnaSep 25, 2008
  7. Thomas RastSep 27, 2008
  8. Miklos VajnaSep 28, 2008
  9. Thomas RastSep 28, 2008
  10. Miklos VajnaSep 29, 2008
  11. builtin-merge: refresh the index before calling a strategyMiklos Vajna, Oct 3, 2008

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.