From: "Heba Waly via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Heba Waly <heba.waly@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 0/1] [Outreachy] [RFC] branch: advise the user to checkout a different branch before deleting
Date: Tue, 07 Jan 2020 04:10:25 +0000 [thread overview]
Message-ID: <pull.507.v2.git.1578370226.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.507.git.1577933387.gitgitgadget@gmail.com>
When a user attempts to delete a checked out branch, an error message is
displayed saying: "error: Cannot delete branch checked out at ". This patch
suggests displaying a hint after the error message advising the user to
checkout another branch first using "git checkout ".
Heba Waly (1):
branch: advise the user to checkout a different branch before deleting
advice.c | 4 +++-
advice.h | 1 +
builtin/branch.c | 14 ++++++++++++++
t/t3200-branch.sh | 6 ++++--
4 files changed, 22 insertions(+), 3 deletions(-)
base-commit: 0a76bd7381ec0dbb7c43776eb6d1ac906bca29e6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-507%2FHebaWaly%2Fdelete_branch_hint-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-507/HebaWaly/delete_branch_hint-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/507
Range-diff vs v1:
1: 82bf24ce53 ! 1: 19a7cc1889 branch: advise the user to checkout a different branch before deleting
@@ -3,15 +3,48 @@
branch: advise the user to checkout a different branch before deleting
Display a hint to the user when attempting to delete a checked out
- branch saying "Checkout another branch before deleting this one:
- git checkout <branch_name>".
+ branch.
Currently the user gets an error message saying: "error: Cannot delete
- branch <branch_name> checked out at <path>". The hint will be displayed
+ branch <branch> checked out at <path>". The hint will be displayed
after the error message.
Signed-off-by: Heba Waly <heba.waly@gmail.com>
+ diff --git a/advice.c b/advice.c
+ --- a/advice.c
+ +++ b/advice.c
+@@
+ int advice_checkout_ambiguous_remote_branch_name = 1;
+ int advice_nested_tag = 1;
+ int advice_submodule_alternate_error_strategy_die = 1;
++int advice_delete_checkedout_branch = 1;
+
+ static int advice_use_color = -1;
+ static char advice_colors[][COLOR_MAXLEN] = {
+@@
+ { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
+ { "nestedTag", &advice_nested_tag },
+ { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
+-
++ { "deleteCheckedoutBranch", &advice_delete_checkedout_branch },
++
+ /* make this an alias for backward compatibility */
+ { "pushNonFastForward", &advice_push_update_rejected }
+ };
+
+ diff --git a/advice.h b/advice.h
+ --- a/advice.h
+ +++ b/advice.h
+@@
+ extern int advice_checkout_ambiguous_remote_branch_name;
+ extern int advice_nested_tag;
+ extern int advice_submodule_alternate_error_strategy_die;
++extern int advice_delete_checkedout_branch;
+
+ int git_default_advice_config(const char *var, const char *value);
+ __attribute__((format (printf, 1, 2)))
+
diff --git a/builtin/branch.c b/builtin/branch.c
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -19,8 +52,20 @@
error(_("Cannot delete branch '%s' "
"checked out at '%s'"),
bname.buf, wt->path);
-+ advise(_("Checkout another branch before deleting this "
-+ "one: git checkout <branch_name>"));
++ if (advice_delete_checkedout_branch) {
++ if (wt->is_current) {
++ advise(_("The branch you are trying to delete is already "
++ "checked out, run the following command to "
++ "checkout a different branch then try again:\n"
++ "git switch <branch>"));
++ }
++ else {
++ advise(_("The branch you are trying to delete is checked "
++ "out on another worktree, run the following command "
++ "to checkout a different branch then try again:\n"
++ "git -C %s switch <branch>"), wt->path);
++ }
++ }
ret = 1;
continue;
}
@@ -29,12 +74,15 @@
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@
+
test_expect_success 'deleting currently checked out branch fails' '
git worktree add -b my7 my7 &&
- test_must_fail git -C my7 branch -d my7 &&
+- test_must_fail git -C my7 branch -d my7 &&
- test_must_fail git branch -d my7 &&
-+ test_must_fail git branch -d my7 >actual.out 2>actual.err &&
-+ test_i18ngrep "hint: Checkout another branch" actual.err &&
++ test_must_fail git -C my7 branch -d my7 2>output1.err &&
++ test_must_fail git branch -d my7 2>output2.err &&
++ test_i18ngrep "hint: The branch you are trying to delete is already checked out" output1.err &&
++ test_i18ngrep "hint: The branch you are trying to delete is checked out on another worktree" output2.err &&
rm -r my7 &&
git worktree prune
'
--
gitgitgadget
next prev parent reply other threads:[~2020-01-07 4:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-02 2:49 [PATCH 0/1] [Outreachy] [RFC] branch: advise the user to checkout a different branch before deleting Heba Waly via GitGitGadget
2020-01-02 2:49 ` [PATCH 1/1] " Heba Waly via GitGitGadget
2020-01-02 8:18 ` Eric Sunshine
2020-01-06 0:42 ` Heba Waly
2020-01-07 4:10 ` Heba Waly via GitGitGadget [this message]
2020-01-07 4:10 ` [PATCH v2 " Heba Waly via GitGitGadget
2020-01-07 11:16 ` Eric Sunshine
2020-01-07 16:34 ` Junio C Hamano
2020-01-08 1:44 ` Emily Shaffer
2020-01-08 10:22 ` Eric Sunshine
2020-01-08 1:14 ` Heba Waly
2020-01-08 9:27 ` Eric Sunshine
2020-01-08 18:06 ` Heba Waly
2020-01-08 19:01 ` Johannes Schindelin
2020-01-08 19:15 ` Junio C Hamano
2020-01-10 12:11 ` Heba Waly
2020-01-08 19:05 ` Junio C Hamano
2020-01-10 12:09 ` Heba Waly
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.507.v2.git.1578370226.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=heba.waly@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.