diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-12-09 10:36:51 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-12-09 10:36:51 -0800 |
commit | 6aa6a92fb61f0ba295b349222b8966c46ef0ba58 (patch) | |
tree | 36d0f2610e844d52d269ee3845219b928f5e31a8 | |
parent | Merge branch 'jl/add-p-reverse-message' into maint (diff) | |
parent | cherry-pick/revert: transparently refresh index (diff) | |
download | tgif-6aa6a92fb61f0ba295b349222b8966c46ef0ba58.tar.xz |
Merge branch 'jn/cherry-pick-refresh-index' into maint
* jn/cherry-pick-refresh-index:
cherry-pick/revert: transparently refresh index
-rw-r--r-- | builtin/revert.c | 18 | ||||
-rwxr-xr-x | t/t3501-revert-cherry-pick.sh | 10 |
2 files changed, 26 insertions, 2 deletions
diff --git a/builtin/revert.c b/builtin/revert.c index 57b51e4a0e..bb6e9e83b7 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -547,6 +547,21 @@ static void prepare_revs(struct rev_info *revs) die("empty commit set passed"); } +static void read_and_refresh_cache(const char *me) +{ + static struct lock_file index_lock; + int index_fd = hold_locked_index(&index_lock, 0); + if (read_index_preload(&the_index, NULL) < 0) + die("git %s: failed to read the index", me); + refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); + if (the_index.cache_changed) { + if (write_index(&the_index, index_fd) || + commit_locked_index(&index_lock)) + die("git %s: failed to refresh the index", me); + } + rollback_lock_file(&index_lock); +} + static int revert_or_cherry_pick(int argc, const char **argv) { struct rev_info revs; @@ -567,8 +582,7 @@ static int revert_or_cherry_pick(int argc, const char **argv) die("cherry-pick --ff cannot be used with --edit"); } - if (read_cache() < 0) - die("git %s: failed to read the index", me); + read_and_refresh_cache(me); prepare_revs(&revs); diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index bc7aedd048..043954422c 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -81,6 +81,16 @@ test_expect_success 'revert after renaming branch' ' ' +test_expect_success 'cherry-pick on stat-dirty working tree' ' + git clone . copy && + ( + cd copy && + git checkout initial && + test-chmtime +40 oops && + git cherry-pick added + ) +' + test_expect_success 'revert forbidden on dirty working tree' ' echo content >extra_file && |