[PATCH] Fix failing test t3700-add.sh

2016-07-29 Thread Ingo Brückl
At the time of the test xfoo1 already exists and is a link.
As a result, the check for file mode 100644 fails.

Create not yet existing file xfoo instead.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 4865304..aee61b9 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -342,12 +342,12 @@ test_expect_success 'git add --chmod=+x stages a 
non-executable file with +x' '
 '

 test_expect_success 'git add --chmod=-x stages an executable file with -x' '
-   echo foo >xfoo1 &&
-   chmod 755 xfoo1 &&
-   git add --chmod=-x xfoo1 &&
-   case "$(git ls-files --stage xfoo1)" in
-   100644" "*xfoo1) echo pass;;
-   *) echo fail; git ls-files --stage xfoo1; (exit 1);;
+   echo foo >xfoo &&
+   chmod 755 xfoo &&
+   git add --chmod=-x xfoo &&
+   case "$(git ls-files --stage xfoo)" in
+   100644" "*xfoo) echo pass;;
+   *) echo fail; git ls-files --stage xfoo; (exit 1);;
esac
 '

--
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/3] Simplify test t3700-add.sh

2016-07-29 Thread Ingo Brückl
Utilize the test_mode_in_index helper function.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh | 30 ++
 1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index c08ec9e..0e21a52 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -25,18 +25,12 @@ test_expect_success \
 echo foo >xfoo1 &&
 chmod 755 xfoo1 &&
 git add xfoo1 &&
-case "$(git ls-files --stage xfoo1)" in
-100644" "*xfoo1) echo pass;;
-*) echo fail; git ls-files --stage xfoo1; (exit 1);;
-esac'
+test_mode_in_index 100644 xfoo1'

 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
rm -f xfoo1 &&
test_ln_s_add foo xfoo1 &&
-   case "$(git ls-files --stage xfoo1)" in
-   12" "*xfoo1) echo pass;;
-   *) echo fail; git ls-files --stage xfoo1; (exit 1);;
-   esac
+   test_mode_in_index 12 xfoo1
 '

 test_expect_success \
@@ -45,28 +39,19 @@ test_expect_success \
 echo foo >xfoo2 &&
 chmod 755 xfoo2 &&
 git update-index --add xfoo2 &&
-case "$(git ls-files --stage xfoo2)" in
-100644" "*xfoo2) echo pass;;
-*) echo fail; git ls-files --stage xfoo2; (exit 1);;
-esac'
+test_mode_in_index 100644 xfoo2'

 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
rm -f xfoo2 &&
test_ln_s_add foo xfoo2 &&
-   case "$(git ls-files --stage xfoo2)" in
-   12" "*xfoo2) echo pass;;
-   *) echo fail; git ls-files --stage xfoo2; (exit 1);;
-   esac
+   test_mode_in_index 12 xfoo2
 '

 test_expect_success \
'git update-index --add: Test that executable bit is not used...' \
'git config core.filemode 0 &&
 test_ln_s_add xfoo2 xfoo3 &&   # runs git update-index --add
-case "$(git ls-files --stage xfoo3)" in
-12" "*xfoo3) echo pass;;
-*) echo fail; git ls-files --stage xfoo3; (exit 1);;
-esac'
+test_mode_in_index 12 xfoo3'

 test_expect_success '.gitignore test setup' '
echo "*.ig" >.gitignore &&
@@ -347,10 +332,7 @@ test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x 
with symlinks' '
rm -f foo2 &&
echo foo >foo2 &&
git add --chmod=+x foo2 &&
-   case "$(git ls-files --stage foo2)" in
-   100755" "*foo2) echo pass;;
-   *) echo fail; git ls-files --stage foo2; (exit 1);;
-   esac
+   test_mode_in_index 100755 foo2
 '

 test_done
--
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/3] Enhance test t3700-add.sh

2016-07-29 Thread Ingo Brückl
The files to be tested may already exist and be links which will make
the test fail. So ensure that we are working in a clean environment.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 4865304..494f5b8 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -333,6 +333,7 @@ test_expect_success 'git add --dry-run --ignore-missing of 
non-existing file out
 '

 test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
+   rm -f foo1 &&
echo foo >foo1 &&
git add --chmod=+x foo1 &&
case "$(git ls-files --stage foo1)" in
@@ -342,6 +343,7 @@ test_expect_success 'git add --chmod=+x stages a 
non-executable file with +x' '
 '

 test_expect_success 'git add --chmod=-x stages an executable file with -x' '
+   rm -f xfoo1 &&
echo foo >xfoo1 &&
chmod 755 xfoo1 &&
git add --chmod=-x xfoo1 &&
@@ -354,6 +356,7 @@ test_expect_success 'git add --chmod=-x stages an 
executable file with -x' '
 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
