1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 05:36:10 +02:00

Merge branch 'ah/advise-force-pushing'

Help newbies by suggesting that there are cases where force-pushing
is a valid and sensible thing to update a branch at a remote
repository, rather than reconciling with merge/rebase.

* ah/advise-force-pushing:
  push: don't imply that integration is always required before pushing
  remote: don't imply that integration is always required before pushing
  wt-status: don't show divergence advice when committing
This commit is contained in:
Junio C Hamano 2023-07-25 12:05:23 -07:00
commit 88d08c342a
6 changed files with 45 additions and 43 deletions

View File

@ -916,7 +916,7 @@ static void report_tracking(struct branch_info *new_branch_info)
struct strbuf sb = STRBUF_INIT;
struct branch *branch = branch_get(new_branch_info->name);
if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL))
if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL, 1))
return;
fputs(sb.buf, stdout);
strbuf_release(&sb);

View File

@ -301,21 +301,21 @@ static void setup_default_push_refspecs(int *flags, struct remote *remote)
static const char message_advice_pull_before_push[] =
N_("Updates were rejected because the tip of your current branch is behind\n"
"its remote counterpart. Integrate the remote changes (e.g.\n"
"'git pull ...') before pushing again.\n"
"its remote counterpart. If you want to integrate the remote changes,\n"
"use 'git pull' before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static const char message_advice_checkout_pull_push[] =
N_("Updates were rejected because a pushed branch tip is behind its remote\n"
"counterpart. Check out this branch and integrate the remote changes\n"
"(e.g. 'git pull ...') before pushing again.\n"
"counterpart. If you want to integrate the remote changes, use 'git pull'\n"
"before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static const char message_advice_ref_fetch_first[] =
N_("Updates were rejected because the remote contains work that you do\n"
"not have locally. This is usually caused by another repository pushing\n"
"to the same ref. You may want to first integrate the remote changes\n"
"(e.g., 'git pull ...') before pushing again.\n"
N_("Updates were rejected because the remote contains work that you do not\n"
"have locally. This is usually caused by another repository pushing to\n"
"the same ref. If you want to integrate the remote changes, use\n"
"'git pull' before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static const char message_advice_ref_already_exists[] =
@ -327,10 +327,10 @@ static const char message_advice_ref_needs_force[] =
"without using the '--force' option.\n");
static const char message_advice_ref_needs_update[] =
N_("Updates were rejected because the tip of the remote-tracking\n"
"branch has been updated since the last checkout. You may want\n"
"to integrate those changes locally (e.g., 'git pull ...')\n"
"before forcing an update.\n");
N_("Updates were rejected because the tip of the remote-tracking branch has\n"
"been updated since the last checkout. If you want to integrate the\n"
"remote changes, use 'git pull' before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static void advise_pull_before_push(void)
{

View File

@ -2259,7 +2259,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
* Return true when there is anything to report, otherwise false.
*/
int format_tracking_info(struct branch *branch, struct strbuf *sb,
enum ahead_behind_flags abf)
enum ahead_behind_flags abf,
int show_divergence_advice)
{
int ours, theirs, sti;
const char *full_base;
@ -2322,9 +2323,10 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
"respectively.\n",
ours + theirs),
base, ours, theirs);
if (advice_enabled(ADVICE_STATUS_HINTS))
if (show_divergence_advice &&
advice_enabled(ADVICE_STATUS_HINTS))
strbuf_addstr(sb,
_(" (use \"git pull\" to merge the remote branch into yours)\n"));
_(" (use \"git pull\" if you want to integrate the remote branch with yours)\n"));
}
free(base);
return 1;

View File

@ -380,7 +380,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
const char **upstream_name, int for_push,
enum ahead_behind_flags abf);
int format_tracking_info(struct branch *branch, struct strbuf *sb,
enum ahead_behind_flags abf);
enum ahead_behind_flags abf,
int show_divergence_advice);
struct ref *get_local_heads(void);
/*

View File

@ -92,7 +92,7 @@ test_expect_success 'status --column' '
# On branch main
# Your branch and '\''upstream'\'' have diverged,
# and have 1 and 2 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
# (use "git pull" if you want to integrate the remote branch with yours)
#
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
@ -123,7 +123,7 @@ cat >expect <<\EOF
# On branch main
# Your branch and 'upstream' have diverged,
# and have 1 and 2 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
# (use "git pull" if you want to integrate the remote branch with yours)
#
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
@ -270,7 +270,7 @@ test_expect_success 'status with gitignore' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -335,7 +335,7 @@ test_expect_success 'status with gitignore (nothing untracked)' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -405,7 +405,7 @@ test_expect_success 'status -uno' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -467,7 +467,7 @@ test_expect_success 'status -unormal' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -522,7 +522,7 @@ test_expect_success 'status -uall' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -582,7 +582,7 @@ test_expect_success 'status with relative paths' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -650,7 +650,7 @@ test_expect_success TTY 'status with color.ui' '
On branch <GREEN>main<RESET>
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -773,7 +773,7 @@ test_expect_success 'status without relative paths' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -847,7 +847,6 @@ test_expect_success 'dry-run of partial commit excluding new file in index' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -901,7 +900,7 @@ test_expect_success 'status submodule summary is disabled by default' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -958,7 +957,7 @@ test_expect_success 'status submodule summary' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -1013,11 +1012,11 @@ test_expect_success 'status -s submodule summary' '
'
test_expect_success 'status submodule summary (clean submodule): commit' '
cat >expect <<EOF &&
cat >expect-status <<EOF &&
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
@ -1033,12 +1032,13 @@ Untracked files:
no changes added to commit (use "git add" and/or "git commit -a")
EOF
sed "/git pull/d" expect-status > expect-commit &&
git commit -m "commit submodule" &&
git config status.submodulesummary 10 &&
test_must_fail git commit --dry-run >output &&
test_cmp expect output &&
test_cmp expect-commit output &&
git status >output &&
test_cmp expect output
test_cmp expect-status output
'
cat >expect <<EOF
@ -1065,7 +1065,6 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git restore --source=HEAD^1 --staged <file>..." to unstage)
@ -1117,7 +1116,7 @@ test_expect_success '--ignore-submodules=untracked suppresses submodules with un
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -1226,7 +1225,7 @@ test_expect_success "--ignore-submodules=untracked doesn't suppress submodules w
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -1283,7 +1282,7 @@ test_expect_success "--ignore-submodules=untracked doesn't suppress submodule su
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -1364,7 +1363,7 @@ cat > expect << EOF
; On branch main
; Your branch and 'upstream' have diverged,
; and have 2 and 2 different commits each, respectively.
; (use "git pull" to merge the remote branch into yours)
; (use "git pull" if you want to integrate the remote branch with yours)
;
; Changes to be committed:
; (use "git restore --staged <file>..." to unstage)
@ -1412,7 +1411,7 @@ test_expect_success "--ignore-submodules=all suppresses submodule summary" '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
@ -1438,7 +1437,7 @@ test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summar
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
(use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@ -1558,7 +1557,6 @@ test_expect_success 'git commit --dry-run will show a staged but ignored submodu
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)

View File

@ -1186,7 +1186,8 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
t_begin = getnanotime();
if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
if (!format_tracking_info(branch, &sb, s->ahead_behind_flags,
!s->commit_template))
return;
if (advice_enabled(ADVICE_STATUS_AHEAD_BEHIND_WARNING) &&