status: add status.aheadbehind setting
The --[no-]ahead-behind option was introduced in fd9b544a (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 <jeffhost@microsoft.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff Hostetler committed
Jun 18, 2019 at 13:21 UTC
06b324c1d71411cdd31da03da9e85b1880ef1c4b
4 files changed
+56
-1
Documentation/config/status.txt
+5
@@ -12,6 +12,11 @@ status.branch::
12
Set to true to enable --branch by default in linkgit:git-status[1].
13
The option --no-branch takes precedence over this variable.
14
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
+
20
status.displayCommentPrefix::
21
If set to true, linkgit:git-status[1] will insert a comment
22
prefix before each output line (starting with
builtin/commit.c
+16
-1
@@ -1078,9 +1078,11 @@ static const char *read_commit_message(const char *name)
1078
static struct status_deferred_config {
1079
enum wt_status_format status_format;
1080
int show_branch;
1081
+ enum ahead_behind_flags ahead_behind;
1082
} status_deferred_config = {
1083
STATUS_FORMAT_UNSPECIFIED,
1083
- -1 /* unspecified */
1084
+ -1, /* unspecified */
1085
+ AHEAD_BEHIND_UNSPECIFIED,
1086
};
1087
1088
static void finalize_deferred_config(struct wt_status *s)
@@ -1107,6 +1109,15 @@ static void finalize_deferred_config(struct wt_status *s)
1109
if (s->show_branch < 0)
1110
s->show_branch = 0;
1111
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
+
1121
if (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)
1122
s->ahead_behind_flags = AHEAD_BEHIND_FULL;
1123
}
@@ -1246,6 +1257,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
1257
status_deferred_config.show_branch = git_config_bool(k, v);
1258
return 0;
1259
}
1260
+ if (!strcmp(k, "status.aheadbehind")) {
1261
+ status_deferred_config.ahead_behind = git_config_bool(k, v);
1262
+ return 0;
1263
+ }
1264
if (!strcmp(k, "status.showstash")) {
1265
s->show_stash = git_config_bool(k, v);
1266
return 0;
t/t6040-tracking-info.sh
+31
@@ -159,6 +159,19 @@ test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
159
test_i18ncmp expect actual
160
'
161
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
+
175
cat >expect <<\EOF
176
On branch b1
177
Your branch and 'origin/master' have diverged,
@@ -174,6 +187,15 @@ test_expect_success 'status --long --branch' '
187
test_i18ncmp expect actual
188
'
189
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
+
199
cat >expect <<\EOF
200
On branch b1
201
Your branch and 'origin/master' refer to different commits.
@@ -188,6 +210,15 @@ test_expect_success 'status --long --branch --no-ahead-behind' '
210
test_i18ncmp expect actual
211
'
212
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
+
222
cat >expect <<\EOF
223
## b5...brokenbase [gone]
224
EOF
t/t7064-wtstatus-pv2.sh
+4
@@ -436,6 +436,10 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '
436
git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
437
test_cmp expect actual &&
438
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
+
443
# Confirm --ahead-behind reports traditional branch.ab with 1/0.
444
cat >expect <<-EOF &&
445
# branch.oid $HUF