3 test_description='restore basic functionality'
7 test_expect_success 'setup' '
9 echo first-and-a-half >>first.t &&
14 echo untracked >untracked &&
15 echo ignored >ignored &&
16 echo /ignored >.gitignore &&
17 git add one two .gitignore &&
18 git update-ref refs/heads/one master
21 test_expect_success 'restore without pathspec is not ok' '
22 test_must_fail git restore &&
23 test_must_fail git restore --source=first
26 test_expect_success 'restore a file, ignoring branch of same name' '
33 test_expect_success 'restore a file on worktree from another ref' '
34 test_when_finished git reset --hard &&
35 git cat-file blob first:./first.t >expected &&
36 git restore --source=first first.t &&
37 test_cmp expected first.t &&
38 git cat-file blob HEAD:./first.t >expected &&
39 git show :first.t >actual &&
40 test_cmp expected actual
43 test_expect_success 'restore a file in the index from another ref' '
44 test_when_finished git reset --hard &&
45 git cat-file blob first:./first.t >expected &&
46 git restore --source=first --staged first.t &&
47 git show :first.t >actual &&
48 test_cmp expected actual &&
49 git cat-file blob HEAD:./first.t >expected &&
50 test_cmp expected first.t
53 test_expect_success 'restore a file in both the index and worktree from another ref' '
54 test_when_finished git reset --hard &&
55 git cat-file blob first:./first.t >expected &&
56 git restore --source=first --staged --worktree first.t &&
57 git show :first.t >actual &&
58 test_cmp expected actual &&
59 test_cmp expected first.t
62 test_expect_success 'restore --staged uses HEAD as source' '
63 test_when_finished git reset --hard &&
64 git cat-file blob :./first.t >expected &&
65 echo index-dirty >>first.t &&
67 git restore --staged first.t &&
68 git cat-file blob :./first.t >actual &&
69 test_cmp expected actual
72 test_expect_success 'restore --ignore-unmerged ignores unmerged entries' '
78 git add unmerged common &&
79 git commit -m common &&
80 git switch -c first &&
81 echo first >unmerged &&
82 git commit -am first &&
83 git switch -c second master &&
84 echo second >unmerged &&
85 git commit -am second &&
86 test_must_fail git merge first &&
88 echo dirty >>common &&
89 test_must_fail git restore . &&
91 git restore --ignore-unmerged --quiet . >output 2>&1 &&
92 git diff common >diff-output &&
93 test_must_be_empty output &&
94 test_must_be_empty diff-output