git status: not "commit --dry-run" anymore

This removes tentative "git stat" and make it take over "git status".

There are some tests that expect "git status" to exit with non-zero status
when there is something staged.  Some tests expect "git status path..." to
show the status for a partial commit.

For these, replace "git status" with "git commit --dry-run".  For the
ones that do not attempt a dry-run of a partial commit that check the
output from the command, check the output from "git status" as well, as
they should be identical.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2009-08-15 02:27:39 -07:00
parent 173e6c8852
commit 9e4b7ab652
9 changed files with 88 additions and 49 deletions

View file

@ -8,7 +8,7 @@ git-status - Show the working tree status
SYNOPSIS SYNOPSIS
-------- --------
'git status' <options>... 'git status' [<options>...] [--] [<pathspec>...]
DESCRIPTION DESCRIPTION
----------- -----------
@ -20,25 +20,85 @@ are what you _would_ commit by running `git commit`; the second and
third are what you _could_ commit by running 'git-add' before running third are what you _could_ commit by running 'git-add' before running
`git commit`. `git commit`.
The command takes the same set of options as 'git-commit'; it OPTIONS
shows what would be committed if the same options are given to -------
'git-commit'.
If there is no path that is different between the index file and -s::
the current HEAD commit (i.e., there is nothing to commit by running --short::
`git commit`), the command exits with non-zero status. Give the output in the short-format.
-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:
+
--
- 'no' - Show no untracked files
- 'normal' - Shows untracked files and directories
- 'all' - Also shows individual files in untracked directories.
--
+
See linkgit:git-config[1] for configuration variable
used to change the default for when the option is not
specified.
-z::
Terminate entries with NUL, instead of LF. This implies `-s`
(short status) output format.
OUTPUT OUTPUT
------ ------
The output from this command is designed to be used as a commit The output from this command is designed to be used as a commit
template comment, and all the output lines are prefixed with '#'. template comment, and all the output lines are prefixed with '#'.
The default, long format, is designed to be human readable,
verbose and descriptive. They are subject to change in any time.
The paths mentioned in the output, unlike many other git commands, are The paths mentioned in the output, unlike many other git commands, are
made relative to the current directory if you are working in a made relative to the current directory if you are working in a
subdirectory (this is on purpose, to help cutting and pasting). See subdirectory (this is on purpose, to help cutting and pasting). See
the status.relativePaths config option below. the status.relativePaths config option below.
In short-format, the status of each path is shown as
XY PATH1 -> PATH2
where `PATH1` is the path in the `HEAD`, and ` -> PATH2` part is
shown only when `PATH1` corresponds to a different path in the
index/worktree (i.e. renamed).
For unmerged entries, `X` shows the status of stage #2 (i.e. ours) and `Y`
shows the status of stage #3 (i.e. theirs).
For entries that do not have conflicts, `X` shows the status of the index,
and `Y` shows the status of the work tree. For untracked paths, `XY` are
`??`.
X Y Meaning
-------------------------------------------------
[MD] not updated
M [ MD] updated in index
A [ MD] added to index
D [ MD] deleted from index
R [ MD] renamed in index
C [ MD] copied in index
[MARC] index and work tree matches
[ MARC] M work tree changed since index
[ MARC] D deleted in work tree
-------------------------------------------------
D D unmerged, both deleted
A U unmerged, added by us
U D unmerged, deleted by them
U A unmerged, added by them
D U unmerged, deleted by us
A A unmerged, both added
U U unmerged, both modified
-------------------------------------------------
? ? untracked
-------------------------------------------------
CONFIGURATION CONFIGURATION
------------- -------------
@ -63,8 +123,7 @@ linkgit:gitignore[5]
Author Author
------ ------
Written by Linus Torvalds <torvalds@osdl.org> and Written by Junio C Hamano <gitster@pobox.com>.
Junio C Hamano <gitster@pobox.com>.
Documentation Documentation
-------------- --------------

View file

@ -378,7 +378,6 @@ BUILT_INS += git-init$X
BUILT_INS += git-merge-subtree$X BUILT_INS += git-merge-subtree$X
BUILT_INS += git-peek-remote$X BUILT_INS += git-peek-remote$X
BUILT_INS += git-repo-config$X BUILT_INS += git-repo-config$X
BUILT_INS += git-stat$X
BUILT_INS += git-show$X BUILT_INS += git-show$X
BUILT_INS += git-stage$X BUILT_INS += git-stage$X
BUILT_INS += git-status$X BUILT_INS += git-status$X

View file

