Skip to content

Commit 2817290

Browse files
authored
Merge pull request #314 from github/xn4p4lm-feature-checker-bug-fix
Bug fix with feature checker
2 parents 8ae8e24 + 80a3f33 commit 2817290

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
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: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TESTS_DIR="$PWD/$(dirname "$0")"
88

99
## testing for known supported command help with and without leading dashes
1010

11-
begin_test "Testing ghe-rsync-feature-checker for known supported command --help"
11+
begin_test "Testing ghe-rsync-feature-checker with known supported command --help"
1212
(
1313
set -e
1414

@@ -17,6 +17,15 @@ begin_test "Testing ghe-rsync-feature-checker for known supported command --help
1717
)
1818
end_test
1919

20+
begin_test "Testing ghe-rsync-feature-checker with known unsupported command -help"
21+
(
22+
set -e
23+
24+
# Test ghe-rsync-feature-checker command
25+
ghe-rsync-feature-checker -help | grep -q "false"
26+
)
27+
end_test
28+
2029
begin_test "Testing ghe-rsync-feature-checker with known supported command help"
2130
(
2231
set -e
@@ -38,6 +47,16 @@ begin_test "Testing ghe-rsync-feature-checker with known unsupported command --n
3847
)
3948
end_test
4049

50+
begin_test "Testing ghe-rsync-feature-checker with known unsupported command -not-an-actual-feature"
51+
(
52+
set -e
53+
54+
# Test ghe-rsync-feature-checker command
55+
ghe-rsync-feature-checker -not-an-actual-feature | grep -q "false"
56+
57+
)
58+
end_test
59+
4160
begin_test "Testing ghe-rsync-feature-checker with known unsupported command not-an-actual-feature"
4261
(
4362
set -e
@@ -98,6 +117,15 @@ begin_test "Testing ghe-rsync-feature-checker with known supported command --ver
98117
)
99118
end_test
100119

120+
begin_test "Testing ghe-rsync-feature-checker with known unsupported command -verbose"
121+
(
122+
set -e
123+
124+
# Test ghe-rsync-feature-checker command
125+
ghe-rsync-feature-checker -verbose | grep -q "false"
126+
)
127+
end_test
128+
101129
begin_test "Testing ghe-rsync-feature-checker with known supported command verbose"
102130
(
103131
set -e

0 commit comments

Comments
 (0)