From 3f59481e338c2d3167b9654a4289a9d1201f7944 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Nov 2011 20:30:02 -0600 Subject: branch: allow a no-op "branch -M HEAD" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Overwriting the current branch with a different commit is forbidden, as it will make the status recorded in the index and the working tree out of sync with respect to the HEAD. There however is no reason to forbid it if the current branch is renamed to itself, which admittedly is something only an insane user would do, but is handy for scripts. Test script is by Conrad Irwin. Reported-by: Soeren Sonnenburg Reported-by: Josh Chia (谢任中) Signed-off-by: Jonathan Nieder Signed-off-by: Conrad Irwin Signed-off-by: Junio C Hamano --- t/t3200-branch.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/t3200-branch.sh') diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index bc73c2099..76903323a 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -115,6 +115,22 @@ test_expect_success 'git branch -M baz bam should succeed when baz is checked ou git branch -M baz bam ' +test_expect_success 'git branch -M master should work when master is checked out' ' + git checkout master && + git branch -M master +' + +test_expect_success 'git branch -M master master should work when master is checked out' ' + git checkout master && + git branch -M master master +' + +test_expect_success 'git branch -M master2 master2 should work when master is checked out' ' + git checkout master && + git branch master2 && + git branch -M master2 master2 +' + test_expect_success 'git branch -v -d t should work' ' git branch t && test_path_is_file .git/refs/heads/t && -- cgit v1.2.1