commit 50f2fadafa8ef856e1162b1ff4bff7e09adadd82 from: Stefan Sperling date: Fri Apr 24 16:22:28 2020 UTC fix 'got log -r' loading refs from the wrong repo if invoked in a work tree ok tracey commit - 59d5e252cee2c78ee6217704af2c93d99b282572 commit + 50f2fadafa8ef856e1162b1ff4bff7e09adadd82 blob - 377d2b0c790ca00f298b74a5033d163a290f3e60 blob + cce99fd025fb8106b5f21bfa90675c46ba374f06 --- 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 blob + ea958f5ec1a9401d85234c78905402873c196e81 --- regress/cmdline/log.sh +++ regress/cmdline/log.sh @@ -545,6 +545,71 @@ function test_log_reverse_display { diff -u $testroot/stdout.expected $testroot/stdout fi 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 @@ -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