Skip to content

Instantly share code, notes, and snippets.

@esmarkowski
Created July 28, 2012 02:23
Show Gist options
  • Save esmarkowski/3191463 to your computer and use it in GitHub Desktop.
Save esmarkowski/3191463 to your computer and use it in GitHub Desktop.
Launch Gitlab Diff
#!/usr/bin/env sh
function gitlab {
if [ -z "$1" ]
then
echo "compare\nrepo\n"
else
case "$1" in
compare)
gitlab-compare "${@:2}"
;;
repo)
;;
*)
echo ""
;;
esac
fi
}
function gitlab-compare() {
function usage() {
cat << EOF
usage:gitlab compare [options]
OPTIONS:
-h Show this message
-l Launch the comparison in a browser
-f Start SHA or branch
-u End SHA or branch
EOF
}
LAUNCH=0
while getopts “h:f:u:l” OPTION
do
case $OPTION in
h)
usage
return 1
;;
l)
LAUNCH=1
;;
f)
FROM_SHA=$OPTARG
;;
u)
TO_SHA=$OPTARG
;;
?)
usage
return 1
;;
esac
done
regex="[^:]+$"
origin=$(git config --get remote.origin.url)
if [[ "$origin" =~ $regex ]]
then
name="${BASH_REMATCH[0]}"
labPathWithRepo="${origin##git\@}"
labPath="${labPathWithRepo%%\:*\.git}"
repo="${name%%\.git}"
echo "http://${labPath}/${repo}/commits/compare?utf8=✓&from=$FROM_SHA&to=$TO_SHA&commit=Compare"
if [[ "$LAUNCH" -eq 1 ]]
then
open "http://${labPath}/${repo}/commits/compare?utf8=✓&from=$FROM_SHA&to=$TO_SHA&commit=Compare"
fi
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment