Skip to content

Commit

Permalink
test-dump-untracked-cache: don't modify the untracked cache
Browse files Browse the repository at this point in the history
To correctly perform its testing function,
test-dump-untracked-cache should not change the state of the
untracked cache in the index.

As a previous patch makes read_index_from() change the state of
the untracked cache and as test-dump-untracked-cache indirectly
calls this function, we need a mechanism to prevent
read_index_from() from changing the untracked cache state when
it's called from test-dump-untracked-cache.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
chriscool authored and gitster committed Jan 27, 2016
1 parent 435ec09 commit dae6c32
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cache.h
Expand Up @@ -1604,6 +1604,13 @@ extern int git_config_get_maybe_bool(const char *key, int *dest);
extern int git_config_get_pathname(const char *key, const char **dest);
extern int git_config_get_untracked_cache(void);

/*
* This is a hack for test programs like test-dump-untracked-cache to
* ensure that they do not modify the untracked cache when reading it.
* Do not use it otherwise!
*/
extern int ignore_untracked_cache_config;

struct key_value_info {
const char *filename;
int linenr;
Expand Down
4 changes: 4 additions & 0 deletions config.c
Expand Up @@ -1599,6 +1599,10 @@ int git_config_get_untracked_cache(void)
int val = -1;
const char *v;

/* Hack for test programs like test-dump-untracked-cache */
if (ignore_untracked_cache_config)
return -1;

if (!git_config_get_maybe_bool("core.untrackedcache", &val))
return val;

Expand Down
7 changes: 7 additions & 0 deletions environment.c
Expand Up @@ -87,6 +87,13 @@ int auto_comment_line_char;
/* Parallel index stat data preload? */
int core_preload_index = 1;

/*
* This is a hack for test programs like test-dump-untracked-cache to
* ensure that they do not modify the untracked cache when reading it.
* Do not use it otherwise!
*/
int ignore_untracked_cache_config;

/* This is set by setup_git_dir_gently() and/or git_default_config() */
char *git_work_tree_cfg;
static char *work_tree;
Expand Down
4 changes: 4 additions & 0 deletions test-dump-untracked-cache.c
Expand Up @@ -44,6 +44,10 @@ int main(int ac, char **av)
{
struct untracked_cache *uc;
struct strbuf base = STRBUF_INIT;

/* Hack to avoid modifying the untracked cache when we read it */
ignore_untracked_cache_config = 1;

setup_git_directory();
if (read_cache() < 0)
die("unable to read index file");
Expand Down

0 comments on commit dae6c32

Please sign in to comment.