Skip to content

Commit

Permalink
[FIX] git-diff-branch: ignore unknown branch names
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed May 19, 2020
1 parent bf886e0 commit dad6907
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions git-diff-branch
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,41 @@ shift
: "${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
echo "🚫 This tool only works on github.com/odoo repositories. URL of remote ${REMOTE} is '${REMOTE_URL}'." >&2
exit 1
fi

PREV=$(
git branch --remotes --list "${REMOTE}"'/*' | awk -F/ '!/tmp|staging|nightly|HEAD/ {
branch=$2;
split(gensub("saas-", "", 1, branch), a, ".");
if(length(a)==1) {
len = split(gensub("saas-", "", 1, branch), a, ".");
if(len == 1) {
a[2] = a[1];
switch(a[2]) {
case "master":
a[1] = a[2] = 9999;
break;
case /^[1-5]$/:
a[1]=7;
a[1] = 7;
break;
case 6:
a[1]=8;
a[1] = 8;
break;
case /^[789]$|^1[0123]$/:
a[1]=9;
a[1] = 9;
break;
case /^1[45678]$/:
a[1]=10;
a[1] = 10;
break;
default:
exit 1;
a[1] = -1;
};
}
printf("%s.%02s:%s\n", a[1], a[2], branch);
else if (len != 2 || int(a[1]) < 1 || int(a[2]) != a[2])
a[1] = -1;
if (a[1] != -1)
printf("%d.%02d:%s\n", a[1], a[2], branch);
}' | sort -n | awk -F: --assign "MATCH=$MATCH" '{
branch = $2;
if (branch == MATCH) {
Expand All @@ -54,7 +58,7 @@ PREV=$(
)

if [[ -z "$PREV" ]]; then
echo "Cannot determine previous branch of $MATCH" >&2
echo "🙁 Cannot determine previous branch of $MATCH" >&2
exit 1
fi

Expand Down

0 comments on commit dad6907

Please sign in to comment.