Skip to content

Commit c63358c

Browse files
committed
fixup! Add packcheck-remote to work with remote repositories directly
1 parent 8259a27 commit c63358c

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ $ ./packcheck-safe.sh cabal-v2 PATH=/bin:/usr/bin:/opt/ghc/bin
199199

200200
## packcheck-remote
201201

202-
`packcheck-remote.sh` is a wrapper over `packcheck.sh`. It makes it easer to
203-
work with remote repositories.
202+
`packcheck-remote.sh` is a wrapper over `packcheck.sh`. It allows you to run
203+
packcheck on a remote repository by cloning it locally and optionally merging a
204+
branch into another branch (e.g. a merging a PR branch into master).
204205

205206
```
206207
$ ./packcheck-remote.sh --force \

packcheck-remote.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
PACKCHECK_DIR="$(dirname $0)"
3+
PACKCHECK_DIR=$(dirname "$0")
44
PACKCHECK_EXE="$PACKCHECK_DIR/packcheck.sh"
55
PWD="$(pwd)"
66
DEFAULT_DIRECTORY_NAME="packcheck-remote-work"
@@ -20,19 +20,21 @@ which_cmd() {
2020

2121
# $1: executable (eg. git)
2222
require_cmd () {
23-
if test -z "$(which_cmd $1)"
23+
local cmd_path
24+
cmd_path=$(which_cmd "$1")
25+
if test -z "$cmd_path"
2426
then
2527
echo "Required command [$1] not found in PATH [$PATH]."
2628
exit 1
2729
else
28-
echo "Using [$1] at [$(which_cmd $1)]"
30+
echo "Using [$1] at [$cmd_path]"
2931
fi
3032
}
3133

3234
# $1: command
3335
function run_verbose() {
34-
echo "$*"
35-
bash -c "$*"
36+
echo "$1"
37+
bash -c "$1"
3638
}
3739

3840
# $1: Remote repository
@@ -98,16 +100,13 @@ try_git_clone_and_merge() {
98100

99101
if test -n "$merge"
100102
then
101-
# This will fail is there are any merge conflicts
103+
# This will fail if there are any merge conflicts
102104
run_verbose "git merge -X theirs $merge --no-edit --commit" || exit 1
103105
fi
104106

105107
show_step "Running packcheck"
106108
# Run packcheck here
107109
run_verbose "$PACKCHECK_EXE $packcheck_cli_opts"
108-
109-
# Go back to where the script was executed from
110-
cd "$PWD" || exit 1
111110
}
112111

113112
# Arguments for the command line
@@ -116,10 +115,12 @@ REMOTE=""
116115
CHECKOUT=""
117116
MERGE=""
118117
DIRECTORY=""
118+
PACKCHECK_CLI_OPTS_ARR=()
119119
PACKCHECK_CLI_OPTS=""
120120

121121
function run_help() {
122-
local script=$(basename $0)
122+
local script
123+
script=$(basename "$0")
123124

124125
echo
125126
echo "USAGE: --option[=value]"
@@ -177,7 +178,7 @@ do
177178
;;
178179
--)
179180
shift
180-
PACKCHECK_CLI_OPTS=$@
181+
PACKCHECK_CLI_OPTS_ARR=("$@")
181182
break
182183
;;
183184
*)
@@ -188,4 +189,20 @@ do
188189
esac
189190
done
190191

192+
for i in "${PACKCHECK_CLI_OPTS_ARR[@]}"
193+
do
194+
case $i in
195+
*=*)
196+
key=${1%%=*}
197+
val=${1#*=}
198+
PACKCHECK_CLI_OPTS="$PACKCHECK_CLI_OPTS $key=\"$val\""
199+
shift
200+
;;
201+
*)
202+
PACKCHECK_CLI_OPTS="$PACKCHECK_CLI_OPTS $i"
203+
shift
204+
;;
205+
esac
206+
done
207+
191208
try_git_clone_and_merge "$REMOTE" "$CHECKOUT" "$MERGE" "$DIRECTORY" "$FORCE" "$PACKCHECK_CLI_OPTS"

0 commit comments

Comments
 (0)