[PATCH 06/16] Add tests for updating no-checkout entries in index
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
.gitignore | 1 +
Makefile | 2 +-
t/t2104-update-index-narrow.sh | 36 ++++++++++++++++++++++++++++++++++++
test-index-version.c | 14 ++++++++++++++
4 files changed, 52 insertions(+), 1 deletions(-)
create mode 100755 t/t2104-update-index-narrow.sh
create mode 100644 test-index-version.c
diff --git a/.gitignore b/.gitignore
index bbaf9de..0c35577 100644
--- a/.gitignore
+++ b/.gitignore
@@ -147,6 +147,7 @@ test-date
test-delta
test-dump-cache-tree
test-genrandom
+test-index-version
test-match-trees
test-parse-options
test-path-utils
diff --git a/Makefile b/Makefile
index 716161d..7a22bde 100644
--- a/Makefile
+++ b/Makefile
@@ -1323,7 +1323,7 @@ endif
### Testing rules
-TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-parse-options$X test-path-utils$X
+TEST_PROGRAMS = test-chmtime$X test-genrandom$X test-date$X test-delta$X test-sha1$X test-match-trees$X test-parse-options$X test-path-utils$X test-index-version$X
all:: $(TEST_PROGRAMS)
diff --git a/t/t2104-update-index-narrow.sh b/t/t2104-update-index-narrow.sh
new file mode 100755
index 0000000..2683929
--- /dev/null
+++ b/t/t2104-update-index-narrow.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Nguyễn Thái Ngọc Duy
+#
+
+test_description='git update-index narrow checkout update'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ mkdir sub &&
+ touch 1 2 sub/1 sub/2 &&
+ git add 1 2 sub/1 sub/2
+'
+
+test_expect_success 'index is at version 2' '
+ test "$(test-index-version < .git/index)" = 2
+'
+
+test_expect_success 'update-index --no-checkout' '
+ git update-index --no-checkout 1 sub/1 &&
+ test -z "$(git ls-files --narrow-checkout|grep 1)"'
+
+test_expect_success 'index is at version 3 after having some no-checkout entries' '
+ test "$(test-index-version < .git/index)" = 3
+'
+
+test_expect_success 'update-index --checkout' '
+ git update-index --checkout 1 sub/1 &&
+ test "$(git ls-files)" = "$(git ls-files --narrow-checkout)"'
+
+test_expect_success 'index version is back to 2 when there is no no-checkout entry' '
+ test "$(test-index-version < .git/index)" = 2
+'
+
+test_done
diff --git a/test-index-version.c b/test-index-version.c
new file mode 100644
index 0000000..bfaad9e
--- /dev/null
+++ b/test-index-version.c
@@ -0,0 +1,14 @@
+#include "cache.h"
+
+int main(int argc, const char **argv)
+{
+ struct cache_header hdr;
+ int version;
+
+ memset(&hdr,0,sizeof(hdr));
+ if (read(0, &hdr, sizeof(hdr)) != sizeof(hdr))
+ return 0;
+ version = ntohl(hdr.hdr_version);
+ printf("%d\n", version);
+ return 0;
+}
--
1.6.0.96.g2fad1.dirty