Merge branch 'rj/branch-copy-and-rename' into maint-2.39
Fix a pair of bugs in 'git branch'.
* rj/branch-copy-and-rename:
  branch: force-copy a branch to itself via @{-1} is a no-op
			
			
				maint
			
			
		
						commit
						2f80d1b42e
					
				| 
						 | 
				
			
			@ -581,13 +581,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
 | 
			
		|||
	strbuf_release(&logmsg);
 | 
			
		||||
 | 
			
		||||
	strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
 | 
			
		||||
	strbuf_release(&oldref);
 | 
			
		||||
	strbuf_addf(&newsection, "branch.%s", interpreted_newname);
 | 
			
		||||
	strbuf_release(&newref);
 | 
			
		||||
	if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
 | 
			
		||||
		die(_("Branch is renamed, but update of config-file failed"));
 | 
			
		||||
	if (copy && strcmp(oldname, newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
 | 
			
		||||
	if (copy && strcmp(interpreted_oldname, interpreted_newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
 | 
			
		||||
		die(_("Branch is copied, but update of config-file failed"));
 | 
			
		||||
	strbuf_release(&oldref);
 | 
			
		||||
	strbuf_release(&newref);
 | 
			
		||||
	strbuf_release(&oldsection);
 | 
			
		||||
	strbuf_release(&newsection);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,6 +57,16 @@ test_expect_success 'create branch with pseudo-qualified name' '
 | 
			
		|||
	expect_branch refs/heads/refs/heads/qualified two
 | 
			
		||||
'
 | 
			
		||||
 | 
			
		||||
test_expect_success 'force-copy a branch to itself via @{-1} is no-op' '
 | 
			
		||||
	git branch -t copiable main &&
 | 
			
		||||
	git checkout copiable &&
 | 
			
		||||
	git checkout - &&
 | 
			
		||||
	git branch -C @{-1} copiable &&
 | 
			
		||||
	git config --get-all branch.copiable.merge >actual &&
 | 
			
		||||
	echo refs/heads/main >expect &&
 | 
			
		||||
	test_cmp expect actual
 | 
			
		||||
'
 | 
			
		||||
 | 
			
		||||
test_expect_success 'delete branch via @{-1}' '
 | 
			
		||||
	git branch previous-del &&
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue