It's been a long time since the v3 of the patch. So, it's worth restating the reason behind this patch. >From v1 of this patch, In builtin/branch, the error messages weren't handled directly by the branch renaming function and was left to the other function. Though this avoids redundancy this gave unclear error messages in some cases. So, make builtin/branch give more useful error messages. Changes since v3: - Handled more error related to old branch name. - Incorporated changes suggested in v3 which include using ';' as a sentence connector instead 'and'. - Error messages use the interpreted branch names (without the (refs/heads/ part). The unrelated cleanup patches which were in the previous versions have since been submitted as a separate series and have been merged into the codebase. The first two patches are related to the topic of this patch. The 3rd one is a little typo fix that I noticed on the way. This patch was based off 'master' and has been rebased to incorporate the new changes to 'master'. So, it generally should apply cleanly on 'master'. Let me know if it doesn't. The sample input/output cases for this patch are as follows, $ git branch * master foo bar Before patch, # Case 1: Trying to rename non-existent branch $ git branch -m hypothet no_such_branch error: refname refs/heads/hypothet not found fatal: Branch rename failed # Case 2: Trying to rename non-existent branch to an existing one $ git branch -m hypothet master fatal: A branch named 'master' already exists. # Case 3: Trying to force update current branch $ git branch -M foo master fatal: Cannot force update the current branch. # Case 4: Trying to force rename an in-existent branch with an invalid name $ git branch -M hypothet ?123 fatal: '?123' is not a valid branch name. After patch, # Case 1: Trying to rename non-existent branch $ git branch -m hypothet no_such_branch fatal: branch 'hypothet' doesn't exist # Case 2: Trying to rename non-existent branch to an existing one $ git branch -m hypothet master fatal: branch 'hypothet' doesn't exist; branch 'master' already exists # Case 3: Trying to force update current branch $ git branch -M foo master fatal: cannot force update the current branch # Case 4: Trying to force rename an in-existent branch with an invalid name $ git branch -M hypothet ?123 fatal: branch 'hypothet' doesn't exist; new branch name '?123' is invalid Note: Thanks to the strbuf API that made it possible to easily construct the composite error message strings! Kaartic Sivaraam (3): branch: introduce dont_fail parameter for branchname validation builtin/branch: give more useful error messages when renaming t/t3200: fix a typo in a test description branch.c | 59 +++++++++++++----------- branch.h | 61 ++++++++++++++++++++----- builtin/branch.c | 111 ++++++++++++++++++++++++++++++++++++++------- builtin/checkout.c | 5 +- t/t3200-branch.sh | 2 +- 5 files changed, 181 insertions(+), 57 deletions(-) -- 2.16.1.291.g4437f3f13