61 lines
1.6 KiB
Bash
61 lines
1.6 KiB
Bash
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
usage() {
|
||
printf "Usage: %s [-s|--source <branch>] [-t|--target <branch>] [source target] (target defaults to 'main')\n" "$0"
|
||
exit 2
|
||
}
|
||
|
||
source_branch=""
|
||
# default target branch to main
|
||
target_branch="main"
|
||
|
||
# Parse options: -s|--source and -t|--target. Falls back to positional args.
|
||
while [[ $# -gt 0 ]]; do
|
||
case "$1" in
|
||
-s|--source)
|
||
source_branch="$2"; shift 2;;
|
||
-t|--target)
|
||
target_branch="$2"; shift 2;;
|
||
-h|--help)
|
||
usage;;
|
||
--)
|
||
shift; break;;
|
||
-*)
|
||
printf "Unknown option: %s\n" "$1"; usage;;
|
||
*)
|
||
if [[ -z "$source_branch" ]]; then
|
||
source_branch="$1"
|
||
elif [[ -z "$target_branch" ]]; then
|
||
target_branch="$1"
|
||
fi
|
||
shift;;
|
||
esac
|
||
done
|
||
|
||
if [[ -z "$source_branch" ]]; then
|
||
printf "no source branch specified, using current HEAD\n"
|
||
source_branch="HEAD"
|
||
else
|
||
printf "checking out source branch: %s\n" "$source_branch"
|
||
git checkout "$source_branch"
|
||
fi
|
||
|
||
# Run unit tests
|
||
printf "\nUnit test results:\n´´´bash\n"
|
||
python3 -m unittest discover
|
||
printf "´´´\n"
|
||
|
||
# Get list of changed files between source and target branches
|
||
export CHANGED_FILES=$(git diff --name-only "$source_branch" "$target_branch")
|
||
for file in $CHANGED_FILES; do
|
||
if [ -f "${file}" ]; then
|
||
printf "\nHere is the diff between source (%s) version of %s and target (%s):\n\n" "$source_branch" "$file" "$target_branch"
|
||
printf "´´´diff\n"
|
||
git --no-pager diff -U1000 -W "$target_branch" -- "$file"
|
||
printf "´´´\n"
|
||
fi
|
||
done
|
||
|
||
|
||
# adjust model context length if needed |