git config core.filemode 1 &&
git config core.symlinks 1 &&
+   rm -f foo2 &&
echo foo >foo2 &&
git add --chmod=+x foo2 &&
case "$(git ls-files --stage foo2)" in
--
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/3] Make test t3700-add.sh more robust

2016-07-29 Thread Ingo Brückl
Don't rely on chmod to work on the underlying platform (although it
wouldn't harm the result of the '--chmod=-x' test). Directly check the
result of the --chmod option.

Add a test_mode_in_index helper function in order to check for success.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh  | 20 
 t/test-lib-functions.sh | 14 ++
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 494f5b8..c08ec9e 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -332,25 +332,13 @@ test_expect_success 'git add --dry-run --ignore-missing 
of non-existing file out
test_i18ncmp expect.err actual.err
 '

-test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
+test_expect_success 'git add --chmod=[+-]x stages correctly' '
rm -f foo1 &&
echo foo >foo1 &&
git add --chmod=+x foo1 &&
-   case "$(git ls-files --stage foo1)" in
-   100755" "*foo1) echo pass;;
-   *) echo fail; git ls-files --stage foo1; (exit 1);;
-   esac
-'
-
-test_expect_success 'git add --chmod=-x stages an executable file with -x' '
-   rm -f xfoo1 &&
-   echo foo >xfoo1 &&
-   chmod 755 xfoo1 &&
-   git add --chmod=-x xfoo1 &&
-   case "$(git ls-files --stage xfoo1)" in
-   100644" "*xfoo1) echo pass;;
-   *) echo fail; git ls-files --stage xfoo1; (exit 1);;
-   esac
+   test_mode_in_index 100755 foo1 &&
+   git add --chmod=-x foo1 &&
+   test_mode_in_index 100644 foo1
 '

 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 4f7eadb..0e6652b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -990,3 +990,17 @@ test_copy_bytes () {
}
' - "$1"
 }
+
+# Test the file mode "$1" of the file "$2" in the index.
+test_mode_in_index () {
+   case "$(git ls-files --stage "$2")" in
+   $1\ *"$2")
+   echo pass
+   ;;
+   *)
+   echo fail
+   git ls-files --stage "$2"
+   return 1
+   ;;
+   esac
+}
--
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/3] t3700: merge two tests into one

2016-07-30 Thread Ingo Brückl
Depending on the underlying platform a chmod may be a noop. Although it
wouldn't harm the result of the '--chmod=-x' test, there is a more
robust way to make sure the --chmod option works both ways.

Merge the two separate tests for the --chmod option into one, checking
both permissions on the same file.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 494f5b8..1fa5dfd 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -332,24 +332,18 @@ test_expect_success 'git add --dry-run --ignore-missing 
of non-existing file out
test_i18ncmp expect.err actual.err
 '

-test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
+test_expect_success 'git add --chmod=[+-]x stages correctly' '
rm -f foo1 &&
echo foo >foo1 &&
git add --chmod=+x foo1 &&
case "$(git ls-files --stage foo1)" in
100755" "*foo1) echo pass;;
*) echo fail; git ls-files --stage foo1; (exit 1);;
-   esac
-'
-
-test_expect_success 'git add --chmod=-x stages an executable file with -x' '
-   rm -f xfoo1 &&
-   echo foo >xfoo1 &&
-   chmod 755 xfoo1 &&
-   git add --chmod=-x xfoo1 &&
-   case "$(git ls-files --stage xfoo1)" in
-   100644" "*xfoo1) echo pass;;
-   *) echo fail; git ls-files --stage xfoo1; (exit 1);;
+   esac &&
+   git add --chmod=-x foo1 &&
+   case "$(git ls-files --stage foo1)" in
+   100644" "*foo1) echo pass;;
+   *) echo fail; git ls-files --stage foo1; (exit 1);;
esac
 '

--
2.9.2
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/3] t3700: remove unwanted leftover files before running new tests

2016-07-30 Thread Ingo Brückl
When an earlier test that has prerequisite is skipped, files
used by later tests may be left in the working tree in an
unexpected state.  For example, a test runs this sequence:

echo foo >xfoo1 && chmod 755 xfoo1

to create an executable file xfoo1, expecting that xfoo1
does not exist before it runs in the test sequence.
However, the absence of this file depends on "git reset
--hard" done in an earlier test, that is skipped when SANITY
prerequisite is not met, and worse yet, xfoo1 originally is
created as a symbolic link, which means the chmod does not
affect the modes of xfoo1 as this test expects.

Fix this by starting the test with "rm -f xfoo1" to make
sure the file is created from scratch, and do the same to
other similar tests.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 4865304..494f5b8 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -333,6 +333,7 @@ test_expect_success 'git add --dry-run --ignore-missing of 
non-existing file out
 '

 test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
