-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] git-diff-branch: allow to diff against major version
- Loading branch information
Showing
1 changed file
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,35 @@ set -euo pipefail | |
|
||
if [[ $# == 0 ]]; then | ||
echo "Usage:" >&2 | ||
echo " git diff-branch BRANCH [GIT_DIFF_ARGUMENTS]" >&2 | ||
echo " git diff-branch [-m] BRANCH [GIT_DIFF_ARGUMENTS]" >&2 | ||
exit 1 | ||
fi | ||
|
||
MATCH=$1 | ||
shift | ||
|
||
MAJOR=N | ||
if [[ "$MATCH" == "-m" ]]; then | ||
MAJOR=Y | ||
MATCH=$1 | ||
shift | ||
fi; | ||
|
||
: "${REMOTE:=origin}" | ||
REMOTE_URL=$(git remote get-url "$REMOTE") | ||
if [[ "${REMOTE_URL%/*}" != "[email protected]:odoo" ]]; then | ||
echo "🚫 This tool only works on github.com/odoo repositories. URL of remote ${REMOTE} is '${REMOTE_URL}'." >&2 | ||
exit 1 | ||
fi | ||
|
||
AWK="awk" | ||
if command -v gawk >/dev/null; then | ||
AWK="gawk" | ||
fi | ||
|
||
PREV=$( | ||
git branch --remotes --list "${REMOTE}"'/*' | awk -F/ '!/tmp|staging|nightly|HEAD/ { | ||
# shellcheck disable=SC2016 | ||
git branch --remotes --list "${REMOTE}"'/*' | $AWK -F/ '!/tmp|staging|nightly|HEAD/ { | ||
branch=$2; | ||
len = split(gensub("saas-", "", 1, branch), a, "."); | ||
if(len == 1) { | ||
|
@@ -48,18 +61,23 @@ PREV=$( | |
if (a[1] != -1) | ||
printf("%d.%02d:%s\n", a[1], a[2], branch); | ||
}' | sort -n | awk -F: --assign "MATCH=$MATCH" '{ | ||
}' | sort -n | $AWK -F: --assign "MATCH=$MATCH" --assign "MAJOR=$MAJOR" '{ | ||
branch = $2; | ||
if (branch == MATCH) { | ||
print prev | ||
} | ||
} | ||
{ prev = branch }' | ||
{ | ||
if (MAJOR == "N" || index($1, ".00") != 0) { | ||
prev = branch; | ||
}; | ||
}' | ||
) | ||
|
||
if [[ -z "$PREV" ]]; then | ||
echo "🙁 Cannot determine previous branch of $MATCH" >&2 | ||
exit 1 | ||
fi | ||
|
||
set -x | ||
git diff --no-prefix "${REMOTE}/${PREV}..${REMOTE}/${MATCH}" "$@" |