Re: [RFC PATCH 3/7] t3705: add tests for `git add` in sparse checkouts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 18, 2021 at 12:07 AM Matheus Tavares Bernardino <matheus.bernardino@xxxxxx> wrote:
>
> On Wed, Feb 17, 2021 at 8:01 PM Junio C Hamano <gitster@xxxxxxxxx> wrote:
> >
> > Matheus Tavares <matheus.bernardino@xxxxxx> writes:
> > >
> > > +test_expect_success 'git add --refresh does not update SKIP_WORKTREE entries' '
> > > +     setup_sparse_entry &&
> > > +     test-tool chmtime -60 sparse_entry &&
> > > +     git add --refresh sparse_entry &&
> > > +
> > > +     # We must unset the SKIP_WORKTREE bit, otherwise
> > > +     # git diff-files would skip examining the file
> > > +     git update-index --no-skip-worktree sparse_entry &&
> > > +
> > > +     echo sparse_entry >expected &&
> > > +     git diff-files --name-only sparse_entry >actual &&
> > > +     test_cmp actual expected
> >
> > Hmph, I am not sure what we are testing at this point.  One way to
> > make the final diff-files step show sparse_entry would be for "git
> > add --refresh" to be a no-op, in which case, the cached stat
> > information in the index would be different in mtime from the path
> > in the working tree.  But "update-index --no-skip-worktree" may be
> > buggy and further change or invalidate the cached stat information
> > to cause diff-files to report that the path may be different.
>
> Oh, that is a problem... We could use `git ls-files --debug` and
> directly compare the mtime field. But the ls-files doc says that
> --debug format may change at any time... Any other idea?

Or maybe we could use a test helper for this? Something like:

-- >8 --
#include "test-tool.h"
#include "cache.h"

int cmd__cached_mtime(int argc, const char **argv)
{
	int i;

	setup_git_directory();
	if (read_cache() < 0)
		die("could not read the index");

	for (i = 1; i < argc; i++) {
		const struct stat_data *sd;
		int pos = cache_name_pos(argv[i], strlen(argv[i]));

		if (pos < 0) {
			pos = -pos-1;
			if (pos < active_nr && !strcmp(active_cache[pos]->name, argv[i]))
				die("'%s' is unmerged", argv[i]);
			else
				die("'%s' is not in the index", argv[i]);
		}

		sd = &active_cache[pos]->ce_stat_data;
		printf("%s %u:%u\n", argv[i], sd->sd_mtime.sec, sd->sd_mtime.nsec);
	}

	discard_cache();
	return 0;
}
-- >8 --

Then, the test would become:

	setup_sparse_entry &&
	test-tool cached_mtime sparse_entry >before &&
	test-tool chmtime -60 sparse_entry &&
	git add --refresh sparse_entry &&
	test-tool cached_mtime sparse_entry >after &&
	test_cmp before after

What do you think?



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux