Skip to content

Commit f5071c7

Browse files
committed
Bug fix with feature checker
- This would allow -help to work even though it's not a valid command
1 parent fd7d2c8 commit f5071c7

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

share/github-backup-utils/ghe-rsync-feature-checker

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,41 @@
77
set -o pipefail
88

99
# set the variable from the first argument and remove any leading dashes
10-
rsync_command=$(echo "$1" | sed -E 's/^-+//')
10+
rsync_command=$1
1111

12-
# check if the passed rsync command is supported by the current version of rsync
13-
if rsync -h | grep -E "\B-+($rsync_command)\b" >/dev/null 2>&1; then
14-
echo "true"
12+
# extract dashes if present into variable
13+
leading_dashes=$(echo "$rsync_command" | grep -oE "^-+")
14+
15+
# this normalizes the passed command by removing any leading dashes
16+
normalized_command=$(echo "$rsync_command" | sed -E "s/^-+//")
17+
18+
# this checks the rsync command and returns the found command if it is valid
19+
found_command=$(rsync -h | grep -oE "\B-+($normalized_command)\b" | head -n "1")
20+
21+
# this is the normalized found command
22+
normalized_found_command=$(echo "$found_command" | sed -E "s/^-+//")
23+
24+
## Check if $leading_dashes is either - or --
25+
if [ "$leading_dashes" == "-" ]; then
26+
# check if the passed rsync command is valid and supported or if the normalized command is valid and supported
27+
if [ "$rsync_command" == "$found_command" ]; then
28+
echo "true"
29+
else
30+
echo "false"
31+
fi
32+
elif [ "$leading_dashes" == "--" ]; then
33+
# check if the passed rsync command is valid and supported or if the normalized command is valid and supported
34+
if [ "$rsync_command" == "$found_command" ]; then
35+
echo "true"
36+
else
37+
echo "false"
38+
fi
1539
else
16-
echo "false"
17-
fi
40+
# check if the passed rsync command is valid and supported or if the normalized command is valid and supported
41+
if [ "$rsync_command" == "$normalized_found_command" ]; then
42+
echo "true"
43+
else
44+
echo "false"
45+
fi
46+
fi
47+

test/test-ghe-rsync-feature-checker.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ begin_test "Testing ghe-rsync-feature-checker for known supported command --help
1717
)
1818
end_test
1919

20+
<<<<<<< Updated upstream
21+
=======
22+
begin_test "Testing ghe-rsync-feature-checker for known supported command -help"
23+
(
24+
set -e
25+
26+
# Test ghe-rsync-feature-checker command
27+
ghe-rsync-feature-checker -help | grep -q "false"
28+
)
29+
end_test
30+
31+
>>>>>>> Stashed changes
2032
begin_test "Testing ghe-rsync-feature-checker with known supported command help"
2133
(
2234
set -e
@@ -38,6 +50,19 @@ begin_test "Testing ghe-rsync-feature-checker with known unsupported command --n
3850
)
3951
end_test
4052

53+
<<<<<<< Updated upstream
54+
=======
55+
begin_test "Testing ghe-rsync-feature-checker with known unsupported command -not-an-actual-feature"
56+
(
57+
set -e
58+
59+
# Test ghe-rsync-feature-checker command
60+
ghe-rsync-feature-checker -not-an-actual-feature | grep -q "false"
61+
62+
)
63+
end_test
64+
65+
>>>>>>> Stashed changes
4166
begin_test "Testing ghe-rsync-feature-checker with known unsupported command not-an-actual-feature"
4267
(
4368
set -e
@@ -98,6 +123,18 @@ begin_test "Testing ghe-rsync-feature-checker with known supported command --ver
98123
)
99124
end_test
100125

126+
<<<<<<< Updated upstream
127+
=======
128+
begin_test "Testing ghe-rsync-feature-checker with known supported command -verbose"
129+
(
130+
set -e
131+
132+
# Test ghe-rsync-feature-checker command
133+
ghe-rsync-feature-checker -verbose | grep -q "false"
134+
)
135+
end_test
136+
137+
>>>>>>> Stashed changes
101138
begin_test "Testing ghe-rsync-feature-checker with known supported command verbose"
102139
(
103140
set -e

0 commit comments

Comments
 (0)