Merge branch 'jn/cherry-pick-refresh-index'

* jn/cherry-pick-refresh-index:
  cherry-pick/revert: transparently refresh index
This commit is contained in:
Junio C Hamano 2010-11-29 17:52:34 -08:00
Родитель d7f4809bc5 f6ce1f2588
Коммит 5eee142c89
2 изменённых файлов: 26 добавлений и 2 удалений

Просмотреть файл

@ -547,6 +547,21 @@ static void prepare_revs(struct rev_info *revs)
die("empty commit set passed"); 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) static int revert_or_cherry_pick(int argc, const char **argv)
{ {
struct rev_info revs; 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"); die("cherry-pick --ff cannot be used with --edit");
} }
if (read_cache() < 0) read_and_refresh_cache(me);
die("git %s: failed to read the index", me);
prepare_revs(&revs); prepare_revs(&revs);

Просмотреть файл

@ -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' ' test_expect_success 'revert forbidden on dirty working tree' '
echo content >extra_file && echo content >extra_file &&