builtin-merge: refresh the index before calling a strategy
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>
Miklos Vajna committed
Oct 3, 2008 at 15:02 UTC
668f26fff610605d112fbedffae79917de948893
2 files changed
+19
builtin-merge.c
+10
@@ -547,6 +547,16 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
547
int i = 0, ret;
548
struct commit_list *j;
549
struct strbuf buf;
550
+ int index_fd;
551
+ struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
552
+
553
+ index_fd = hold_locked_index(lock, 1);
554
+ refresh_cache(REFRESH_QUIET);
555
+ if (active_cache_changed &&
556
+ (write_cache(index_fd, active_cache, active_nr) ||
557
+ commit_locked_index(lock)))
558
+ return error("Unable to write index.");
559
+ rollback_lock_file(lock);
560
561
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
562
int clean;
t/t7600-merge.sh
+9
@@ -511,4 +511,13 @@ test_expect_success 'in-index merge' '
511
512
test_debug 'gitk --all'
513
514
+test_expect_success 'refresh the index before merging' '
515
+ git reset --hard c1 &&
516
+ sleep 1 &&
517
+ touch file &&
518
+ git merge c3
519
+'
520
+
521
+test_debug 'gitk --all'
522
+
523
test_done