Skip to content

Commit 06b324c

Browse files
jeffhostetlergitster
authored andcommitted
status: add status.aheadbehind setting
The --[no-]ahead-behind option was introduced in fd9b544 (status: add --[no-]ahead-behind to status and commit for V2 format, 2018-01-09). This is a necessary change of behavior in repos where the remote tracking branches can move very quickly ahead of the local branches. However, users need to remember to provide the command-line argument every time. Add a new "status.aheadBehind" config setting to change the default behavior of all git status formats. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a6a95cd commit 06b324c

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

Documentation/config/status.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ status.branch::
1212
Set to true to enable --branch by default in linkgit:git-status[1].
1313
The option --no-branch takes precedence over this variable.
1414

15+
status.aheadBehind::
16+
Set to true to enable `--ahead-behind` and false to enable
17+
`--no-ahead-behind` by default in linkgit:git-status[1] for
18+
non-porcelain status formats. Defaults to true.
19+
1520
status.displayCommentPrefix::
1621
If set to true, linkgit:git-status[1] will insert a comment
1722
prefix before each output line (starting with

builtin/commit.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,11 @@ static const char *read_commit_message(const char *name)
10781078
static struct status_deferred_config {
10791079
enum wt_status_format status_format;
10801080
int show_branch;
1081+
enum ahead_behind_flags ahead_behind;
10811082
} status_deferred_config = {
10821083
STATUS_FORMAT_UNSPECIFIED,
1083-
-1 /* unspecified */
1084+
-1, /* unspecified */
1085+
AHEAD_BEHIND_UNSPECIFIED,
10841086
};
10851087

10861088
static void finalize_deferred_config(struct wt_status *s)
@@ -1107,6 +1109,15 @@ static void finalize_deferred_config(struct wt_status *s)
11071109
if (s->show_branch < 0)
11081110
s->show_branch = 0;
11091111

1112+
/*
1113+
* If the user did not give a "--[no]-ahead-behind" command
1114+
* line argument, then we inherit the a/b config setting.
1115+
* If is not set, then we inherit _FULL for backwards
1116+
* compatibility.
1117+
*/
1118+
if (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)
1119+
s->ahead_behind_flags = status_deferred_config.ahead_behind;
1120+
11101121
if (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)
11111122
s->ahead_behind_flags = AHEAD_BEHIND_FULL;
11121123
}
@@ -1246,6 +1257,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
12461257
status_deferred_config.show_branch = git_config_bool(k, v);
12471258
return 0;
12481259
}
1260+
if (!strcmp(k, "status.aheadbehind")) {
1261+
status_deferred_config.ahead_behind = git_config_bool(k, v);
1262+
return 0;
1263+
}
12491264
if (!strcmp(k, "status.showstash")) {
12501265
s->show_stash = git_config_bool(k, v);
12511266
return 0;

t/t6040-tracking-info.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
159159
test_i18ncmp expect actual
160160
'
161161

162+
cat >expect <<\EOF
163+
## b1...origin/master [different]
164+
EOF
165+
166+
test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '
167+
(
168+
cd test &&
169+
git checkout b1 >/dev/null &&
170+
git -c status.aheadbehind=false status -s -b | head -1
171+
) >actual &&
172+
test_i18ncmp expect actual
173+
'
174+
162175
cat >expect <<\EOF
163176
On branch b1
164177
Your branch and 'origin/master' have diverged,
@@ -174,6 +187,15 @@ test_expect_success 'status --long --branch' '
174187
test_i18ncmp expect actual
175188
'
176189

190+
test_expect_success 'status --long --branch' '
191+
(
192+
cd test &&
193+
git checkout b1 >/dev/null &&
194+
git -c status.aheadbehind=true status --long -b | head -3
195+
) >actual &&
196+
test_i18ncmp expect actual
197+
'
198+
177199
cat >expect <<\EOF
178200
On branch b1
179201
Your branch and 'origin/master' refer to different commits.
@@ -188,6 +210,15 @@ test_expect_success 'status --long --branch --no-ahead-behind' '
188210
test_i18ncmp expect actual
189211
'
190212

213+
test_expect_success 'status.aheadbehind=false status --long --branch' '
214+
(
215+
cd test &&
216+
git checkout b1 >/dev/null &&
217+
git -c status.aheadbehind=false status --long -b | head -2
218+
) >actual &&
219+
test_i18ncmp expect actual
220+
'
221+
191222
cat >expect <<\EOF
192223
## b5...brokenbase [gone]
193224
EOF

t/t7064-wtstatus-pv2.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
436436
git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
437437
test_cmp expect actual &&
438438
439+
# Confirmat that "status.aheadbehind" works on V2 format.
440+
git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&
441+
test_cmp expect actual &&
442+
439443
# Confirm --ahead-behind reports traditional branch.ab with 1/0.
440444
cat >expect <<-EOF &&
441445
# branch.oid $HUF

0 commit comments

Comments
 (0)