Skip to content

Commit 8f21b09

Browse files
matttbekuba-moo
authored andcommitted
tests: use correct HEAD to list files
When checking the files before the patch, after a checkout to 'HEAD~', it is required to use the previous HEAD, not the new one to look at the same files and not others. While at it, always use the $HEAD variable, and also fix a related comment + added an extra one to explain the diff. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 255ee02 commit 8f21b09

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

tests/patch/pylint/pylint.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pr() {
88
echo " ====== $@ ======" | tee -a /dev/stderr
99
}
1010

11-
# If it doesn't touch .py files, don't bother. Ignore created and deleted.
12-
if ! git show --diff-filter=AM --pretty="" --name-only HEAD | grep -q -E "\.py$"
11+
# If it doesn't touch .py files, don't bother. Ignore deleted.
12+
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.py$"
1313
then
1414
echo "No python scripts touched, skip" >&$DESC_FD
1515
exit 0
@@ -28,7 +28,8 @@ git log -1 --pretty='%h ("%s")' HEAD
2828
pr "Checking before the patch"
2929
git checkout -q HEAD~
3030

31-
for f in $(git show --diff-filter=M --pretty="" --name-only HEAD | grep -E "\.py$"); do
31+
# Also ignore created, as not present in the parent commit
32+
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do
3233
pylint $f | tee -a $tmpfile_o
3334
done
3435

@@ -38,7 +39,7 @@ incumbent_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " $tmpfile_o)
3839
pr "Checking the tree with the patch"
3940
git checkout -q $HEAD
4041

41-
for f in $(git show --diff-filter=AM --pretty="" --name-only HEAD | grep -E "\.py$"); do
42+
for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do
4243
pylint $f | tee -a $tmpfile_n
4344
done
4445

tests/patch/shellcheck/shellcheck.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pr() {
88
echo " ====== $@ ======" | tee -a /dev/stderr
99
}
1010

11-
# If it doesn't touch .sh files, don't bother. Ignore created and deleted.
12-
if ! git show --diff-filter=AM --pretty="" --name-only HEAD | grep -q -E "\.sh$"
11+
# If it doesn't touch .sh files, don't bother. Ignore deleted.
12+
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.sh$"
1313
then
1414
echo "No shell scripts touched, skip" >&$DESC_FD
1515
exit 0
@@ -28,7 +28,8 @@ git log -1 --pretty='%h ("%s")' HEAD
2828
pr "Checking before the patch"
2929
git checkout -q HEAD~
3030

31-
for f in $(git show --diff-filter=M --pretty="" --name-only HEAD | grep -E "\.sh$"); do
31+
# Also ignore created, as not present in the parent commit
32+
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
3233
(
3334
echo "Checking $f"
3435
echo
@@ -45,7 +46,7 @@ incumbent_w=$(grep -i -c "SC[0-9]* (" $tmpfile_o)
4546
pr "Building the tree with the patch"
4647
git checkout -q $HEAD
4748

48-
for f in $(git show --diff-filter=AM --pretty="" --name-only HEAD | grep -E "\.sh$"); do
49+
for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
4950
(
5051
echo "Checking $f"
5152
echo

tests/patch/yamllint/yamllint.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pr() {
88
echo " ====== $@ ======" | tee -a /dev/stderr
99
}
1010

11-
# If it doesn't touch .yaml files, don't bother. Ignore created and deleted.
12-
if ! git show --diff-filter=AM --pretty="" --name-only HEAD | grep -q -E "\.yaml$"
11+
# If it doesn't touch .yaml files, don't bother. Ignore deleted.
12+
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.yaml$"
1313
then
1414
echo "No YAML files touched, skip" >&$DESC_FD
1515
exit 0
@@ -28,7 +28,8 @@ git log -1 --pretty='%h ("%s")' HEAD
2828
pr "Checking before the patch"
2929
git checkout -q HEAD~
3030

31-
for f in $(git show --diff-filter=M --pretty="" --name-only HEAD | grep -E "\.yaml$"); do
31+
# Also ignore created, as not present in the parent commit
32+
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.yaml$"); do
3233
yamllint $f | tee -a $tmpfile_o
3334
done
3435

@@ -38,7 +39,7 @@ incumbent_w=$(grep -i -c " warning " $tmpfile_o)
3839
pr "Checking the tree with the patch"
3940
git checkout -q $HEAD
4041

41-
for f in $(git show --diff-filter=AM --pretty="" --name-only HEAD | grep -E "\.yaml$"); do
42+
for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.yaml$"); do
4243
yamllint $f | tee -a $tmpfile_n
4344
done
4445

0 commit comments

Comments
 (0)