+   rm -f foo1 &&
echo foo >foo1 &&
git add --chmod=+x foo1 &&
case "$(git ls-files --stage foo1)" in
@@ -342,6 +343,7 @@ test_expect_success 'git add --chmod=+x stages a 
non-executable file with +x' '
 '

 test_expect_success 'git add --chmod=-x stages an executable file with -x' '
+   rm -f xfoo1 &&
echo foo >xfoo1 &&
chmod 755 xfoo1 &&
git add --chmod=-x xfoo1 &&
@@ -354,6 +356,7 @@ test_expect_success 'git add --chmod=-x stages an 
executable file with -x' '
 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
git config core.filemode 1 &&
git config core.symlinks 1 &&
+   rm -f foo2 &&
echo foo >foo2 &&
git add --chmod=+x foo2 &&
case "$(git ls-files --stage foo2)" in
--
2.9.2
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] t3700: add a test_mode_in_index helper function

2016-07-30 Thread Ingo Brückl
The case statement to check the file mode of a staged file appears
a number of times.

Simplify the test by utilizing a test_mode_in_index helper function.

Signed-off-by: Ingo Brückl <i...@wupperonline.de>
---
 t/t3700-add.sh | 54 ++
 1 file changed, 22 insertions(+), 32 deletions(-)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 1fa5dfd..7b98483 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'

 . ./test-lib.sh

+# Test the file mode "$1" of the file "$2" in the index.
+test_mode_in_index () {
+   case "$(git ls-files --stage "$2")" in
+   $1\ *"$2")
+   echo pass
+   ;;
+   *)
+   echo fail
+   git ls-files --stage "$2"
+   return 1
+   ;;
+   esac
+}
+
 test_expect_success \
 'Test of git add' \
 'touch foo && git add foo'
@@ -25,18 +39,12 @@ test_expect_success \
 echo foo >xfoo1 &&
 chmod 755 xfoo1 &&
 git add xfoo1 &&
-case "$(git ls-files --stage xfoo1)" in
-100644" "*xfoo1) echo pass;;
-*) echo fail; git ls-files --stage xfoo1; (exit 1);;
-esac'
+test_mode_in_index 100644 xfoo1'

 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
rm -f xfoo1 &&
test_ln_s_add foo xfoo1 &&
-   case "$(git ls-files --stage xfoo1)" in
-   12" "*xfoo1) echo pass;;
-   *) echo fail; git ls-files --stage xfoo1; (exit 1);;
-   esac
+   test_mode_in_index 12 xfoo1
 '

 test_expect_success \
@@ -45,28 +53,19 @@ test_expect_success \
 echo foo >xfoo2 &&
 chmod 755 xfoo2 &&
 git update-index --add xfoo2 &&
-case "$(git ls-files --stage xfoo2)" in
-100644" "*xfoo2) echo pass;;
-*) echo fail; git ls-files --stage xfoo2; (exit 1);;
-esac'
+test_mode_in_index 100644 xfoo2'

 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
rm -f xfoo2 &&
test_ln_s_add foo xfoo2 &&
-   case "$(git ls-files --stage xfoo2)" in
-   12" "*xfoo2) echo pass;;
-   *) echo fail; git ls-files --stage xfoo2; (exit 1);;
-   esac
+   test_mode_in_index 12 xfoo2
 '

 test_expect_success \
'git update-index --add: Test that executable bit is not used...' \
'git config core.filemode 0 &&
 test_ln_s_add xfoo2 xfoo3 &&   # runs git update-index --add
-case "$(git ls-files --stage xfoo3)" in
-12" "*xfoo3) echo pass;;
-*) echo fail; git ls-files --stage xfoo3; (exit 1);;
-esac'
+test_mode_in_index 12 xfoo3'

 test_expect_success '.gitignore test setup' '
echo "*.ig" >.gitignore &&
@@ -336,15 +335,9 @@ test_expect_success 'git add --chmod=[+-]x stages 
correctly' '
rm -f foo1 &&
echo foo >foo1 &&
git add --chmod=+x foo1 &&
-   case "$(git ls-files --stage foo1)" in
-   100755" "*foo1) echo pass;;
-   *) echo fail; git ls-files --stage foo1; (exit 1);;
-   esac &&
+   test_mode_in_index 100755 foo1 &&
git add --chmod=-x foo1 &&
-   case "$(git ls-files --stage foo1)" in
-   100644" "*foo1) echo pass;;
-   *) echo fail; git ls-files --stage foo1; (exit 1);;
-   esac
+   test_mode_in_index 100644 foo1
 '

 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
@@ -353,10 +346,7 @@ test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x 
with symlinks' '
rm -f foo2 &&
echo foo >foo2 &&
git add --chmod=+x foo2 &&
-   case "$(git ls-files --stage foo2)" in
-   100755" "*foo2) echo pass;;
-   *) echo fail; git ls-files --stage foo2; (exit 1);;
-   esac
+   test_mode_in_index 100755 foo2
 '

 test_done
--
2.9.2
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html