@matheusbsbs / matheus-bagliano / commits / 4bfee30a98
Fork 0

Add an optional <mode> argument to commit/status -u|--untracked-files option

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>

Marius Storm-Olsen committed Jun 5, 2008 at 10:31 UTC 4bfee30a98783f7987c395e6006a2a6717344c04
5 files changed +92 -10
Documentation/git-commit.txt
+11 -7
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository
8 SYNOPSIS
9 --------
10 [verse]
11 -'git-commit' [-a | --interactive] [-s] [-v] [-u]
11 +'git-commit' [-a | --interactive] [-s] [-v] [-u[<mode>]]
12 [(-c | -C) <commit> | -F <file> | -m <msg> | --amend]
13 [--allow-empty] [--no-verify] [-e] [--author <author>]
14 [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -150,12 +150,16 @@ but can be used to amend a merge commit.
150 the last commit without committing changes that have
151 already been staged.
152
153 --u|--untracked-files::
154 - Show all untracked files, also those in uninteresting
155 - directories, in the "Untracked files:" section of commit
156 - message template. Without this option only its name and
157 - a trailing slash are displayed for each untracked
158 - directory.
153 +-u[<mode>]|--untracked-files[=<mode>]::
154 + Show untracked files (Default: 'all').
155 ++
156 +The mode parameter is optional, and is used to specify
157 +the handling of untracked files. The possible options are:
158 ++
159 +--
160 + - 'normal' - Shows untracked files and directories
161 + - 'all' - Also shows individual files in untracked directories.
162 +--
163
164 -v|--verbose::
165 Show unified diff between the HEAD commit and what
builtin-commit.c
+13 -3
@@ -49,7 +49,8 @@ static char *logfile, *force_author, *template_file;
49 static char *edit_message, *use_message;
50 static char *author_name, *author_email, *author_date;
51 static int all, edit_flag, also, interactive, only, amend, signoff;
52 -static int quiet, verbose, untracked_files, no_verify, allow_empty;
52 +static int quiet, verbose, no_verify, allow_empty;
53 +static char *untracked_files_arg;
54 /*
55 * The default commit message cleanup mode will remove the lines
56 * beginning with # (shell comments) and leading and trailing
@@ -102,7 +103,7 @@ static struct option builtin_commit_options[] = {
103 OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
104 OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
105 OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
105 - OPT_BOOLEAN('u', "untracked-files", &untracked_files, "show all untracked files"),
106 + { 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" },
107 OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
108 OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
109
@@ -347,7 +348,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
348 s.reference = "HEAD^1";
349 }
350 s.verbose = verbose;
350 - s.untracked = untracked_files;
351 + s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
352 s.index_file = index_file;
353 s.fp = fp;
354 s.nowarn = nowarn;
@@ -795,6 +796,15 @@ static int parse_and_validate_options(int argc, const char *argv[],
796 else
797 die("Invalid cleanup mode %s", cleanup_arg);
798
799 + if (!untracked_files_arg)
800 + ; /* default already initialized */
801 + else if (!strcmp(untracked_files_arg, "normal"))
802 + show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
803 + else if (!strcmp(untracked_files_arg, "all"))
804 + show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
805 + else
806 + die("Invalid untracked files mode '%s'", untracked_files_arg);
807 +
808 if (all && argc > 0)
809 die("Paths with -a does not make sense.");
810 else if (interactive && argc > 0)
t/t7502-status.sh
+61
@@ -67,6 +67,67 @@ test_expect_success 'status (2)' '
67
68 '
69
70 +cat >expect <<EOF
71 +# On branch master
72 +# Changes to be committed:
73 +# (use "git reset HEAD <file>..." to unstage)
74 +#
75 +# new file: dir2/added
76 +#
77 +# Changed but not updated:
78 +# (use "git add <file>..." to update what will be committed)
79 +#
80 +# modified: dir1/modified
81 +#
82 +# Untracked files:
83 +# (use "git add <file>..." to include in what will be committed)
84 +#
85 +# dir1/untracked
86 +# dir2/modified
87 +# dir2/untracked
88 +# dir3/
89 +# expect
90 +# output
91 +# untracked
92 +EOF
93 +test_expect_success 'status -unormal' '
94 + mkdir dir3 &&
95 + : > dir3/untracked1 &&
96 + : > dir3/untracked2 &&
97 + git status -unormal >output &&
98 + test_cmp expect output
99 +'
100 +
101 +cat >expect <<EOF
102 +# On branch master
103 +# Changes to be committed:
104 +# (use "git reset HEAD <file>..." to unstage)
105 +#
106 +# new file: dir2/added
107 +#
108 +# Changed but not updated:
109 +# (use "git add <file>..." to update what will be committed)
110 +#
111 +# modified: dir1/modified
112 +#
113 +# Untracked files:
114 +# (use "git add <file>..." to include in what will be committed)
115 +#
116 +# dir1/untracked
117 +# dir2/modified
118 +# dir2/untracked
119 +# dir3/untracked1
120 +# dir3/untracked2
121 +# expect
122 +# output
123 +# untracked
124 +EOF
125 +test_expect_success 'status -uall' '
126 + git status -uall >output &&
127 + rm -rf dir3 &&
128 + test_cmp expect output
129 +'
130 +
131 cat > expect << \EOF
132 # On branch master
133 # Changes to be committed:
wt-status.c
+1
@@ -27,6 +27,7 @@ static const char use_add_rm_msg[] =
27 "use \"git add/rm <file>...\" to update what will be committed";
28 static const char use_add_to_include_msg[] =
29 "use \"git add <file>...\" to include in what will be committed";
30 +enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
31
32 static int parse_status_slot(const char *var, int offset)
33 {
wt-status.h
+6
@@ -11,6 +11,12 @@ enum color_wt_status {
11 WT_STATUS_NOBRANCH,
12 };
13
14 +enum untracked_status_type {
15 + SHOW_NORMAL_UNTRACKED_FILES = 1,
16 + SHOW_ALL_UNTRACKED_FILES
17 +};
18 +extern enum untracked_status_type show_untracked_files;
19 +
20 struct wt_status {
21 int is_initial;
22 char *branch;