summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7f8365f)
raw | patch | inline | side by side (parent: 7f8365f)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 22 Jun 2008 09:04:31 +0000 (02:04 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 22 Jun 2008 09:06:58 +0000 (02:06 -0700) |
When this configuration is set, paths that are autoresolved by git-rerere
are updated in the index as well.
are updated in the index as well.
Documentation/config.txt | patch | blob | history | |
builtin-rerere.c | patch | blob | history | |
t/t4200-rerere.sh | patch | blob | history |
index 5331b450ea051334d53ce3f1e727e33def2ea2cf..0c7cf618ed2847d56d811e39c67ea53bdd71796b 100644 (file)
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
kept for this many days when `git rerere gc` is run.
The default is 15 days. See linkgit:git-rerere[1].
+rerere.autoupdate::
+ When set to true, `git-rerere` updates the index with the
+ resulting contents after it cleanly resolves conflicts using
+ previously recorded resolution. Defaults to false.
+
rerere.enabled::
Activate recording of resolved conflicts, so that identical
conflict hunks can be resolved automatically, should they
diff --git a/builtin-rerere.c b/builtin-rerere.c
index 0eec1f937321024187c185226764c39f6534017a..839b26e8e0a10a498a81bf27d907543e7c256cb8 100644 (file)
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
/* if rerere_enabled == -1, fall back to detection of .git/rr-cache */
static int rerere_enabled = -1;
+/* automatically update cleanly resolved paths to the index */
+static int rerere_autoupdate;
+
static char *merge_rr_path;
static const char *rr_path(const char *name, const char *file)
return 0;
}
+static struct lock_file index_lock;
+
+static int update_paths(struct path_list *update)
+{
+ int i;
+ int fd = hold_locked_index(&index_lock, 0);
+ int status = 0;
+
+ if (fd < 0)
+ return -1;
+
+ for (i = 0; i < update->nr; i++) {
+ struct path_list_item *item = &update->items[i];
+ if (add_file_to_cache(item->path, ADD_CACHE_IGNORE_ERRORS))
+ status = -1;
+ }
+
+ if (!status && active_cache_changed) {
+ if (write_cache(fd, active_cache, active_nr) ||
+ commit_locked_index(&index_lock))
+ die("Unable to write new index file");
+ } else if (fd >= 0)
+ rollback_lock_file(&index_lock);
+ return status;
+}
+
static int do_plain_rerere(struct path_list *rr, int fd)
{
struct path_list conflict = { NULL, 0, 0, 1 };
+ struct path_list update = { NULL, 0, 0, 1 };
int i;
find_conflict(&conflict);
if (!merge(name, path)) {
fprintf(stderr, "Resolved '%s' using "
"previous resolution.\n", path);
+ if (rerere_autoupdate)
+ path_list_insert(path, &update);
goto mark_resolved;
}
}
rr->items[i].util = NULL;
}
+ if (update.nr)
+ update_paths(&update);
+
return write_rr(rr, fd);
}
cutoff_noresolve = git_config_int(var, value);
else if (!strcmp(var, "rerere.enabled"))
rerere_enabled = git_config_bool(var, value);
+ else if (!strcmp(var, "rerere.autoupdate"))
+ rerere_autoupdate = git_config_bool(var, value);
else
return git_default_config(var, value, cb);
return 0;
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index afb3e3d17619786cce89334e9f8afee0e93d792f..a64727d5ad00cb222e3020b6702e4f89e212039c 100755 (executable)
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
echo Bello > file3 &&
git add file3 &&
git commit -m version2 &&
+ git tag version2 &&
test_must_fail git merge fifth &&
test Cello = "$(cat file3)" &&
test 0 != $(git ls-files -u | wc -l)
'
+test_expect_success 'rerere.autoupdate' '
+ git config rerere.autoupdate true
+ git reset --hard &&
+ git checkout version2 &&
+ test_must_fail git merge fifth &&
+ test 0 = $(git ls-files -u | wc -l)
+
+'
+
test_done