git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Toon Claes <toon@iotcl.com>
To: Derrick Stolee <stolee@gmail.com>,
	Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH] last-modified: support sparse checkouts
Date: Wed, 03 Dec 2025 12:11:50 +0100	[thread overview]
Message-ID: <87qztbx1jd.fsf@iotcl.com> (raw)
In-Reply-To: <75f862a5-2663-4211-b96c-d2c5d1c6f91e@gmail.com>

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

      reply	other threads:[~2025-12-03 11:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87qztbx1jd.fsf@iotcl.com \
    --to=toon@iotcl.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).