Skip to content

Commit

Permalink
builtin-merge: refresh the index before calling a strategy
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Miklos Vajna authored and Shawn O. Pearce committed Oct 3, 2008
1 parent 52e8370 commit 668f26f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions builtin-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,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;
Expand Down
9 changes: 9 additions & 0 deletions t/t7600-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,13 @@ test_expect_success 'in-index merge' '

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

0 comments on commit 668f26f

Please sign in to comment.