 13228c30a6
			
		
	
	13228c30a6
	
	
	
		
			
			The interpret_branch_name() function takes a ptr/len pair
for the name, but you can pass "0" for "namelen", which will
cause it to check the length with strlen().
However, before we do that auto-namelen magic, we call
interpret_nth_prior_checkout(), which gets fed the bogus
"0". This was broken by 8cd4249c4 (interpret_branch_name:
always respect "namelen" parameter, 2014-01-15).  Though to
be fair to that commit, it was broken in the _opposite_
direction before, where we would always treat "name" as a
string even if a length was passed.
You can see the bug with "git log -g @{-1}". That code path
always passes "0", and without this patch it cannot figure
out which branch's reflog to show.
We can fix it by a small reordering of the code.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
		
	
		
			
				
	
	
		
			69 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh
 | |
| 
 | |
| test_description='previous branch syntax @{-n}'
 | |
| 
 | |
| . ./test-lib.sh
 | |
| 
 | |
| test_expect_success 'branch -d @{-1}' '
 | |
| 	test_commit A &&
 | |
| 	git checkout -b junk &&
 | |
| 	git checkout - &&
 | |
| 	test "$(git symbolic-ref HEAD)" = refs/heads/master &&
 | |
| 	git branch -d @{-1} &&
 | |
| 	test_must_fail git rev-parse --verify refs/heads/junk
 | |
| '
 | |
| 
 | |
| test_expect_success 'branch -d @{-12} when there is not enough switches yet' '
 | |
| 	git reflog expire --expire=now &&
 | |
| 	git checkout -b junk2 &&
 | |
| 	git checkout - &&
 | |
| 	test "$(git symbolic-ref HEAD)" = refs/heads/master &&
 | |
| 	test_must_fail git branch -d @{-12} &&
 | |
| 	git rev-parse --verify refs/heads/master
 | |
| '
 | |
| 
 | |
| test_expect_success 'merge @{-1}' '
 | |
| 	git checkout A &&
 | |
| 	test_commit B &&
 | |
| 	git checkout A &&
 | |
| 	test_commit C &&
 | |
| 	test_commit D &&
 | |
| 	git branch -f master B &&
 | |
| 	git branch -f other &&
 | |
| 	git checkout other &&
 | |
| 	git checkout master &&
 | |
| 	git merge @{-1} &&
 | |
| 	git cat-file commit HEAD | grep "Merge branch '\''other'\''"
 | |
| '
 | |
| 
 | |
| test_expect_success 'merge @{-1}~1' '
 | |
| 	git checkout master &&
 | |
| 	git reset --hard B &&
 | |
| 	git checkout other &&
 | |
| 	git checkout master &&
 | |
| 	git merge @{-1}~1 &&
 | |
| 	git cat-file commit HEAD >actual &&
 | |
| 	grep "Merge branch '\''other'\''" actual
 | |
| '
 | |
| 
 | |
| test_expect_success 'merge @{-100} before checking out that many branches yet' '
 | |
| 	git reflog expire --expire=now &&
 | |
| 	git checkout -f master &&
 | |
| 	git reset --hard B &&
 | |
| 	git branch -f other C &&
 | |
| 	git checkout other &&
 | |
| 	git checkout master &&
 | |
| 	test_must_fail git merge @{-100}
 | |
| '
 | |
| 
 | |
| test_expect_success 'log -g @{-1}' '
 | |
| 	git checkout -b last_branch &&
 | |
| 	git checkout -b new_branch &&
 | |
| 	echo "last_branch@{0}" >expect &&
 | |
| 	git log -g --format=%gd @{-1} >actual &&
 | |
| 	test_cmp expect actual
 | |
| '
 | |
| 
 | |
| test_done
 | |
| 
 |