]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t3705: add tests for `git add` in sparse checkouts
authorMatheus Tavares <matheus.bernardino@usp.br>
Thu, 8 Apr 2021 20:41:23 +0000 (17:41 -0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Apr 2021 21:18:03 +0000 (14:18 -0700)
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>
t/t3705-add-sparse-checkout.sh [new file with mode: 0755]
t/t7012-skip-worktree-writing.sh

diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh
new file mode 100755 (executable)
index 0000000..6c5b8be
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+test_description='git add in sparse checked out working trees'
+
+. ./test-lib.sh
+
+SPARSE_ENTRY_BLOB=""
+
+# Optionally take a printf format string to write to the sparse_entry file
+setup_sparse_entry () {
+       # 'sparse_entry' might already be in the index with the skip-worktree
+       # bit set. Remove it so that the subsequent git add can update it.
+       git update-index --force-remove sparse_entry &&
+       if test $# -eq 1
+       then
+               printf "$1" >sparse_entry
+       else
+               >sparse_entry
+       fi &&
+       git add sparse_entry &&
+       git update-index --skip-worktree sparse_entry &&
+       SPARSE_ENTRY_BLOB=$(git rev-parse :sparse_entry)
+}
+
+test_sparse_entry_unchanged () {
+       echo "100644 $SPARSE_ENTRY_BLOB 0       sparse_entry" >expected &&
+       git ls-files --stage sparse_entry >actual &&
+       test_cmp expected actual
+}
+
+setup_gitignore () {
+       test_when_finished rm -f .gitignore &&
+       cat >.gitignore <<-EOF
+       *
+       !/sparse_entry
+       EOF
+}
+
+test_expect_success 'git add does not remove sparse entries' '
+       setup_sparse_entry &&
+       rm sparse_entry &&
+       git add sparse_entry &&
+       test_sparse_entry_unchanged
+'
+
+test_expect_success 'git add -A does not remove sparse entries' '
+       setup_sparse_entry &&
+       rm sparse_entry &&
+       setup_gitignore &&
+       git add -A &&
+       test_sparse_entry_unchanged
+'
+
+test_expect_success 'git add . does not remove sparse entries' '
+       setup_sparse_entry &&
+       rm sparse_entry &&
+       setup_gitignore &&
+       git add . &&
+       test_sparse_entry_unchanged
+'
+
+for opt in "" -f -u --ignore-removal --dry-run
+do
+       test_expect_success "git add${opt:+ $opt} does not update sparse entries" '
+               setup_sparse_entry &&
+               echo modified >sparse_entry &&
+               git add $opt sparse_entry &&
+               test_sparse_entry_unchanged
+       '
+done
+
+test_expect_success 'git add --refresh does not update sparse entries' '
+       setup_sparse_entry &&
+       git ls-files --debug sparse_entry | grep mtime >before &&
+       test-tool chmtime -60 sparse_entry &&
+       git add --refresh sparse_entry &&
+       git ls-files --debug sparse_entry | grep mtime >after &&
+       test_cmp before after
+'
+
+test_expect_failure 'git add --chmod does not update sparse entries' '
+       setup_sparse_entry &&
+       git add --chmod=+x sparse_entry &&
+       test_sparse_entry_unchanged &&
+       ! test -x sparse_entry
+'
+
+test_expect_failure 'git add --renormalize does not update sparse entries' '
+       test_config core.autocrlf false &&
+       setup_sparse_entry "LINEONE\r\nLINETWO\r\n" &&
+       echo "sparse_entry text=auto" >.gitattributes &&
+       git add --renormalize sparse_entry &&
+       test_sparse_entry_unchanged
+'
+
+test_done
index f2a8e765114fd1a01f1256a6768353cd2ab69b4a..a1080b94e388aef309c958e9ca7d6150e2577b06 100755 (executable)
@@ -60,13 +60,6 @@ setup_absent() {
        git update-index --skip-worktree 1
 }
 
-test_absent() {
-       echo "100644 $EMPTY_BLOB 0      1" > expected &&
-       git ls-files --stage 1 > result &&
-       test_cmp expected result &&
-       test ! -f 1
-}
-
 setup_dirty() {
        git update-index --force-remove 1 &&
        echo dirty > 1 &&
@@ -100,18 +93,6 @@ test_expect_success 'index setup' '
        test_cmp expected result
 '
 
-test_expect_success 'git-add ignores worktree content' '
-       setup_absent &&
-       git add 1 &&
-       test_absent
-'
-
-test_expect_success 'git-add ignores worktree content' '
-       setup_dirty &&
-       git add 1 &&
-       test_dirty
-'
-
 test_expect_success 'git-rm fails if worktree is dirty' '
        setup_dirty &&
        test_must_fail git rm 1 &&