summaryrefslogtreecommitdiff
path: root/t/t3700-add.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t3700-add.sh')
-rwxr-xr-xt/t3700-add.sh107
1 files changed, 79 insertions, 28 deletions
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 8689b48..839c904 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -24,17 +24,27 @@ test_mode_in_index () {
esac
}
-test_expect_success \
- 'Test of git add' \
- 'touch foo && git add foo'
+test_expect_success 'Test of git add' '
+ touch foo && git add foo
+'
-test_expect_success \
- 'Post-check that foo is in the index' \
- 'git ls-files foo | grep foo'
+test_expect_success 'Test with no pathspecs' '
+ cat >expect <<-EOF &&
+ Nothing specified, nothing added.
+ hint: Maybe you wanted to say ${SQ}git add .${SQ}?
+ hint: Disable this message with "git config advice.addEmptyPathspec false"
+ EOF
+ git add 2>actual &&
+ test_cmp expect actual
+'
-test_expect_success \
- 'Test that "git add -- -q" works' \
- 'touch -- -q && git add -- -q'
+test_expect_success 'Post-check that foo is in the index' '
+ git ls-files foo | grep foo
+'
+
+test_expect_success 'Test that "git add -- -q" works' '
+ touch -- -q && git add -- -q
+'
BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
@@ -106,24 +116,32 @@ test_expect_success '.gitignore test setup' '
test_expect_success '.gitignore is honored' '
git add . &&
- ! (git ls-files | grep "\\.ig")
+ git ls-files >files &&
+ sed -n "/\\.ig/p" <files >actual &&
+ test_must_be_empty actual
'
test_expect_success 'error out when attempting to add ignored ones without -f' '
test_must_fail git add a.?? &&
- ! (git ls-files | grep "\\.ig")
+ git ls-files >files &&
+ sed -n "/\\.ig/p" <files >actual &&
+ test_must_be_empty actual
'
test_expect_success 'error out when attempting to add ignored ones without -f' '
test_must_fail git add d.?? &&
- ! (git ls-files | grep "\\.ig")
+ git ls-files >files &&
+ sed -n "/\\.ig/p" <files >actual &&
+ test_must_be_empty actual
'
test_expect_success 'error out when attempting to add ignored ones but add others' '
touch a.if &&
test_must_fail git add a.?? &&
- ! (git ls-files | grep "\\.ig") &&
- (git ls-files | grep a.if)
+ git ls-files >files &&
+ sed -n "/\\.ig/p" <files >actual &&
+ test_must_be_empty actual &&
+ grep a.if files
'
test_expect_success 'add ignored ones with -f' '
@@ -276,14 +294,14 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
rm -f foo2
test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
- git config add.ignore-errors 1 &&
- git reset --hard &&
- date >foo1 &&
- date >foo2 &&
- chmod 0 foo2 &&
- test_must_fail git add --verbose --no-ignore-errors . &&
- ! ( git ls-files foo1 | grep foo1 ) &&
- git config add.ignore-errors 0
+ git config add.ignore-errors 1 &&
+ git reset --hard &&
+ date >foo1 &&
+ date >foo2 &&
+ chmod 0 foo2 &&
+ test_must_fail git add --verbose --no-ignore-errors . &&
+ ! ( git ls-files foo1 | grep foo1 ) &&
+ git config add.ignore-errors 0
'
rm -f foo2
@@ -291,7 +309,7 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
git reset --hard &&
touch fo\[ou\]bar foobar &&
git add '\''fo\[ou\]bar'\'' &&
- git ls-files fo\[ou\]bar | fgrep fo\[ou\]bar &&
+ git ls-files fo\[ou\]bar | grep -F fo\[ou\]bar &&
! ( git ls-files foobar | grep foobar )
'
@@ -331,6 +349,40 @@ test_expect_success '"git add ." in empty repo' '
)
'
+test_expect_success '"git add" a embedded repository' '
+ rm -fr outer && git init outer &&
+ (
+ cd outer &&
+ for i in 1 2
+ do
+ name=inner$i &&
+ git init $name &&
+ git -C $name commit --allow-empty -m $name ||
+ return 1
+ done &&
+ git add . 2>actual &&
+ cat >expect <<-EOF &&
+ warning: adding embedded git repository: inner1
+ hint: You${SQ}ve added another git repository inside your current repository.
+ hint: Clones of the outer repository will not contain the contents of
+ hint: the embedded repository and will not know how to obtain it.
+ hint: If you meant to add a submodule, use:
+ hint:
+ hint: git submodule add <url> inner1
+ hint:
+ hint: If you added this path by mistake, you can remove it from the
+ hint: index with:
+ hint:
+ hint: git rm --cached inner1
+ hint:
+ hint: See "git help submodule" for more information.
+ hint: Disable this message with "git config advice.addEmbeddedRepo false"
+ warning: adding embedded git repository: inner2
+ EOF
+ test_cmp expect actual
+ )
+'
+
test_expect_success 'error on a repository with no commits' '
rm -fr empty &&
git init empty &&
@@ -362,8 +414,7 @@ cat >expect.err <<\EOF
The following paths are ignored by one of your .gitignore files:
ignored-file
hint: Use -f if you really want to add them.
-hint: Turn this message off by running
-hint: "git config advice.addIgnoredFile false"
+hint: Disable this message with "git config advice.addIgnoredFile false"
EOF
cat >expect.out <<\EOF
add 'track-this'
@@ -430,7 +481,7 @@ test_expect_success 'git add --chmod fails with non regular files (but updates t
test_ln_s_add foo foo3 &&
touch foo4 &&
test_must_fail git add --chmod=+x foo3 foo4 2>stderr &&
- test_i18ngrep "cannot chmod +x .foo3." stderr &&
+ test_grep "cannot chmod +x .foo3." stderr &&
test_mode_in_index 120000 foo3 &&
test_mode_in_index 100755 foo4
'
@@ -447,12 +498,12 @@ test_expect_success 'git add --chmod --dry-run reports error for non regular fil
git reset --hard &&
test_ln_s_add foo foo4 &&
test_must_fail git add --chmod=+x --dry-run foo4 2>stderr &&
- test_i18ngrep "cannot chmod +x .foo4." stderr
+ test_grep "cannot chmod +x .foo4." stderr
'
test_expect_success 'git add --chmod --dry-run reports error for unmatched pathspec' '
test_must_fail git add --chmod=+x --dry-run nonexistent 2>stderr &&
- test_i18ngrep "pathspec .nonexistent. did not match any files" stderr
+ test_grep "pathspec .nonexistent. did not match any files" stderr
'
test_expect_success 'no file status change if no pathspec is given' '