Re: [PATCH] sparse-checkout: avoid staging deletions of all files
flat view
From: Derrick Stolee <hidden>
Date: 2020-06-04 15:23:31
On 6/4/2020 11:05 AM, Elijah Newren wrote:
On Thu, Jun 4, 2020 at 7:48 AM Derrick Stolee [off-list ref] wrote:quoted
On 6/4/2020 4:17 AM, Elijah Newren via GitGitGadget wrote:quoted
+test_expect_success 'interaction with clone --no-checkout (unborn index)' ' + git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout && + git -C clone_no_checkout sparse-checkout init --cone && + git -C clone_no_checkout sparse-checkout set folder1 && + git -C clone_no_checkout sparse-checkout list >actual && + cat >expect <<-\EOF && + folder1 + EOF + test_cmp expect actual && + ls clone_no_checkout >actual && + test_must_be_empty actual &&My only comment on the test case is to see if you could use the "check_files" macro instead of "ls". See 761e3d26 (sparse-checkout: improve OS ls compatibility, 2019-12-20) for details.I attempted to do so initially, but that function fails badly when there are no files (other than the "hidden" files '.git', '.', and '..') in the directory. The reason for this comes from the "printf '%s\n' *" -- the glob won't match anything and so it prints a literal asterisk, which is not helpful. I thought about writing an asterisk out to the expected file for comparison, but that just made the testcase look confusing. It was a lot cleaner to just use ls with no glob coupled with test_must_be_empty.quoted
quoted
+ test_path_is_missing clone_no_checkout/.git/index && + + # No branch is checked out until we manually switch to one + git -C clone_no_checkout switch master && + test_path_is_file clone_no_checkout/.git/index && + check_files clone_no_checkout a folder1However, when I did have files in the directory, then I used your check_files function as seen here. :-) Does that make sense, or is there a better alternative?
Unfortunately, we'll still have the platform issue, since there
_is_ a .git directory. To repeat the commit message for 761e3d26:
On FreeBSD, when executed by root ls enables the '-A' option:
-A Include directory entries whose names begin with a dot (`.')
except for . and ... Automatically set for the super-user unless
-I is specified.
As a result the .git directory appeared in the output when run as root.
Simulate no-dotfile ls behaviour using a shell glob.
So maybe be purposeful and include the -a option and expect only the
.git dir (along with . and ..)?
Something like:
cat >expect <<-\EOF &&
.
..
.git
EOF
ls -a clone_no_checkout >actual &&
test_cmp expect actual &&
Thanks,
-Stolee