wt-status: don't show divergence advice when committing
When the user is in the middle of making a commit, they are not yet at the point where they are ready to think about integrating their local branch with the corresponding remote branch or force-pushing over the remote branch. Don't include advice on how to deal with divergent branches in the commit template, to avoid giving the impression that the divergence needs to be dealt with immediately. Similar advice will be printed when it is most relevant, that is, if the user does try to push without first reconciling the two branches. Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alex Henrie committed
Jul 12, 2023 at 22:41 UTC
b6f3da51322345a19c259b9359065aa54cda74ff
5 files changed
+13
-11
builtin/checkout.c
+1
-1
@@ -916,7 +916,7 @@ static void report_tracking(struct branch_info *new_branch_info)
916
struct strbuf sb = STRBUF_INIT;
917
struct branch *branch = branch_get(new_branch_info->name);
918
919
- if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL))
919
+ if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL, 1))
920
return;
921
fputs(sb.buf, stdout);
922
strbuf_release(&sb);
remote.c
+4
-2
@@ -2258,7 +2258,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2258
* Return true when there is anything to report, otherwise false.
2259
*/
2260
int format_tracking_info(struct branch *branch, struct strbuf *sb,
2261
- enum ahead_behind_flags abf)
2261
+ enum ahead_behind_flags abf,
2262
+ int show_divergence_advice)
2263
{
2264
int ours, theirs, sti;
2265
const char *full_base;
@@ -2321,7 +2322,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
2322
"respectively.\n",
2323
ours + theirs),
2324
base, ours, theirs);
2324
- if (advice_enabled(ADVICE_STATUS_HINTS))
2325
+ if (show_divergence_advice &&
2326
+ advice_enabled(ADVICE_STATUS_HINTS))
2327
strbuf_addstr(sb,
2328
_(" (use \"git pull\" to merge the remote branch into yours)\n"));
2329
}
remote.h
+2
-1
@@ -380,7 +380,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
380
const char **upstream_name, int for_push,
381
enum ahead_behind_flags abf);
382
int format_tracking_info(struct branch *branch, struct strbuf *sb,
383
- enum ahead_behind_flags abf);
383
+ enum ahead_behind_flags abf,
384
+ int show_divergence_advice);
385
386
struct ref *get_local_heads(void);
387
/*
t/t7508-status.sh
+4
-6
@@ -847,7 +847,6 @@ test_expect_success 'dry-run of partial commit excluding new file in index' '
847
On branch main
848
Your branch and '\''upstream'\'' have diverged,
849
and have 1 and 2 different commits each, respectively.
850
- (use "git pull" to merge the remote branch into yours)
850
851
Changes to be committed:
852
(use "git restore --staged <file>..." to unstage)
@@ -1013,7 +1012,7 @@ test_expect_success 'status -s submodule summary' '
1012
'
1013
1014
test_expect_success 'status submodule summary (clean submodule): commit' '
1016
- cat >expect <<EOF &&
1015
+ cat >expect-status <<EOF &&
1016
On branch main
1017
Your branch and '\''upstream'\'' have diverged,
1018
and have 2 and 2 different commits each, respectively.
@@ -1033,12 +1032,13 @@ Untracked files:
1032
1033
no changes added to commit (use "git add" and/or "git commit -a")
1034
EOF
1035
+ sed "/git pull/d" expect-status > expect-commit &&
1036
git commit -m "commit submodule" &&
1037
git config status.submodulesummary 10 &&
1038
test_must_fail git commit --dry-run >output &&
1039
- test_cmp expect output &&
1039
+ test_cmp expect-commit output &&
1040
git status >output &&
1041
- test_cmp expect output
1041
+ test_cmp expect-status output
1042
'
1043
1044
cat >expect <<EOF
@@ -1065,7 +1065,6 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
1065
On branch main
1066
Your branch and '\''upstream'\'' have diverged,
1067
and have 2 and 2 different commits each, respectively.
1068
- (use "git pull" to merge the remote branch into yours)
1068
1069
Changes to be committed:
1070
(use "git restore --source=HEAD^1 --staged <file>..." to unstage)
@@ -1558,7 +1557,6 @@ test_expect_success 'git commit --dry-run will show a staged but ignored submodu
1557
On branch main
1558
Your branch and '\''upstream'\'' have diverged,
1559
and have 2 and 2 different commits each, respectively.
1561
- (use "git pull" to merge the remote branch into yours)
1560
1561
Changes to be committed:
1562
(use "git restore --staged <file>..." to unstage)
wt-status.c
+2
-1
@@ -1186,7 +1186,8 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
1186
1187
t_begin = getnanotime();
1188
1189
- if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
1189
+ if (!format_tracking_info(branch, &sb, s->ahead_behind_flags,
1190
+ !s->commit_template))
1191
return;
1192
1193
if (advice_enabled(ADVICE_STATUS_AHEAD_BEHIND_WARNING) &&