forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 160
last-modified: support sparse checkouts #2013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dscho
wants to merge
1
commit into
gitgitgadget:master
Choose a base branch
from
dscho:last-modified-vs-sparse-checkouts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 git-for-windows#5978 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
a430cf4 to
7040ae9
Compare
Member
Author
|
/submit |
|
Submitted as pull.2013.git.1764423826908.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
On the Git mailing list, Derrick Stolee wrote (reply to this): 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
|
|
User |
|
On the Git mailing list, Toon Claes wrote (reply to this): 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cc: Toon Claes toon@iotcl.com
cc: Derrick Stolee stolee@gmail.com