@ -36,11 +36,6 @@ static const char * const builtin_status_usage[] = {
NULL NULL
}; };
static const char * const builtin_stat_usage[] = {
"git stat [options]",
NULL
};
static unsigned char head_sha1[20], merge_head_sha1[20]; static unsigned char head_sha1[20], merge_head_sha1[20];
static char *use_message_buffer; static char *use_message_buffer;
static const char commit_editmsg[] = "COMMIT_EDITMSG"; static const char commit_editmsg[] = "COMMIT_EDITMSG";
@ -971,13 +966,13 @@ static void short_untracked(int null_termination, struct string_list_item *it,
} }
} }
int cmd_stat(int argc, const char **argv, const char *prefix) int cmd_status(int argc, const char **argv, const char *prefix)
{ {
struct wt_status s; struct wt_status s;
static int null_termination, shortstatus; static int null_termination, shortstatus;
int i; int i;
unsigned char sha1[20]; unsigned char sha1[20];
static struct option builtin_stat_options[] = { static struct option builtin_status_options[] = {
OPT__VERBOSE(&verbose), OPT__VERBOSE(&verbose),
OPT_BOOLEAN('s', "short", &shortstatus, OPT_BOOLEAN('s', "short", &shortstatus,
"show status concicely"), "show status concicely"),
@ -996,8 +991,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
wt_status_prepare(&s); wt_status_prepare(&s);
git_config(git_status_config, &s); git_config(git_status_config, &s);
argc = parse_options(argc, argv, prefix, argc = parse_options(argc, argv, prefix,
builtin_stat_options, builtin_status_options,
builtin_stat_usage, 0); builtin_status_usage, 0);
handle_untracked_files_arg(&s); handle_untracked_files_arg(&s);
if (*argv) if (*argv)
@ -1039,22 +1034,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }
int cmd_status(int argc, const char **argv, const char *prefix)
{
struct wt_status s;
wt_status_prepare(&s);
git_config(git_status_config, &s);
if (s.use_color == -1)
s.use_color = git_use_color_default;
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
argc = parse_and_validate_options(argc, argv, builtin_status_usage,
prefix, &s);
return dry_run_commit(argc, argv, prefix, &s);
}
static void print_summary(const char *prefix, const unsigned char *sha1) static void print_summary(const char *prefix, const unsigned char *sha1)
{ {
struct rev_info rev; struct rev_info rev;

View file

@ -95,7 +95,6 @@ extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
extern int cmd_shortlog(int argc, const char **argv, const char *prefix); extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
extern int cmd_show(int argc, const char **argv, const char *prefix); extern int cmd_show(int argc, const char **argv, const char *prefix);
extern int cmd_show_branch(int argc, const char **argv, const char *prefix); extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
extern int cmd_stat(int argc, const char **argv, const char *prefix);
extern int cmd_status(int argc, const char **argv, const char *prefix); extern int cmd_status(int argc, const char **argv, const char *prefix);
extern int cmd_stripspace(int argc, const char **argv, const char *prefix); extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);

1
git.c
View file

@ -350,7 +350,6 @@ static void handle_internal_command(int argc, const char **argv)
{ "shortlog", cmd_shortlog, USE_PAGER }, { "shortlog", cmd_shortlog, USE_PAGER },
{ "show-branch", cmd_show_branch, RUN_SETUP }, { "show-branch", cmd_show_branch, RUN_SETUP },
{ "show", cmd_show, RUN_SETUP | USE_PAGER }, { "show", cmd_show, RUN_SETUP | USE_PAGER },
{ "stat", cmd_stat, RUN_SETUP | NEED_WORK_TREE },
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
{ "stripspace", cmd_stripspace }, { "stripspace", cmd_stripspace },
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },

View file

@ -69,7 +69,7 @@ test_expect_success 'status' '
cd test && cd test &&
git checkout b1 >/dev/null && git checkout b1 >/dev/null &&
# reports nothing to commit # reports nothing to commit
test_must_fail git status test_must_fail git commit --dry-run
) >actual && ) >actual &&
grep "have 1 and 1 different" actual grep "have 1 and 1 different" actual
' '

View file

@ -50,9 +50,11 @@ test_expect_success 'M/D conflict does not segfault' '
git rm foo && git rm foo &&
git commit -m delete && git commit -m delete &&
test_must_fail git merge master && test_must_fail git merge master &&
test_must_fail git status > ../actual test_must_fail git commit --dry-run >../actual &&
) && test_cmp ../expect ../actual &&
test_cmp expect actual git status >../actual &&
test_cmp ../expect ../actual
)
' '
test_done test_done

View file

@ -19,8 +19,8 @@ test_expect_success 'status clean' '
git status | git status |
grep "nothing to commit" grep "nothing to commit"
' '
test_expect_success 'status -a clean' ' test_expect_success 'commit --dry-run -a clean' '
git status -a | git commit --dry-run -a |
grep "nothing to commit" grep "nothing to commit"
' '
test_expect_success 'rm submodule contents' ' test_expect_success 'rm submodule contents' '
@ -31,7 +31,7 @@ test_expect_success 'status clean (empty submodule dir)' '
grep "nothing to commit" grep "nothing to commit"
' '
test_expect_success 'status -a clean (empty submodule dir)' ' test_expect_success 'status -a clean (empty submodule dir)' '
git status -a | git commit --dry-run -a |
grep "nothing to commit" grep "nothing to commit"
' '

View file

@ -248,8 +248,8 @@ cat <<EOF >expect
# output # output
# untracked # untracked
EOF EOF
test_expect_success 'status of partial commit excluding new file in index' ' test_expect_success 'dry-run of partial commit excluding new file in index' '
git status dir1/modified >output && git commit --dry-run dir1/modified >output &&
test_cmp expect output test_cmp expect output
' '
@ -358,7 +358,9 @@ EOF
test_expect_success 'status submodule summary (clean submodule)' ' test_expect_success 'status submodule summary (clean submodule)' '
git commit -m "commit submodule" && git commit -m "commit submodule" &&
git config status.submodulesummary 10 && git config status.submodulesummary 10 &&
test_must_fail git status >output && test_must_fail git commit --dry-run >output &&
test_cmp expect output &&
git status >output &&
test_cmp expect output test_cmp expect output
' '
@ -391,9 +393,9 @@ cat >expect <<EOF
# output # output
# untracked # untracked
EOF EOF
test_expect_success 'status submodule summary (--amend)' ' test_expect_success 'commit --dry-run submodule summary (--amend)' '
git config status.submodulesummary 10 && git config status.submodulesummary 10 &&
git status --amend >output && git commit --dry-run --amend >output &&
test_cmp expect output test_cmp expect output
' '