From f4a4b9aca3cb70fabe3e856fa61ca35a99e2b8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 29 Mar 2019 17:38:59 +0700 Subject: checkout: inform the user when removing branch state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a successful switch, if a merge, cherry-pick or revert is ongoing, it is canceled. This behavior has been with us from the very early beginning, soon after git-merge was created but never actually documented [1]. It may be a good idea to be transparent and tell the user if some operation is canceled. I consider this a better way of telling the user than just adding a sentence or two in git-checkout.txt, which will be mostly ignored anyway. PS. Originally I wanted to print more details like warning: cancelling an in-progress merge from which may allow some level of undo if the user wants to. But that seems a lot more work. Perhaps it can be improved later if people still want that. [1] ... and I will try not to argue whether it is a sensible behavior. There is some more discussion here if people are interested: CACsJy8Axa5WsLSjiscjnxVK6jQHkfs-gH959=YtUvQkWriAk5w@mail.gmail.com Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- branch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'branch.c') diff --git a/branch.c b/branch.c index 28b81a7e02..8dd5bb9f1c 100644 --- a/branch.c +++ b/branch.c @@ -337,11 +337,14 @@ void create_branch(struct repository *r, free(real_ref); } -void remove_branch_state(struct repository *r) +void remove_branch_state(struct repository *r, int verbose) { - unlink(git_path_cherry_pick_head(r)); - unlink(git_path_revert_head(r)); - unlink(git_path_merge_head(r)); + if (!unlink(git_path_cherry_pick_head(r)) && verbose) + warning(_("cancelling a cherry picking in progress")); + if (!unlink(git_path_revert_head(r)) && verbose) + warning(_("cancelling a revert in progress")); + if (!unlink(git_path_merge_head(r)) && verbose) + warning(_("cancelling a merge in progress")); unlink(git_path_merge_rr(r)); unlink(git_path_merge_msg(r)); unlink(git_path_merge_mode(r)); -- cgit v1.2.3