diff options
Diffstat (limited to 't/t2070-restore.sh')
-rwxr-xr-x | t/t2070-restore.sh | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh index 21c3f84459..7c43ddf1d9 100755 --- a/t/t2070-restore.sh +++ b/t/t2070-restore.sh @@ -2,6 +2,9 @@ test_description='restore basic functionality' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh test_expect_success 'setup' ' @@ -15,7 +18,7 @@ test_expect_success 'setup' ' echo ignored >ignored && echo /ignored >.gitignore && git add one two .gitignore && - git update-ref refs/heads/one master + git update-ref refs/heads/one main ' test_expect_success 'restore without pathspec is not ok' ' @@ -69,6 +72,17 @@ test_expect_success 'restore --staged uses HEAD as source' ' test_cmp expected actual ' +test_expect_success 'restore --worktree --staged uses HEAD as source' ' + test_when_finished git reset --hard && + git show HEAD:./first.t >expected && + echo dirty >>first.t && + git add first.t && + git restore --worktree --staged first.t && + git show :./first.t >actual && + test_cmp expected actual && + test_cmp expected first.t +' + test_expect_success 'restore --ignore-unmerged ignores unmerged entries' ' git init unmerged && ( @@ -80,7 +94,7 @@ test_expect_success 'restore --ignore-unmerged ignores unmerged entries' ' git switch -c first && echo first >unmerged && git commit -am first && - git switch -c second master && + git switch -c second main && echo second >unmerged && git commit -am second && test_must_fail git merge first && @@ -106,4 +120,21 @@ test_expect_success 'restore --staged adds deleted intent-to-add file back to in git diff --cached --exit-code ' +test_expect_success 'restore --staged invalidates cache tree for deletions' ' + test_when_finished git reset --hard && + >new1 && + >new2 && + git add new1 new2 && + + # It is important to commit and then reset here, so that the index + # contains a valid cache-tree for the "both" tree. + git commit -m both && + git reset --soft HEAD^ && + + git restore --staged new1 && + git commit -m "just new2" && + git rev-parse HEAD:new2 && + test_must_fail git rev-parse HEAD:new1 +' + test_done |