rev-list --count: comment on the use of count_right++
[alt-git.git] / t / t2070-restore.sh
blob21c3f84459dfe29053bbb0d9a43160a6df33f737
1 #!/bin/sh
3 test_description='restore basic functionality'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit first &&
9 echo first-and-a-half >>first.t &&
10 git add first.t &&
11 test_commit second &&
12 echo one >one &&
13 echo two >two &&
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' '
27 cat one >expected &&
28 echo dirty >>one &&
29 git restore one &&
30 test_cmp expected one
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 &&
66 git add 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' '
73 git init unmerged &&
75 cd unmerged &&
76 echo one >unmerged &&
77 echo one >common &&
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
98 test_expect_success 'restore --staged adds deleted intent-to-add file back to index' '
99 echo "nonempty" >nonempty &&
100 >empty &&
101 git add nonempty empty &&
102 git commit -m "create files to be deleted" &&
103 git rm --cached nonempty empty &&
104 git add -N nonempty empty &&
105 git restore --staged nonempty empty &&
106 git diff --cached --exit-code
109 test_done