Skip to content

Commit 46f721c

Browse files
peffgitster
authored andcommitted
add status.relativePaths config variable
The output of git-status was recently changed to output relative paths. Setting this variable to false restores the old behavior for any old-timers that prefer it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c3ce326 commit 46f721c

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ showbranch.default::
762762
The default set of branches for gitlink:git-show-branch[1].
763763
See gitlink:git-show-branch[1].
764764

765+
status.relativePaths::
766+
By default, gitlink:git-status[1] shows paths relative to the
767+
current directory. Setting this variable to `false` shows paths
768+
relative to the repository root (this was the default for git
769+
prior to v1.5.4).
770+
765771
tar.umask::
766772
This variable can be used to restrict the permission bits of
767773
tar archive entries. The default is 0002, which turns off the

Documentation/git-status.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ template comments, and all the output lines are prefixed with '#'.
4242

4343
The paths mentioned in the output, unlike many other git commands, are
4444
made relative to the current directory, if you are working in a
45-
subdirectory (this is on purpose, to help cutting and pasting).
45+
subdirectory (this is on purpose, to help cutting and pasting). See
46+
the status.relativePaths config option below.
4647

4748

4849
CONFIGURATION
@@ -53,6 +54,10 @@ mean the same thing and the latter is kept for backward
5354
compatibility) and `color.status.<slot>` configuration variables
5455
to colorize its output.
5556

57+
If the config variable `status.relativePaths` is set to false, then all
58+
paths shown are relative to the repository root, not to the current
59+
directory.
60+
5661
See Also
5762
--------
5863
gitlink:gitignore[5]

builtin-commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)
285285
struct wt_status s;
286286

287287
wt_status_prepare(&s);
288-
s.prefix = prefix;
288+
if (wt_status_relative_paths)
289+
s.prefix = prefix;
289290

290291
if (amend) {
291292
s.amend = 1;

t/t7502-status.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,35 @@ test_expect_success 'status with relative paths' '
8888
8989
'
9090

91+
cat > expect << \EOF
92+
# On branch master
93+
# Changes to be committed:
94+
# (use "git reset HEAD <file>..." to unstage)
95+
#
96+
# new file: dir2/added
97+
#
98+
# Changed but not updated:
99+
# (use "git add <file>..." to update what will be committed)
100+
#
101+
# modified: dir1/modified
102+
#
103+
# Untracked files:
104+
# (use "git add <file>..." to include in what will be committed)
105+
#
106+
# dir1/untracked
107+
# dir2/modified
108+
# dir2/untracked
109+
# expect
110+
# output
111+
# untracked
112+
EOF
113+
114+
test_expect_success 'status without relative paths' '
115+
116+
git config status.relativePaths false
117+
(cd dir1 && git status) > output &&
118+
git diff expect output
119+
120+
'
121+
91122
test_done

wt-status.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "revision.h"
99
#include "diffcore.h"
1010

11+
int wt_status_relative_paths = 1;
1112
int wt_status_use_color = 0;
1213
static char wt_status_colors[][COLOR_MAXLEN] = {
1314
"", /* WT_STATUS_HEADER: normal */
@@ -400,6 +401,11 @@ int git_status_config(const char *k, const char *v)
400401
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
401402
int slot = parse_status_slot(k, 13);
402403
color_parse(v, k, wt_status_colors[slot]);
404+
return 0;
405+
}
406+
if (!strcmp(k, "status.relativepaths")) {
407+
wt_status_relative_paths = git_config_bool(k, v);
408+
return 0;
403409
}
404410
return git_default_config(k, v);
405411
}

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct wt_status {
2828

2929
int git_status_config(const char *var, const char *value);
3030
int wt_status_use_color;
31+
int wt_status_relative_paths;
3132
void wt_status_prepare(struct wt_status *s);
3233
void wt_status_print(struct wt_status *s);
3334

0 commit comments

Comments
 (0)