tsantos-gitadm 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gitadm +36 -8
- metadata +1 -1
data/gitadm
CHANGED
@@ -48,7 +48,7 @@ def help_opt opts
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
51
|
+
def create_branch_from_master branch_name, checkout = false
|
52
52
|
`git push origin master:refs/heads/#{branch_name}`
|
53
53
|
if checkout
|
54
54
|
`git checkout --track -b #{branch_name} origin/#{branch_name}`
|
@@ -122,24 +122,52 @@ elsif :checkout == command
|
|
122
122
|
|
123
123
|
=begin
|
124
124
|
create-remote-branch
|
125
|
-
Creates a remote branch
|
126
|
-
tracking
|
125
|
+
Creates a remote branch. You can use a local branch to base it from or you can default to
|
126
|
+
the master. You can also either setup tracking on your local branch or check it out with
|
127
|
+
tracking if you chose to use master as your local branch.
|
127
128
|
=end
|
128
129
|
elsif :create_remote_branch == command
|
130
|
+
options.local = :master
|
131
|
+
|
129
132
|
opts = OptionParser.new do |opts|
|
130
|
-
opts.banner =
|
133
|
+
opts.banner = <<EOS
|
134
|
+
Examples:
|
135
|
+
|
136
|
+
This will use your local branch named 'dabranch' to make a new remote branch called 'dabranch'
|
137
|
+
and then it will set up the local branch to track the remote one that was created.
|
138
|
+
|
139
|
+
gitadm create-remote-branch -l dabranch -b dabranch -t
|
140
|
+
|
141
|
+
This will create a new remote branch called 'dabranch' based off master and then check it out
|
142
|
+
with tracking.
|
143
|
+
|
144
|
+
gitadm create-remote-branch -b dabranch -c
|
145
|
+
|
146
|
+
EOS
|
147
|
+
opts.on('-l', '--local-branch NAME', 'The local branch to base it from. Defaults to master.') do |name|
|
148
|
+
options.local = name.to_sym
|
149
|
+
end
|
131
150
|
opts.on('-b', '--branch-name NAME', 'The branch name to create') do |name|
|
132
151
|
options.branch_name = name
|
133
152
|
end
|
134
|
-
opts.on('-
|
153
|
+
opts.on('-t', '--track', "Setup tracking. (doesn't apply if you used master)") do
|
154
|
+
options.tracking = true
|
155
|
+
end
|
156
|
+
opts.on('-c', '--checkout', "Will check the branch out (only works if local branch was master)") do
|
135
157
|
options.checkout = true
|
136
158
|
end
|
137
159
|
help_opt(opts)
|
138
160
|
end
|
139
|
-
if !defined? ARGS then puts opts; exit(1); end
|
161
|
+
if !defined? ARGS || !options.branch_name then puts opts; exit(1); end
|
140
162
|
opts.parse! ARGS
|
141
163
|
|
142
|
-
|
164
|
+
`git push origin #{options.local}:refs/heads/#{options.branch_name}`
|
165
|
+
if options.checkout && options.local == :master
|
166
|
+
`git checkout --track -b #{options.branch_name} origin/#{options.branch_name}`
|
167
|
+
elsif options.tracking && options.local != :master
|
168
|
+
`git config branch.#{options.local}.remote origin`
|
169
|
+
`git config branch.#{options.local}.merge refs/heads/#{options.branch_name}`
|
170
|
+
end
|
143
171
|
|
144
172
|
=begin
|
145
173
|
create-repo
|
@@ -198,7 +226,7 @@ elsif :create_repo == command
|
|
198
226
|
end
|
199
227
|
|
200
228
|
if options.branches
|
201
|
-
options.branches.each { |branch|
|
229
|
+
options.branches.each { |branch| create_branch_from_master(branch, options.checkout) }
|
202
230
|
`git checkout master` if options.checkout
|
203
231
|
end
|
204
232
|
end
|