sha1_file: restore OBJECT_INFO_QUICK functionality
[gitweb.git] / t / t3701-add-interactive.sh
index 2bfd41f06e4435607760dbe6d78ec72633e46aba..a49c12c79b28fac8545dffcbaba8e8905c8d6222 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='add -i basic tests'
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
 
 if ! test_have_prereq PERL
 then
@@ -380,6 +381,100 @@ test_expect_success 'patch mode ignores unmerged entries' '
        test_cmp expected diff
 '
 
+test_expect_success TTY 'diffs can be colorized' '
+       git reset --hard &&
+
+       echo content >test &&
+       printf y | test_terminal git add -p >output 2>&1 &&
+
+       # We do not want to depend on the exact coloring scheme
+       # git uses for diffs, so just check that we saw some kind of color.
+       grep "$(printf "\\033")" output
+'
+
+test_expect_success 'patch-mode via -i prompts for files' '
+       git reset --hard &&
+
+       echo one >file &&
+       echo two >test &&
+       git add -i <<-\EOF &&
+       patch
+       test
+
+       y
+       quit
+       EOF
+
+       echo test >expect &&
+       git diff --cached --name-only >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'add -p handles globs' '
+       git reset --hard &&
+
+       mkdir -p subdir &&
+       echo base >one.c &&
+       echo base >subdir/two.c &&
+       git add "*.c" &&
+       git commit -m base &&
+
+       echo change >one.c &&
+       echo change >subdir/two.c &&
+       git add -p "*.c" <<-\EOF &&
+       y
+       y
+       EOF
+
+       cat >expect <<-\EOF &&
+       one.c
+       subdir/two.c
+       EOF
+       git diff --cached --name-only >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'add -p handles relative paths' '
+       git reset --hard &&
+
+       echo base >relpath.c &&
+       git add "*.c" &&
+       git commit -m relpath &&
+
+       echo change >relpath.c &&
+       mkdir -p subdir &&
+       git -C subdir add -p .. 2>error <<-\EOF &&
+       y
+       EOF
+
+       test_must_be_empty error &&
+
+       cat >expect <<-\EOF &&
+       relpath.c
+       EOF
+       git diff --cached --name-only >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'add -p does not expand argument lists' '
+       git reset --hard &&
+
+       echo content >not-changed &&
+       git add not-changed &&
+       git commit -m "add not-changed file" &&
+
+       echo change >file &&
+       GIT_TRACE=$(pwd)/trace.out git add -p . <<-\EOF &&
+       y
+       EOF
+
+       # we know that "file" must be mentioned since we actually
+       # update it, but we want to be sure that our "." pathspec
+       # was not expanded into the argument list of any command.
+       # So look only for "not-changed".
+       ! grep not-changed trace.out
+'
+
 test_expect_success 'hunk-editing handles custom comment char' '
        git reset --hard &&
        echo change >>file &&
@@ -388,4 +483,14 @@ test_expect_success 'hunk-editing handles custom comment char' '
        git diff --exit-code
 '
 
+test_expect_success 'add -p works even with color.ui=always' '
+       git reset --hard &&
+       echo change >>file &&
+       test_config color.ui always &&
+       echo y | git add -p &&
+       echo file >expect &&
+       git diff --cached --name-only >actual &&
+       test_cmp expect actual
+'
+
 test_done