From 500b97e4bb184c954a52550843e6314ecf97a208 Mon Sep 17 00:00:00 2001 From: Fredrik Kuivinen Date: Sun, 2 Oct 2005 17:33:38 +0200 Subject: [PATCH] [PATCH] Teach git-ls-files about '--' to denote end of options. Useful if you have a file whose name starts with a dash. Signed-off-by: Fredrik Kuivinen Signed-off-by: Junio C Hamano --- Documentation/git-ls-files.txt | 9 ++++- ls-files.c | 6 ++- t/t3002-ls-files-dashpath.sh | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100755 t/t3002-ls-files-dashpath.sh diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 591f4ed462..87cc362ad8 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -13,7 +13,7 @@ SYNOPSIS (-[c|d|o|i|s|u|k|m])\* [-x |--exclude=] [-X |--exclude-from=] - [--exclude-per-directory=] + [--exclude-per-directory=] [--] []\* DESCRIPTION ----------- @@ -77,6 +77,13 @@ OPTIONS K to be killed ? other +--:: + Do not interpret any more arguments as options. + +:: + Files to show. If no files are given all files which match the other + specified criteria are shown. + Output ------ show files just outputs the filename unless '--stage' is specified in diff --git a/ls-files.c b/ls-files.c index 956be09350..f47114a168 100644 --- a/ls-files.c +++ b/ls-files.c @@ -530,7 +530,7 @@ static void verify_pathspec(void) static const char ls_files_usage[] = "git-ls-files [-z] [-t] (--[cached|deleted|others|stage|unmerged|killed|modified])* " "[ --ignored ] [--exclude=] [--exclude-from=] " - "[ --exclude-per-directory= ]"; + "[ --exclude-per-directory= ] [--] []*"; int main(int argc, const char **argv) { @@ -544,6 +544,10 @@ int main(int argc, const char **argv) for (i = 1; i < argc; i++) { const char *arg = argv[i]; + if (!strcmp(arg, "--")) { + i++; + break; + } if (!strcmp(arg, "-z")) { line_terminator = 0; continue; diff --git a/t/t3002-ls-files-dashpath.sh b/t/t3002-ls-files-dashpath.sh new file mode 100755 index 0000000000..b42f1382bc --- /dev/null +++ b/t/t3002-ls-files-dashpath.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# +# Copyright (c) 2005 Junio C Hamano +# + +test_description='git-ls-files test (-- to terminate the path list). + +This test runs git-ls-files --others with the following on the +filesystem. + + path0 - a file + -foo - a file with a funny name. + -- - another file with a funny name. +' +. ./test-lib.sh + +test_expect_success \ + setup \ + 'echo frotz >path0 && + echo frotz >./-foo && + echo frotz >./--' + +test_expect_success \ + 'git-ls-files without path restriction.' \ + 'git-ls-files --others >output && + diff -u output - <output && + diff -u output - <output && + diff -u output - <output && + diff -u output - <output && + diff -u output - <