Commit 0f171de1 authored by Robert Maynard's avatar Robert Maynard

Add gitlab-sync command to ease updating local branches after reformats

parent c5d20ef7
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2015 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
USAGE='[<remote>] [<options>...] [--]
OPTIONS
--dry-run
Show what would be changed without actually updating
'
OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
. "$(git --exec-path)/git-sh-setup"
egrep-q() {
egrep "$@" >/dev/null 2>/dev/null
}
# Load the project configuration.
require_work_tree_exists
#-----------------------------------------------------------------------------
remote=''
dry_run=false
# Parse the command line options.
while test $# != 0; do
case "$1" in
--dry-run) dry_run=true ;;
--) shift; break ;;
-*) usage ;;
*) test -z "$remote" || usage ; remote="$1" ;;
esac
shift
done
test $# = 0 || usage
# Default remote.
test -n "$remote" || remote="gitlab"
# Identify and validate the topic branch name.
head="$(git symbolic-ref HEAD)" && topic="${head#refs/heads/}" || topic=''
if test -z "$topic" -o "$topic" = "master"; then
die 'You cant sync the master branch, please checkout the correct a branch with:
git checkout <branch>'
fi
#-----------------------------------------------------------------------------
require_clean_work_tree "sync" "$(gettext "Error syncing \
We are trying to overwrite all local changes on this branch with the version on \
gitlab. Before you do this make sure to stash your changes or commit these \
changes to a different branch.")"
#-----------------------------------------------------------------------------
fetch_stdout=$(git fetch "$remote" $topic); fetch_exit=$?
gettext "$fetch_stdout"
if [ $fetch_exit -eq 0 ]
then
if test "$dry_run" = true
then
reset_stdout=$(git diff --color HEAD..FETCH_HEAD); fetch_exit=$?
gettext "$reset_stdout"
else
reset_stdout=$(git reset --hard FETCH_HEAD); fetch_exit=$?
gettext "$reset_stdout"
fi
fi
# Reproduce the push exit code.
exit $fetch_exit
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment