t3705: add tests for `git add` in sparse checkouts
We already have a couple tests for `add` with SKIP_WORKTREE entries in t7012, but these only cover the most basic scenarios. As we will be changing how `add` deals with sparse paths in the subsequent commits, let's move these two tests to their own file and add more test cases for different `add` options and situations. This also demonstrates two options that don't currently respect SKIP_WORKTREE entries: `--chmod` and `--renormalize`. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matheus Tavares committed
Apr 8, 2021 at 17:41 UTC
6594afc3cc4bd87247b44d3d3bf75d693fc066aa
2 files changed
+96
-19
t/t3705-add-sparse-checkout.sh
new
+96
@@ -0,0 +1,96 @@
1
+#!/bin/sh
2
+
3
+test_description='git add in sparse checked out working trees'
4
+
5
+. ./test-lib.sh
6
+
7
+SPARSE_ENTRY_BLOB=""
8
+
9
+# Optionally take a printf format string to write to the sparse_entry file
10
+setup_sparse_entry () {
11
+ # 'sparse_entry' might already be in the index with the skip-worktree
12
+ # bit set. Remove it so that the subsequent git add can update it.
13
+ git update-index --force-remove sparse_entry &&
14
+ if test $# -eq 1
15
+ then
16
+ printf "$1" >sparse_entry
17
+ else
18
+ >sparse_entry
19
+ fi &&
20
+ git add sparse_entry &&
21
+ git update-index --skip-worktree sparse_entry &&
22
+ SPARSE_ENTRY_BLOB=$(git rev-parse :sparse_entry)
23
+}
24
+
25
+test_sparse_entry_unchanged () {
26
+ echo "100644 $SPARSE_ENTRY_BLOB 0 sparse_entry" >expected &&
27
+ git ls-files --stage sparse_entry >actual &&
28
+ test_cmp expected actual
29
+}
30
+
31
+setup_gitignore () {
32
+ test_when_finished rm -f .gitignore &&
33
+ cat >.gitignore <<-EOF
34
+ *
35
+ !/sparse_entry
36
+ EOF
37
+}
38
+
39
+test_expect_success 'git add does not remove sparse entries' '
40
+ setup_sparse_entry &&
41
+ rm sparse_entry &&
42
+ git add sparse_entry &&
43
+ test_sparse_entry_unchanged
44
+'
45
+
46
+test_expect_success 'git add -A does not remove sparse entries' '
47
+ setup_sparse_entry &&
48
+ rm sparse_entry &&
49
+ setup_gitignore &&
50
+ git add -A &&
51
+ test_sparse_entry_unchanged
52
+'
53
+
54
+test_expect_success 'git add . does not remove sparse entries' '
55
+ setup_sparse_entry &&
56
+ rm sparse_entry &&
57
+ setup_gitignore &&
58
+ git add . &&
59
+ test_sparse_entry_unchanged
60
+'
61
+
62
+for opt in "" -f -u --ignore-removal --dry-run
63
+do
64
+ test_expect_success "git add${opt:+ $opt} does not update sparse entries" '
65
+ setup_sparse_entry &&
66
+ echo modified >sparse_entry &&
67
+ git add $opt sparse_entry &&
68
+ test_sparse_entry_unchanged
69
+ '
70
+done
71
+
72
+test_expect_success 'git add --refresh does not update sparse entries' '
73
+ setup_sparse_entry &&
74
+ git ls-files --debug sparse_entry | grep mtime >before &&
75
+ test-tool chmtime -60 sparse_entry &&
76
+ git add --refresh sparse_entry &&
77
+ git ls-files --debug sparse_entry | grep mtime >after &&
78
+ test_cmp before after
79
+'
80
+
81
+test_expect_failure 'git add --chmod does not update sparse entries' '
82
+ setup_sparse_entry &&
83
+ git add --chmod=+x sparse_entry &&
84
+ test_sparse_entry_unchanged &&
85
+ ! test -x sparse_entry
86
+'
87
+
88
+test_expect_failure 'git add --renormalize does not update sparse entries' '
89
+ test_config core.autocrlf false &&
90
+ setup_sparse_entry "LINEONE\r\nLINETWO\r\n" &&
91
+ echo "sparse_entry text=auto" >.gitattributes &&
92
+ git add --renormalize sparse_entry &&
93
+ test_sparse_entry_unchanged
94
+'
95
+
96
+test_done
t/t7012-skip-worktree-writing.sh
-19
@@ -60,13 +60,6 @@ setup_absent() {
60
git update-index --skip-worktree 1
61
}
62
63
-test_absent() {
64
- echo "100644 $EMPTY_BLOB 0 1" > expected &&
65
- git ls-files --stage 1 > result &&
66
- test_cmp expected result &&
67
- test ! -f 1
68
-}
69
-
63
setup_dirty() {
64
git update-index --force-remove 1 &&
65
echo dirty > 1 &&
@@ -100,18 +93,6 @@ test_expect_success 'index setup' '
93
test_cmp expected result
94
'
95
103
-test_expect_success 'git-add ignores worktree content' '
104
- setup_absent &&
105
- git add 1 &&
106
- test_absent
107
-'
108
-
109
-test_expect_success 'git-add ignores worktree content' '
110
- setup_dirty &&
111
- git add 1 &&
112
- test_dirty
113
-'
114
-
96
test_expect_success 'git-rm fails if worktree is dirty' '
97
setup_dirty &&
98
test_must_fail git rm 1 &&