]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Add an optional <mode> argument to commit/status -u|--untracked-files option
authorMarius Storm-Olsen <marius@trolltech.com>
Thu, 5 Jun 2008 08:31:19 +0000 (10:31 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Jun 2008 22:47:36 +0000 (15:47 -0700)
This lets you specify how you want untracked files to be listed.
The possible options are:

    normal - Show untracked files and directories
    all    - Show all untracked files

The 'all' mode is used, if the mode is not specified.

Signed-off-by: Marius Storm-Olsen <marius@trolltech.com>
Documentation/git-commit.txt
builtin-commit.c
t/t7502-status.sh
wt-status.c
wt-status.h

index 02d4baab6d2530f91a76c2c3111e6d47376ca8d8..e600e14be5be7ef45a8b1d51e4cfa47068731075 100644 (file)
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository
 SYNOPSIS
 --------
 [verse]
-'git-commit' [-a | --interactive] [-s] [-v] [-u]
+'git-commit' [-a | --interactive] [-s] [-v] [-u[<mode>]]
           [(-c | -C) <commit> | -F <file> | -m <msg> | --amend]
           [--allow-empty] [--no-verify] [-e] [--author <author>]
           [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -150,12 +150,16 @@ but can be used to amend a merge commit.
        the last commit without committing changes that have
        already been staged.
 
--u|--untracked-files::
-       Show all untracked files, also those in uninteresting
-       directories, in the "Untracked files:" section of commit
-       message template.  Without this option only its name and
-       a trailing slash are displayed for each untracked
-       directory.
+-u[<mode>]|--untracked-files[=<mode>]::
+       Show untracked files (Default: 'all').
++
+The mode parameter is optional, and is used to specify
+the handling of untracked files. The possible options are:
++
+--
+       - 'normal' - Shows untracked files and directories
+       - 'all'    - Also shows individual files in untracked directories.
+--
 
 -v|--verbose::
        Show unified diff between the HEAD commit and what
index 90200ed643bcf21f28a66396f0d15db920a5d4c8..446a1086fd78e96dc46d78cd61d05ab456944a51 100644 (file)
@@ -49,7 +49,8 @@ static char *logfile, *force_author, *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, untracked_files, no_verify, allow_empty;
+static int quiet, verbose, no_verify, allow_empty;
+static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
  * beginning with # (shell comments) and leading and trailing
@@ -102,7 +103,7 @@ static struct option builtin_commit_options[] = {
        OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
        OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
-       OPT_BOOLEAN('u', "untracked-files", &untracked_files, "show all untracked files"),
+       { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
        OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
        OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
 
@@ -347,7 +348,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
                s.reference = "HEAD^1";
        }
        s.verbose = verbose;
-       s.untracked = untracked_files;
+       s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
        s.index_file = index_file;
        s.fp = fp;
        s.nowarn = nowarn;
@@ -795,6 +796,15 @@ static int parse_and_validate_options(int argc, const char *argv[],
        else
                die("Invalid cleanup mode %s", cleanup_arg);
 
+       if (!untracked_files_arg)
+               ; /* default already initialized */
+       else if (!strcmp(untracked_files_arg, "normal"))
+               show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+       else if (!strcmp(untracked_files_arg, "all"))
+               show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+       else
+               die("Invalid untracked files mode '%s'", untracked_files_arg);
+
        if (all && argc > 0)
                die("Paths with -a does not make sense.");
        else if (interactive && argc > 0)
index 80a438d4d988baa54a25e5725665904c6c45f431..0d24e259fb69f9e0be51a9f997bb92176b55600d 100755 (executable)
@@ -67,6 +67,67 @@ test_expect_success 'status (2)' '
 
 '
 
+cat >expect <<EOF
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#      new file:   dir2/added
+#
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#
+#      modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#      dir1/untracked
+#      dir2/modified
+#      dir2/untracked
+#      dir3/
+#      expect
+#      output
+#      untracked
+EOF
+test_expect_success 'status -unormal' '
+       mkdir dir3 &&
+       : > dir3/untracked1 &&
+       : > dir3/untracked2 &&
+       git status -unormal >output &&
+       test_cmp expect output
+'
+
+cat >expect <<EOF
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#      new file:   dir2/added
+#
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#
+#      modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#      dir1/untracked
+#      dir2/modified
+#      dir2/untracked
+#      dir3/untracked1
+#      dir3/untracked2
+#      expect
+#      output
+#      untracked
+EOF
+test_expect_success 'status -uall' '
+       git status -uall >output &&
+       rm -rf dir3 &&
+       test_cmp expect output
+'
+
 cat > expect << \EOF
 # On branch master
 # Changes to be committed:
index 5b4d74c1f3f4c24aa23cf564a16592d188449da1..25d998513e270a6e85dafcc6796560ab086ce517 100644 (file)
@@ -27,6 +27,7 @@ static const char use_add_rm_msg[] =
 "use \"git add/rm <file>...\" to update what will be committed";
 static const char use_add_to_include_msg[] =
 "use \"git add <file>...\" to include in what will be committed";
+enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 
 static int parse_status_slot(const char *var, int offset)
 {
index 597c7ea988634409f920c86008f5ba70910722f9..54f756de2be173879c69ec6204535c7efb5c18e1 100644 (file)
@@ -11,6 +11,12 @@ enum color_wt_status {
        WT_STATUS_NOBRANCH,
 };
 
+enum untracked_status_type {
+       SHOW_NORMAL_UNTRACKED_FILES = 1,
+       SHOW_ALL_UNTRACKED_FILES
+};
+extern enum untracked_status_type show_untracked_files;
+
 struct wt_status {
        int is_initial;
        char *branch;