2 #=============================================================================
3 # Copyright 2010-2015 Kitware, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #=============================================================================
18 USAGE
="[<remote>] [--no-topic] [--dry-run] [--]"
21 .
"$(git --exec-path)/git-sh-setup"
23 #-----------------------------------------------------------------------------
30 # Parse the command line options.
31 while test $# != 0; do
33 --no-topic) no_topic
=1 ;;
34 --dry-run) dry_run
=--dry-run ;;
37 *) test -z "$remote" || usage
; remote
="$1" ;;
44 test -n "$remote" || remote
="gerrit"
46 if test -z "$no_topic"; then
47 # Identify and validate the topic branch name.
48 head="$(git symbolic-ref HEAD)" && topic
="${head#refs/heads/}" || topic
=''
49 if test -z "$topic" -o "$topic" = "master"; then
50 die
'Please name your topic:
51 git checkout -b descriptive-name'
53 # The topic branch will be pushed by name.
54 refspecs
="HEAD:refs/for/master/$topic $refspecs"
57 # Fetch the current upstream master branch head.
58 # This helps computation of a minimal pack to push.
59 echo "Fetching $remote master"
60 fetch_out
=$
(git fetch
"$remote" master
2>&1) || die
"$fetch_out"
62 # Exit early if we have nothing to push.
63 if test -z "$refspecs"; then
64 echo 'Nothing to push!'
68 # Push. Save output and exit code.
69 echo "Pushing to $remote"
70 push_stdout
=$
(git push
--porcelain $dry_run "$remote" $refspecs); push_exit
=$?
73 # Reproduce the push exit code.