"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Tracey Emery <tracey@traceyemery.net>
Subject:
Re: fix 'got log' repository path confusion
To:
gameoftrees@openbsd.org
Date:
Fri, 24 Apr 2020 08:04:55 -0600

Download raw body.

Thread
On Fri, Apr 24, 2020 at 10:58:03AM +0200, Stefan Sperling wrote:
> 'got log' can get confused about which repository to use.
> 
> If the -r option is used while in a work tree, references get loaded
> from the repository associated with the work tree instead of loading
> them from the same repository that was passed via -r. 
> 
> I noticed this because the clone.sh tests are failing if they run in
> a got project work tree which is switched to a branch other than master.
> 

ok tracey

> diff 59d5e252cee2c78ee6217704af2c93d99b282572 /home/stsp/src/got
> blob - 377d2b0c790ca00f298b74a5033d163a290f3e60
> file + got/got.c
> --- got/got.c
> +++ got/got.c
> @@ -3389,10 +3389,12 @@ cmd_log(int argc, char *argv[])
>  		goto done;
>  	}
>  
> -	error = got_worktree_open(&worktree, cwd);
> -	if (error && error->code != GOT_ERR_NOT_WORKTREE)
> -		goto done;
> -	error = NULL;
> +	if (repo_path == NULL) {
> +		error = got_worktree_open(&worktree, cwd);
> +		if (error && error->code != GOT_ERR_NOT_WORKTREE)
> +			goto done;
> +		error = NULL;
> +	}
>  
>  	if (argc == 0) {
>  		path = strdup("");
> blob - a92186b2b16972f09b0b1e3bb41f213be3c136f7
> file + regress/cmdline/log.sh
> --- regress/cmdline/log.sh
> +++ regress/cmdline/log.sh
> @@ -547,6 +547,71 @@ function test_log_reverse_display {
>  	test_done "$testroot" "$ret"
>  }
>  
> +function test_log_in_worktree_different_repo {
> +	local testroot=`test_init log_in_worktree_different_repo 1`
> +
> +	make_test_tree $testroot/repo
> +	mkdir -p $testroot/repo/epsilon/d
> +	echo foo > $testroot/repo/epsilon/d/foo
> +	(cd $testroot/repo && git add .)
> +	git_commit $testroot/repo -m "adding the test tree"
> +	local head_commit=`git_show_head $testroot/repo`
> +
> +	got init $testroot/other-repo
> +	mkdir -p $testroot/tree
> +	make_test_tree $testroot/tree
> +	got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
> +	got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
> +	ret="$?"
> +	if [ "$ret" != "0" ]; then
> +		test_done "$testroot" "$ret"
> +		return 1
> +	fi
> +
> +	echo "commit $head_commit (master)" > $testroot/stdout.expected
> +
> +	# 'got log' used to fail with "reference refs/heads/foo not found"
> +	# even though that reference belongs to an unrelated repository
> +	# found via a worktree via the current working directory
> +	for p in "" alpha epsilon; do
> +		(cd $testroot/wt && got log -r $testroot/repo $p | \
> +			grep ^commit > $testroot/stdout)
> +		cmp -s $testroot/stdout.expected $testroot/stdout
> +		ret="$?"
> +		if [ "$ret" != "0" ]; then
> +			diff -u $testroot/stdout.expected $testroot/stdout
> +			test_done "$testroot" "$ret"
> +			return 1
> +		fi
> +	done
> +
> +	for p in "" epsilon/zeta; do
> +		(cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
> +			grep ^commit > $testroot/stdout)
> +		cmp -s $testroot/stdout.expected $testroot/stdout
> +		ret="$?"
> +		if [ "$ret" != "0" ]; then
> +			diff -u $testroot/stdout.expected $testroot/stdout
> +			test_done "$testroot" "$ret"
> +			return 1
> +		fi
> +	done
> +
> +	for p in "" foo; do
> +		(cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
> +			grep ^commit > $testroot/stdout)
> +		cmp -s $testroot/stdout.expected $testroot/stdout
> +		ret="$?"
> +		if [ "$ret" != "0" ]; then
> +			diff -u $testroot/stdout.expected $testroot/stdout
> +			test_done "$testroot" "$ret"
> +			return 1
> +		fi
> +	done
> +
> +	test_done "$testroot" "0"
> +}
> +
>  run_test test_log_in_repo
>  run_test test_log_in_bare_repo
>  run_test test_log_in_worktree
> @@ -556,3 +621,4 @@ run_test test_log_limit
>  run_test test_log_nonexistent_path
>  run_test test_log_end_at_commit
>  run_test test_log_reverse_display
> +run_test test_log_in_worktree_different_repo

-- 

Tracey Emery