[PATCH v2 1/3] t: consolidate the `is_hidden` functions
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Apr 10, 2020, 11:03 UTC
- Message-ID
- <dd81ea68d6b74c3031565a472d622d8db1f896bd.1586516583.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.603.v2.git.1586516583.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
The `is_hidden` function can be used (only on Windows) to determine whether a directory or file have their `hidden` flag set.
This function is duplicated between two test scripts. It is better to move it into `test-lib-functions.sh` so that it is reused.
To make it safer to use, we specifically test for the `MINGW` prereq now, so that it is not used on a non-Windows platform by mistake.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- t/t0001-init.sh | 9 +-------- t/t5611-clone-config.sh | 13 +++---------- t/test-lib-functions.sh | 10 ++++++++++ 3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 26f82063267..1edd5aeb8f0 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -392,13 +392,6 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' ' test_path_is_dir realgitdir/refs ' -# Tests for the hidden file attribute on windows -is_hidden () { - # Use the output of `attrib`, ignore the absolute path - case "$(attrib "$1")" in *H*?:*) return 0;; esac - return 1 -} - test_expect_success MINGW '.git hidden' ' rm -rf newdir && ( @@ -406,7 +399,7 @@ test_expect_success MINGW '.git hidden' ' mkdir newdir && cd newdir && git init && - is_hidden .git + test_path_is_hidden .git ) && check_config newdir/.git false unset ' diff --git a/t/t5611-clone-config.sh b/t/t5611-clone-config.sh index 60c1ba951b7..8e0fd398236 100755 --- a/t/t5611-clone-config.sh +++ b/t/t5611-clone-config.sh @@ -92,24 +92,17 @@ test_expect_success 'clone -c remote.<remote>.fetch=<refspec> --origin=<name>' ' test_cmp expect actual ' -# Tests for the hidden file attribute on windows -is_hidden () { - # Use the output of `attrib`, ignore the absolute path - case "$(attrib "$1")" in *H*?:*) return 0;; esac - return 1 -} - test_expect_success MINGW 'clone -c core.hideDotFiles' ' test_commit attributes .gitattributes "" && rm -rf child && git clone -c core.hideDotFiles=false . child && - ! is_hidden child/.gitattributes && + ! test_path_is_hidden child/.gitattributes && rm -rf child && git clone -c core.hideDotFiles=dotGitOnly . child && - ! is_hidden child/.gitattributes && + ! test_path_is_hidden child/.gitattributes && rm -rf child && git clone -c core.hideDotFiles=true . child && - is_hidden child/.gitattributes + test_path_is_hidden child/.gitattributes ' test_done diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 352c213d52e..09a2479fd38 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1543,3 +1543,13 @@ test_bitmap_traversal () { test_cmp "$1.normalized" "$2.normalized" && rm -f "$1.normalized" "$2.normalized" } + +# Tests for the hidden file attribute on windows +test_path_is_hidden () { + test_have_prereq MINGW || + BUG "test_path_is_hidden can only be used on Windows" + + # Use the output of `attrib`, ignore the absolute path + case "$(attrib "$1")" in *H*?:*) return 0;; esac + return 1 +}
-- gitgitgadget