From: ZheNing Hu <adlternative@xxxxxxxxx> Because sometimes we want to check if the files in the index match the sparse specification, so introduce "%(skipworktree)" atom to git ls-files `--format` option. When we use this option, if the file match the sparse specification, it will output "1", otherwise, output empty string "". Signed-off-by: ZheNing Hu <adlternative@xxxxxxxxx> --- Documentation/git-ls-files.txt | 5 +++++ builtin/ls-files.c | 3 +++ t/t3013-ls-files-format.sh | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 440043cdb8e..2540b404808 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -260,6 +260,11 @@ eolattr:: that applies to the path. path:: The pathname of the file which is recorded in the index. +skipworktree:: + If the file in the index marked with SKIP_WORKTREE bit. + It means the file do not match the sparse specification. + See link:technical/sparse-checkout.txt[sparse-checkout] + for more information. EXCLUDE PATTERNS ---------------- diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a03b559ecaa..bbff868ae6b 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -280,6 +280,9 @@ static size_t expand_show_index(struct strbuf *sb, const char *start, data->pathname)); else if (skip_prefix(start, "(path)", &p)) write_name_to_buf(sb, data->pathname); + else if (skip_prefix(start, "(skipworktree)", &p)) + strbuf_addstr(sb, ce_skip_worktree(data->ce) ? + "1" : ""); else die(_("bad ls-files format: %%%.*s"), (int)len, start); diff --git a/t/t3013-ls-files-format.sh b/t/t3013-ls-files-format.sh index efb7450bf1e..cd35dba5930 100755 --- a/t/t3013-ls-files-format.sh +++ b/t/t3013-ls-files-format.sh @@ -92,4 +92,27 @@ test_expect_success 'git ls-files --format with --debug' ' test_cmp expect actual ' +test_expect_success 'git ls-files --format with skipworktree' ' + test_when_finished "git sparse-checkout disable" && + mkdir dir1 dir2 && + echo "file1" >dir1/file1.txt && + echo "file2" >dir2/file2.txt && + git add dir1 dir2 && + git commit -m skipworktree && + git sparse-checkout set dir1 && + git ls-files --format="%(path)%(skipworktree)" >actual && + cat >expect <<-\EOF && + dir1/file1.txt + dir2/file2.txt1 + o1.txt + o2.txt + o3.txt + o4.txt + o5.txt + o6.txt + o7.txt + EOF + test_cmp expect actual +' + test_done -- gitgitgadget