mirror of
https://git.dn42.dev/dn42/registry.git
synced 2025-05-10 22:55:29 +08:00
Merge pull request 'Update squash-my-commits script to support multiple git protocols' (#162) from burble-20200901/update-squash-script into master
Reviewed-on: https://git.dn42.dev/dn42/registry/pulls/162 Reviewed-by: schema-checker <schema-checker@noreply.dn42.us>
This commit is contained in:
commit
eae5435a3c
1 changed files with 112 additions and 9 deletions
|
@ -8,25 +8,117 @@
|
||||||
# use './squash-my-commits -S' to sign the result with your pgp key
|
# use './squash-my-commits -S' to sign the result with your pgp key
|
||||||
#
|
#
|
||||||
##########################################################################
|
##########################################################################
|
||||||
do_sign="$1"
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
echo "Usage: $0 [options]"
|
||||||
|
echo 'Options:'
|
||||||
|
echo ' -S, sign the result with your pgp key'
|
||||||
|
echo ' --push, force push result'
|
||||||
|
echo ' --ssh, use ssh to fetch from the registry'
|
||||||
|
echo ' --https, use https to fetch from the registry'
|
||||||
|
echo 'Environment variables:'
|
||||||
|
echo ' DN42_REG_URL, set the registry URL to use'
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# parse arguments
|
||||||
|
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case "$arg" in
|
||||||
|
|
||||||
|
-S)
|
||||||
|
do_sign='-S'
|
||||||
|
;;
|
||||||
|
--push)
|
||||||
|
do_push=1
|
||||||
|
;;
|
||||||
|
--ssh)
|
||||||
|
echo 'Forcing use of SSH to fetch from registry'
|
||||||
|
reg_proto="ssh"
|
||||||
|
;;
|
||||||
|
--https)
|
||||||
|
echo 'Forcing use of HTTPS to fetch from registry'
|
||||||
|
reg_proto="https"
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $arg"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
# check for dn42registry remote, and add if missing
|
# check for dn42registry remote, and add if missing
|
||||||
git remote -v | grep dn42registry > /dev/null 2>&1
|
git remote -v | grep dn42registry > /dev/null 2>&1
|
||||||
if [ "$?" -ne 0 ]
|
if [ "$?" -ne 0 ]
|
||||||
then
|
then
|
||||||
reg='git@git.dn42.dev:dn42/registry.git'
|
|
||||||
|
# was the URL specified directly ?
|
||||||
|
if [ -n "$DN42_REG_URL" ]
|
||||||
|
then
|
||||||
|
reg="$DN42_REG_URL"
|
||||||
|
else
|
||||||
|
|
||||||
|
if [ -z "$reg_proto" ]
|
||||||
|
then
|
||||||
|
# if the proto wasn't forced, try to guess it
|
||||||
|
git remote -v | grep 'https' > /dev/null 2>&1
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
reg_proto='https'
|
||||||
|
else
|
||||||
|
reg_proto='ssh'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$reg_proto" in
|
||||||
|
ssh)
|
||||||
|
reg='git@git.dn42.dev:dn42/registry.git'
|
||||||
|
;;
|
||||||
|
https)
|
||||||
|
reg='https://git.dn42.dev/dn42/registry.git'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo 'ERROR: Unknown registry protocol'
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Adding dn42registry remote: $reg"
|
echo "Adding dn42registry remote: $reg"
|
||||||
git remote add dn42registry "$reg"
|
git remote add dn42registry "$reg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# ensure the local branch is up to date
|
||||||
|
echo 'Rebasing local changes against the registry master'
|
||||||
|
git fetch dn42registry master
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
echo 'ERROR: Failed to fetch registry master branch'
|
||||||
|
echo 'Hint: you can use --ssh/--https to force use of ssh or https'
|
||||||
|
echo 'If all else fails, you can also set the DN42_REG_URL'
|
||||||
|
echo 'environment variable to directly specify the URL to fetch'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# fail on errors from here onwards
|
# fail on errors from here onwards
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# ensure the local branch is up to date
|
|
||||||
echo "Rebasing local changes against the registry master"
|
|
||||||
git fetch dn42registry master
|
|
||||||
git rebase dn42registry/master
|
git rebase dn42registry/master
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
# find number of local commits
|
# find number of local commits
|
||||||
count=$(git rev-list --count HEAD ^dn42registry/master)
|
count=$(git rev-list --count HEAD ^dn42registry/master)
|
||||||
|
|
||||||
|
@ -37,7 +129,7 @@ then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Squashing $count commits ..."
|
echo 'Squashing $count commits ...'
|
||||||
|
|
||||||
# construct a new comment based on previous commits
|
# construct a new comment based on previous commits
|
||||||
comment="squashed commit:
|
comment="squashed commit:
|
||||||
|
@ -48,10 +140,21 @@ $(git log --oneline HEAD ^dn42registry/master)"
|
||||||
git reset --soft dn42registry/master
|
git reset --soft dn42registry/master
|
||||||
git commit $do_sign -m "$comment"
|
git commit $do_sign -m "$comment"
|
||||||
|
|
||||||
echo "---"
|
# show what happened
|
||||||
|
echo '---'
|
||||||
git log -n 1 --show-signature
|
git log -n 1 --show-signature
|
||||||
echo "---"
|
echo '---'
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# push changes if requested
|
||||||
|
if [ "$do_push" -eq 1 ]
|
||||||
|
then
|
||||||
|
echo 'Force pushing changes'
|
||||||
|
git push --force
|
||||||
|
else
|
||||||
|
echo 'Remember to push your changes using: git push --force'
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Remember to push your changes using: git push --force"
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# end of file
|
# end of file
|
||||||
|
|
Loading…
Add table
Reference in a new issue