]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: support sparse checkouts
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sat, 29 Nov 2025 13:43:46 +0000 (13:43 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Dec 2025 22:20:18 +0000 (14:20 -0800)
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>
Acked-by: Derrick Stolee <stolee@gmail.com>
Acked-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/last-modified.c
t/t8020-last-modified.sh

index b0ecbdc5400d137b7e147c8f91f43210cf8236e0..dc1e229f4d4f443b8307e4e6f4bc6d709dfea466 100644 (file)
@@ -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);
 
index a4c1114ee28f7fca858e425c0eeb69f3f5c98d0f..50f4312f715f41ffeb091d6d7f9da7ec8b63e65c 100755 (executable)
@@ -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