git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] last-modified: support sparse checkouts
@ 2025-11-29 13:43 Johannes Schindelin via GitGitGadget
  2025-11-30 20:00 ` Derrick Stolee
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2025-11-29 13:43 UTC (permalink / raw)
  To: git; +Cc: Toon Claes, Johannes Schindelin, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

In a sparse checkout, a user might want to run `last-modified` on a
directory outside the worktree.

And even in non-sparse checkouts, a user might need to run that command
on a directory that does not exist in the worktree.

These use cases should be supported via the `--` separator between
revision and file arguments, which is even advertised in the
documentation. This patch fixes a tiny bug that prevents that from
working.

This fixes https://github.com/git-for-windows/git/issues/5978

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    last-modified: support sparse checkouts

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2013%2Fdscho%2Flast-modified-vs-sparse-checkouts-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2013/dscho/last-modified-vs-sparse-checkouts-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2013

 builtin/last-modified.c  | 3 ++-
 t/t8020-last-modified.sh | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/builtin/last-modified.c b/builtin/last-modified.c
index b0ecbdc540..dc1e229f4d 100644
--- a/builtin/last-modified.c
+++ b/builtin/last-modified.c
@@ -525,7 +525,8 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
 
 	argc = parse_options(argc, argv, prefix, last_modified_options,
 			     last_modified_usage,
-			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
+			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT |
+			     PARSE_OPT_KEEP_DASHDASH);
 
 	repo_config(repo, git_default_config, NULL);
 
diff --git a/t/t8020-last-modified.sh b/t/t8020-last-modified.sh
index a4c1114ee2..50f4312f71 100755
--- a/t/t8020-last-modified.sh
+++ b/t/t8020-last-modified.sh
@@ -78,6 +78,14 @@ test_expect_success 'last-modified subdir' '
 	EOF
 '
 
+test_expect_success 'last-modified in sparse checkout' '
+	test_when_finished "git sparse-checkout disable" &&
+	git sparse-checkout set b &&
+	check_last_modified -- a <<-\EOF
+	3 a
+	EOF
+'
+
 test_expect_success 'last-modified subdir recursive' '
 	check_last_modified -r a <<-\EOF
 	3 a/b/file

base-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] last-modified: support sparse checkouts
  2025-11-29 13:43 [PATCH] last-modified: support sparse checkouts Johannes Schindelin via GitGitGadget
@ 2025-11-30 20:00 ` Derrick Stolee
  2025-12-03 11:11   ` Toon Claes
  0 siblings, 1 reply; 3+ messages in thread
From: Derrick Stolee @ 2025-11-30 20:00 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget, git; +Cc: Toon Claes, Johannes Schindelin

On 11/29/2025 8:43 AM, Johannes Schindelin via GitGitGadget wrote:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> In a sparse checkout, a user might want to run `last-modified` on a
> directory outside the worktree.
> 
> And even in non-sparse checkouts, a user might need to run that command
> on a directory that does not exist in the worktree.
> 
> These use cases should be supported via the `--` separator between
> revision and file arguments, which is even advertised in the
> documentation. This patch fixes a tiny bug that prevents that from
> working.

>  	argc = parse_options(argc, argv, prefix, last_modified_options,
>  			     last_modified_usage,
> -			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
> +			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT |
> +			     PARSE_OPT_KEEP_DASHDASH);

I'm intrigued that this is the only fix that was required.

> +test_expect_success 'last-modified in sparse checkout' '
> +	test_when_finished "git sparse-checkout disable" &&
> +	git sparse-checkout set b &&
> +	check_last_modified -- a <<-\EOF

Would we expect this to work without the '--'? Should it
fail for a directory that exists at HEAD but is outside of
the sparse-checkout?

Thanks,
-Stolee


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] last-modified: support sparse checkouts
  2025-11-30 20:00 ` Derrick Stolee
@ 2025-12-03 11:11   ` Toon Claes
  0 siblings, 0 replies; 3+ messages in thread
From: Toon Claes @ 2025-12-03 11:11 UTC (permalink / raw)
  To: Derrick Stolee, Johannes Schindelin via GitGitGadget, git
  Cc: Johannes Schindelin

Derrick Stolee <stolee@gmail.com> writes:

> On 11/29/2025 8:43 AM, Johannes Schindelin via GitGitGadget wrote:
>> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>> 
>> In a sparse checkout, a user might want to run `last-modified` on a
>> directory outside the worktree.
>> 
>> And even in non-sparse checkouts, a user might need to run that command
>> on a directory that does not exist in the worktree.
>> 
>> These use cases should be supported via the `--` separator between
>> revision and file arguments, which is even advertised in the
>> documentation. This patch fixes a tiny bug that prevents that from
>> working.
>
>>  	argc = parse_options(argc, argv, prefix, last_modified_options,
>>  			     last_modified_usage,
>> -			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
>> +			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT |
>> +			     PARSE_OPT_KEEP_DASHDASH);
>
> I'm intrigued that this is the only fix that was required.

I like it!

>> +test_expect_success 'last-modified in sparse checkout' '
>> +	test_when_finished "git sparse-checkout disable" &&
>> +	git sparse-checkout set b &&
>> +	check_last_modified -- a <<-\EOF
>
> Would we expect this to work without the '--'? Should it
> fail for a directory that exists at HEAD but is outside of
> the sparse-checkout?

I don't think we need to complicate things that much. Arguments after
the '--' are handled as pathspecs. If no paths match that pathspec, the
output is simply nothing.

Just to demonstrate:

On 'master':

    $ git last-modified a
    fatal: ambiguous argument 'a': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'

    $ git last-modified -- a
    fatal: ambiguous argument 'a': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'

With this patch applied:

    $ git last-modified a
    fatal: ambiguous argument 'a': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'

    $ git last-modified -- a

    $ echo $?
    0

I agree this behavior is better. Thanks for this fix. I approve.

-- 
Cheers,
Toon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-03 11:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29 13:43 [PATCH] last-modified: support sparse checkouts Johannes Schindelin via GitGitGadget
2025-11-30 20:00 ` Derrick Stolee
2025-12-03 11:11   ` Toon Claes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).