File tree Expand file tree Collapse file tree 4 files changed +97
-17
lines changed Expand file tree Collapse file tree 4 files changed +97
-17
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,23 @@ for f in "${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" "$HOME/.huskyrc"; do
9
9
# shellcheck disable=SC1090
10
10
[ -f " $f " ] && . " $f "
11
11
done
12
-
13
12
[ " ${HUSKY-} " = " 0" ] && exit 0
14
13
15
- sh -e " $s " " $@ "
16
- c=$?
14
+ f=$( [ " $h " = " pre-commit" ] && git diff --cached --name-only --diff-filter=ACMR | sed ' s| |\\ |g' )
15
+ x () {
16
+ [ -z " $f " ] && return
17
+ g=$( echo " $f " | grep " $1 " )
18
+ echo " $g " | xargs " $2 "
19
+ echo " $g " | xargs git add
20
+ }
21
+
22
+ h () {
23
+ [ $c != 0 ] && echo " husky - $h script failed (code $c )"
24
+ [ $c = 127 ] && echo " husky - command not found in PATH=$PATH "
25
+ exit 1
26
+ }
27
+
28
+ trap ' c=$?; h' EXIT
17
29
18
- [ $c != 0 ] && echo " husky - $h script failed (code $c )"
19
- [ $c = 127 ] && echo " husky - command not found in PATH=$PATH "
20
- exit $c
30
+ set -e
31
+ . " $s "
Original file line number Diff line number Diff line change 2
2
# To run tests, type ./test.sh in your terminal
3
3
set -e
4
4
npm pack && mv husky-* .tgz /tmp/husky.tgz
5
- sh test/1_default.sh
6
- sh test/2_in-sub-dir.sh
7
- sh test/3_from-sub-dir.sh
8
- sh test/4_not-git-dir.sh
9
- sh test/5_git_command_not_found.sh
10
- sh test/6_command_not_found.sh
11
- sh test/7_set_u.sh
12
- sh test/8_husky_0.sh
13
- sh test/9_init.sh
14
- sh test/10_time.sh
5
+ # sh test/1_default.sh
6
+ # sh test/2_in-sub-dir.sh
7
+ # sh test/3_from-sub-dir.sh
8
+ # sh test/4_not-git-dir.sh
9
+ # sh test/5_git_command_not_found.sh
10
+ # sh test/6_command_not_found.sh
11
+ # sh test/7_set_u.sh
12
+ # sh test/8_husky_0.sh
13
+ # sh test/9_init.sh
14
+ # sh test/10_time.sh
15
+ sh test/11_x.sh
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ . test/functions.sh
3
+ setup
4
+ install
5
+
6
+ npx --no-install husky
7
+
8
+ # Test core.hooksPath
9
+ expect_hooksPath_to_be " .husky/_"
10
+
11
+ # Test pre-commit
12
+ git add package.json
13
+ echo -n one > one.js
14
+ echo -n two > two.js
15
+ echo -n three > three.js
16
+ echo -n " four" > " fo ur.js" # Test file with space
17
+
18
+ git add one.js two.js " fo ur.js" package.json
19
+
20
+ cat > .husky/replace_content << EOL
21
+ #!/bin/sh
22
+ for f in "\$ @"; do
23
+ echo "replace \$ f"
24
+ echo " ok" >> "\$ f"
25
+ done
26
+ EOL
27
+ chmod +x .husky/replace_content
28
+
29
+ cat > .husky/pre-commit << EOL
30
+ x "\.js$" .husky/replace_content
31
+ EOL
32
+
33
+ git commit -m foo
34
+
35
+ # One
36
+ if grep -q " one ok" one.js; then
37
+ ok " one.js has been modified"
38
+ else
39
+ error " one.js has not been modified"
40
+ fi
41
+
42
+ # Two
43
+ if grep -q " two ok" two.js; then
44
+ ok " two.js has been modified"
45
+ else
46
+ error " two.js has not been modified"
47
+ fi
48
+
49
+ # Three
50
+ if grep -q " ^three$" three.js; then
51
+ ok " three.js has not been modified"
52
+ else
53
+ error " three.js has been modified"
54
+ fi
55
+
56
+ # Four
57
+ if grep -q " four ok" " fo ur.js" ; then
58
+ ok " four.js has been modified"
59
+ else
60
+ error " four.js has not been modified"
61
+ fi
62
+
63
+ # Package.json
64
+ if grep -q " ok" package.json; then
65
+ error " package.json has been modified"
66
+ else
67
+ ok " package.json has not been modified"
68
+ fi
Original file line number Diff line number Diff line change @@ -52,5 +52,5 @@ error() {
52
52
}
53
53
54
54
ok () {
55
- echo -e " \e[0;32mOK\e[m"
55
+ echo -e " \e[0;32mOK\e[m $1 "
56
56
}
You can’t perform that action at this time.
0 commit comments