-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit-flux-publish
94 lines (82 loc) · 3.16 KB
/
git-flux-publish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# git-flux -- A collection of git tools to help with workflows
# often associated with "infrastructure as code" or configuration
# management.
#
# Feel free to contribute to this project at:
# http://github.com/joemiller/git-flux
#
# Copyright 2012 Joe Miller. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY JOE MILLER ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL JOE MILLER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Joe Miller.
#
gitflux_load_settings
usage() {
echo "usage: git flux publish [<name>]"
echo
echo "- <name> is optional. If not specified, the current branch is used"
echo "- <name> may be an environment branch or feature branch without the prefix."
echo
}
cmd_default() {
cmd_publish "$@"
}
cmd_publish() {
local branch_name="$1"; shift
if [ "$branch_name" = "help" ]; then
cmd_help
fi
if [ -z "$branch_name" ]; then
branch_name=$(git_current_branch)
fi
# strip off prefixes, we'll add them ourselves later
branch_name=$(echo "$branch_name" | sed "s@^$ENVIRONMENT_PREFIX@@" | sed "s@^$FEATURE_PREFIX@@")
# try to find a valid branch
local env_branch="${ENVIRONMENT_PREFIX}${branch_name}"
local feature_branch="${FEATURE_PREFIX}${branch_name}"
for branch in "$branch_name" "$feature_branch" "$env_branch" ; do
if git_local_branch_exists "$branch"; then
branch_name=$branch
break
fi
done
# sanity checks
require_clean_working_tree
require_branch "$branch_name"
git fetch -q origin
# create remote branch
git push -q -u origin "$branch_name:refs/heads/$branch_name"
git checkout -q "$branch_name"
echo
echo "Summary of actions:"
echo " - Pushed local branch '$branch_name' to remote origin."
echo " - You are now on branch '$branch_name'"
echo
}
cmd_help() {
usage
exit 0
}