Skip to content

Commit edf3b90

Browse files
dturner-twgitster
authored andcommitted
unpack-trees: preserve index extensions
Make git checkout (and other unpack_tree operations) preserve the untracked cache. This is valuable for two reasons: 1. Often, an unpack_tree operation will not touch large parts of the working tree, and thus most of the untracked cache will continue to be valid. 2. Even if the untracked cache were entirely invalidated by such an operation, the user has signaled their intention to have such a cache, and we don't want to throw it away. [jes: backed out the watchman-specific parts] Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4fa66c8 commit edf3b90

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ extern int read_index_unmerged(struct index_state *);
597597
#define CLOSE_LOCK (1 << 1)
598598
extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
599599
extern int discard_index(struct index_state *);
600+
extern void move_index_extensions(struct index_state *dst, struct index_state *src);
600601
extern int unmerged_index(const struct index_state *);
601602
extern int verify_path(const char *path);
602603
extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);

read-cache.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,3 +2628,9 @@ void stat_validity_update(struct stat_validity *sv, int fd)
26282628
fill_stat_data(sv->sd, &st);
26292629
}
26302630
}
2631+
2632+
void move_index_extensions(struct index_state *dst, struct index_state *src)
2633+
{
2634+
dst->untracked = src->untracked;
2635+
src->untracked = NULL;
2636+
}

t/t7063-status-untracked-cache.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,26 @@ test_expect_success 'test ident field is working' '
661661
test_i18ncmp ../expect ../err
662662
'
663663

664+
test_expect_success 'untracked cache survives a checkout' '
665+
git commit --allow-empty -m empty &&
666+
test-dump-untracked-cache >../before &&
667+
test_when_finished "git checkout master" &&
668+
git checkout -b other_branch &&
669+
test-dump-untracked-cache >../after &&
670+
test_cmp ../before ../after &&
671+
test_commit test &&
672+
test-dump-untracked-cache >../before &&
673+
git checkout master &&
674+
test-dump-untracked-cache >../after &&
675+
test_cmp ../before ../after
676+
'
677+
678+
test_expect_success 'untracked cache survives a commit' '
679+
test-dump-untracked-cache >../before &&
680+
git add done/two &&
681+
git commit -m commit &&
682+
test-dump-untracked-cache >../after &&
683+
test_cmp ../before ../after
684+
'
685+
664686
test_done

unpack-trees.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
13911391
WRITE_TREE_SILENT |
13921392
WRITE_TREE_REPAIR);
13931393
}
1394+
move_index_extensions(&o->result, o->dst_index);
13941395
discard_index(o->dst_index);
13951396
*o->dst_index = o->result;
13961397
} else {

0 commit comments

Comments
 (0)