git-scripts 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +17 -0
- data/bin/feature +101 -32
- data/bin/hotfix +61 -71
- data/lib/git.rb +50 -16
- data/lib/github.rb +4 -4
- data/lib/helpers.rb +46 -6
- data/lib/signal_handlers.rb +3 -0
- data/man/feature-clean.1 +4 -1
- data/man/feature-clean.1.html +6 -1
- data/man/feature-clean.1.markdown +5 -0
- data/man/feature-clean.1.ronn +4 -0
- data/man/feature-finish.1 +4 -1
- data/man/feature-finish.1.html +6 -1
- data/man/feature-finish.1.markdown +5 -0
- data/man/feature-finish.1.ronn +4 -0
- data/man/feature-github-test.1 +4 -1
- data/man/feature-github-test.1.html +6 -1
- data/man/feature-github-test.1.markdown +5 -0
- data/man/feature-github-test.1.ronn +4 -0
- data/man/feature-list.1 +4 -1
- data/man/feature-list.1.html +6 -1
- data/man/feature-list.1.markdown +5 -0
- data/man/feature-list.1.ronn +4 -0
- data/man/feature-merge.1 +4 -1
- data/man/feature-merge.1.html +6 -1
- data/man/feature-merge.1.markdown +5 -0
- data/man/feature-merge.1.ronn +4 -0
- data/man/feature-prune.1 +37 -0
- data/man/feature-prune.1.ronn +30 -0
- data/man/feature-start.1 +4 -1
- data/man/feature-start.1.html +6 -1
- data/man/feature-start.1.markdown +5 -0
- data/man/feature-start.1.ronn +4 -0
- data/man/feature-stashes.1 +4 -1
- data/man/feature-stashes.1.html +6 -1
- data/man/feature-stashes.1.markdown +5 -0
- data/man/feature-stashes.1.ronn +4 -0
- data/man/feature-status.1 +4 -1
- data/man/feature-status.1.html +6 -1
- data/man/feature-status.1.markdown +5 -0
- data/man/feature-status.1.ronn +4 -0
- data/man/feature-switch.1 +4 -1
- data/man/feature-switch.1.html +6 -1
- data/man/feature-switch.1.markdown +5 -0
- data/man/feature-switch.1.ronn +4 -0
- data/man/feature.1 +8 -1
- data/man/feature.1.html +6 -1
- data/man/feature.1.markdown +5 -0
- data/man/feature.1.ronn +6 -0
- data/man/hotfix-finish.1 +4 -1
- data/man/hotfix-finish.1.html +6 -1
- data/man/hotfix-finish.1.markdown +5 -0
- data/man/hotfix-finish.1.ronn +4 -0
- data/man/hotfix-list.1 +4 -1
- data/man/hotfix-list.1.html +6 -1
- data/man/hotfix-list.1.markdown +5 -0
- data/man/hotfix-list.1.ronn +4 -0
- data/man/hotfix-merge.1 +4 -1
- data/man/hotfix-merge.1.html +6 -1
- data/man/hotfix-merge.1.markdown +5 -0
- data/man/hotfix-merge.1.ronn +4 -0
- data/man/hotfix-start.1 +4 -1
- data/man/hotfix-start.1.html +6 -1
- data/man/hotfix-start.1.markdown +5 -0
- data/man/hotfix-start.1.ronn +4 -0
- data/man/hotfix-switch.1 +4 -1
- data/man/hotfix-switch.1.html +6 -1
- data/man/hotfix-switch.1.markdown +5 -0
- data/man/hotfix-switch.1.ronn +4 -0
- data/man/hotfix.1 +4 -1
- data/man/hotfix.1.html +6 -1
- data/man/hotfix.1.markdown +5 -0
- data/man/hotfix.1.ronn +4 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://rubygems.org/gems/git-scripts)
|
2
|
+
|
1
3
|
# Git Scripts
|
2
4
|
|
3
5
|
User scripts for easily managing feature branches and hotfixes.
|
@@ -122,3 +124,18 @@ Merges the hotfix branch back into `stable` with `--no-ff`. Also does a
|
|
122
124
|
merge back into `master`.
|
123
125
|
|
124
126
|
[gitflow]: http://nvie.com/posts/a-successful-git-branching-model/
|
127
|
+
|
128
|
+
## Hacking
|
129
|
+
|
130
|
+
We (obviously) use the same method on this repo as the tools contained within
|
131
|
+
encourage. Unfortunately, `feature finish` will create a pull request within
|
132
|
+
your own forked repo. Thus, if you do not have write privileges to this
|
133
|
+
repository, you have to create the pull request manually - bummer.
|
134
|
+
|
135
|
+
Please include any necessary changes to the documentation. The man files are
|
136
|
+
written in [ronn], so the only manual change you need make are to the
|
137
|
+
man/*.ronn files. After you've done that, run `rake man` to generate the HTML
|
138
|
+
and roff files.
|
139
|
+
|
140
|
+
[ronn]: http://rtomayko.github.io/ronn/ronn-format.7.html
|
141
|
+
|
data/bin/feature
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/signal_handlers.rb'
|
2
3
|
require_relative '../lib/github.rb'
|
3
4
|
require_relative '../lib/git.rb'
|
4
5
|
require_relative '../lib/helpers.rb'
|
5
6
|
|
6
7
|
command=ARGV.first
|
7
8
|
|
9
|
+
$0 = ARGV.join(" ")
|
10
|
+
|
8
11
|
case command
|
9
12
|
when 'github-test'
|
10
13
|
octokit = Github::api
|
@@ -16,25 +19,29 @@ when 'start'
|
|
16
19
|
require_argument(:feature, :start)
|
17
20
|
feature = ARGV[1]
|
18
21
|
|
19
|
-
exit
|
22
|
+
exit unless confirm("Create feature branch named: '#{feature}' ?")
|
20
23
|
|
21
|
-
Git::run_safe(
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
Git::run_safe([
|
25
|
+
"git checkout #{Git::development_branch}",
|
26
|
+
"git pull --rebase",
|
27
|
+
"git branch \"#{feature}\" #{Git::development_branch}",
|
28
|
+
"git checkout \"#{feature}\"",
|
29
|
+
])
|
25
30
|
|
26
31
|
Git::submodules_update
|
27
32
|
|
28
33
|
# Automatically setup remote tracking branch
|
29
|
-
Git::run_safe(
|
30
|
-
|
31
|
-
|
34
|
+
Git::run_safe([
|
35
|
+
"git config branch.#{feature}.remote origin",
|
36
|
+
"git config branch.#{feature}.merge refs/heads/#{feature}",
|
37
|
+
"git config branch.#{feature}.rebase true"
|
38
|
+
])
|
32
39
|
|
33
40
|
puts "Successfully created a new feature-branch: #{feature}"
|
34
41
|
|
35
42
|
when 'status'
|
36
43
|
current = Git::current_branch
|
37
|
-
Git::run_safe("git fetch")
|
44
|
+
Git::run_safe(["git fetch"])
|
38
45
|
|
39
46
|
upstream = `git rev-parse --verify --quiet #{current}@{upstream} 2>/dev/null`.strip
|
40
47
|
if upstream == ''
|
@@ -70,9 +77,9 @@ when 'status'
|
|
70
77
|
when 'finish'
|
71
78
|
feature = ARGV[1] || Git::current_branch
|
72
79
|
# Push commits to origin
|
73
|
-
Git::run_safe("git push origin #{feature}:#{feature}")
|
80
|
+
Git::run_safe(["git push origin #{feature}:#{feature}"])
|
74
81
|
|
75
|
-
exit 1
|
82
|
+
exit 1 unless confirm("Create a pull-request for feature branch named: '#{feature}' ?")
|
76
83
|
octokit = Github::api
|
77
84
|
|
78
85
|
description = Github::get_pull_request_description(feature)
|
@@ -95,34 +102,32 @@ when 'finish'
|
|
95
102
|
when 'merge'
|
96
103
|
dev_branch = Git::development_branch
|
97
104
|
fail_on_local_changes
|
98
|
-
|
105
|
+
|
106
|
+
Git::run_safe(["git fetch"])
|
99
107
|
|
100
108
|
feature = ARGV[1] || Git::current_branch
|
101
109
|
|
102
|
-
exit 1
|
110
|
+
exit 1 unless confirm("Merge feature branch named: '#{feature}' ?")
|
103
111
|
|
104
112
|
description = Github::get_pull_request_description_from_api(feature, dev_branch)
|
105
113
|
|
106
114
|
# Checkout the branch first to make sure we have it locally.
|
107
|
-
Git::run_safe(
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
# merge the feature branch into master
|
119
|
-
Git::run_safe("git merge --no-ff --edit -m #{description.shellescape} \"#{feature}\"")
|
115
|
+
Git::run_safe([
|
116
|
+
"git checkout \"#{feature}\"",
|
117
|
+
"git rebase --preserve-merges origin/#{feature}",
|
118
|
+
# pull the latest changes from master
|
119
|
+
"git checkout #{dev_branch}",
|
120
|
+
# rebase the unpushed master commits if any.
|
121
|
+
"git rebase --preserve-merges origin/#{dev_branch}",
|
122
|
+
# merge the feature branch into master
|
123
|
+
"git merge --no-ff --edit -m #{description.shellescape} \"#{feature}\"",
|
124
|
+
])
|
120
125
|
|
121
126
|
# init any submodules in the master branch
|
122
127
|
Git::submodules_update
|
123
128
|
|
124
129
|
# delete the local feature-branch
|
125
|
-
Git::run_safe("git branch -d \"#{feature}\"")
|
130
|
+
Git::run_safe(["git branch -d \"#{feature}\""])
|
126
131
|
|
127
132
|
# delete the remote branch we'll leave this off for now
|
128
133
|
# Git::run_safe("git push origin :\"#{feature}\"")
|
@@ -131,6 +136,9 @@ when 'merge'
|
|
131
136
|
|
132
137
|
puts
|
133
138
|
puts "Successfully merged feature-branch: #{feature} into #{dev_branch}"
|
139
|
+
puts "If you are satisfied with the result, do this:\n" + <<CMDS
|
140
|
+
git push
|
141
|
+
CMDS
|
134
142
|
|
135
143
|
when 'switch'
|
136
144
|
require_argument(:feature, :switch, min=2, max=3)
|
@@ -138,17 +146,77 @@ when 'switch'
|
|
138
146
|
|
139
147
|
Git::switch_branch(feature)
|
140
148
|
|
149
|
+
when 'prune'
|
150
|
+
require_argument(:feature, :prune, min=3, max=3)
|
151
|
+
location = ARGV[1]
|
152
|
+
option = ARGV[2]
|
153
|
+
|
154
|
+
# Check arguments.
|
155
|
+
if location != "local" and location != "origin"
|
156
|
+
abort("Valid locations: local, origin.")
|
157
|
+
end
|
158
|
+
|
159
|
+
if option != "preview" and option != "clean"
|
160
|
+
abort("Valid options: preview, clean.")
|
161
|
+
end
|
162
|
+
|
163
|
+
currentBranch = Git::current_branch()
|
164
|
+
|
165
|
+
def branches_cmd(location, currentBranch)
|
166
|
+
branch = location == 'origin' ? 'origin/master' : 'master'
|
167
|
+
return "git branch --merged #{branch} |
|
168
|
+
grep -v master |
|
169
|
+
grep -v stable |
|
170
|
+
grep -v #{currentBranch}"
|
171
|
+
end
|
172
|
+
|
173
|
+
def preview(location, currentBranch)
|
174
|
+
puts "Would delete the following..."
|
175
|
+
commands = branches_cmd(location, currentBranch)
|
176
|
+
|
177
|
+
if location == "local"
|
178
|
+
system(commands)
|
179
|
+
elsif location == "origin"
|
180
|
+
message = `git remote prune -n origin && #{commands}`
|
181
|
+
puts message.gsub(" * [would prune] origin/",'')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def delete(location, currentBranch)
|
186
|
+
puts "Deleting..."
|
187
|
+
commands = branches_cmd(location, currentBranch)
|
188
|
+
|
189
|
+
if location == "local"
|
190
|
+
system("#{commands} | xargs git branch -d")
|
191
|
+
elsif location == "origin"
|
192
|
+
system("git remote prune origin &&
|
193
|
+
git branch -r --merged origin/master |
|
194
|
+
grep -v master |
|
195
|
+
grep -v stable |
|
196
|
+
grep -v #{currentBranch} |
|
197
|
+
sed -n 's| origin/|:|p' |
|
198
|
+
xargs git push origin")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
if option == 'preview'
|
203
|
+
preview(location, currentBranch)
|
204
|
+
elsif option == 'clean'
|
205
|
+
exit unless confirm("Are you sure you want to prune branches?")
|
206
|
+
delete(location, currentBranch)
|
207
|
+
end
|
208
|
+
|
141
209
|
when 'clean'
|
142
210
|
args = ''
|
143
211
|
|
144
|
-
# Remove all untracked .
|
212
|
+
# Remove all untracked .gitignore'd files as well
|
145
213
|
args += 'x' if ARGV.include?('--all')
|
146
214
|
|
147
215
|
# -fd alone will NOT remove submodule directories, -ffd is required for this
|
148
|
-
Git::run_safe("git clean -ffd#{args}")
|
216
|
+
Git::run_safe(["git clean -ffd#{args}"])
|
149
217
|
|
150
218
|
when 'pull'
|
151
|
-
Git::run_safe("git fetch")
|
219
|
+
Git::run_safe(["git fetch"])
|
152
220
|
|
153
221
|
current = Git::current_branch
|
154
222
|
upstream = "#{current}@{upstream}"
|
@@ -159,7 +227,7 @@ when 'pull'
|
|
159
227
|
end
|
160
228
|
|
161
229
|
old_branch_hash = Git::branch_hash(current)
|
162
|
-
Git::run_safe("git rebase --preserve-merges origin/#{current}")
|
230
|
+
Git::run_safe(["git rebase --preserve-merges origin/#{current}"])
|
163
231
|
|
164
232
|
Git::submodules_update
|
165
233
|
|
@@ -179,7 +247,7 @@ when 'list'
|
|
179
247
|
when 'stashes'
|
180
248
|
current_branch = nil
|
181
249
|
|
182
|
-
|
250
|
+
unless ARGV.include?('-v')
|
183
251
|
current_branch = Git::current_branch
|
184
252
|
end
|
185
253
|
|
@@ -189,3 +257,4 @@ else
|
|
189
257
|
display_feature_help
|
190
258
|
end
|
191
259
|
|
260
|
+
log_command("feature #{$0}")
|
data/bin/hotfix
CHANGED
@@ -1,47 +1,49 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/signal_handlers.rb'
|
2
3
|
require_relative '../lib/github.rb'
|
3
4
|
require_relative '../lib/git.rb'
|
4
5
|
require_relative '../lib/helpers.rb'
|
5
6
|
|
6
7
|
command=ARGV.first
|
7
|
-
|
8
|
+
|
9
|
+
$0 = ARGV.join(" ")
|
10
|
+
|
8
11
|
case command
|
9
12
|
when 'start'
|
10
13
|
require_argument(:hotfix, :start)
|
11
|
-
hotfix =
|
14
|
+
hotfix = hotfix_branch(ARGV[1])
|
12
15
|
|
13
|
-
exit
|
16
|
+
exit unless confirm("Create hotfix branch named: '#{hotfix}' ?")
|
14
17
|
|
15
|
-
Git::run_safe(
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
Git::run_safe([
|
19
|
+
"git checkout stable",
|
20
|
+
"git pull --rebase",
|
21
|
+
"git branch \"#{hotfix}\" stable",
|
22
|
+
"git checkout \"#{hotfix}\""
|
23
|
+
])
|
19
24
|
|
20
25
|
Git::submodules_update
|
21
26
|
|
22
27
|
# Automatically setup remote tracking branch
|
23
|
-
Git::run_safe(
|
24
|
-
|
25
|
-
|
28
|
+
Git::run_safe([
|
29
|
+
"git config branch.#{hotfix}.remote origin",
|
30
|
+
"git config branch.#{hotfix}.merge refs/heads/#{hotfix}",
|
31
|
+
"git config branch.#{hotfix}.rebase true"
|
32
|
+
])
|
26
33
|
|
27
34
|
when 'switch'
|
28
35
|
require_argument(:hotfix, :switch, min=2, max=3)
|
29
|
-
hotfix =
|
36
|
+
hotfix = current_hotfix_branch
|
30
37
|
|
31
38
|
Git::switch_branch(hotfix)
|
32
39
|
|
33
40
|
when 'finish'
|
34
|
-
hotfix =
|
35
|
-
|
36
|
-
# ensure the hotfix name is the real branch name
|
37
|
-
if (!hotfix.start_with?("hotfix-"))
|
38
|
-
hotfix = "hotfix-" + hotfix
|
39
|
-
end
|
41
|
+
hotfix = current_hotfix_branch
|
40
42
|
|
41
43
|
# Push commits to origin
|
42
|
-
Git::run_safe("git push origin #{hotfix}:#{hotfix}")
|
44
|
+
Git::run_safe(["git push origin #{hotfix}:#{hotfix}"])
|
43
45
|
|
44
|
-
exit 1
|
46
|
+
exit 1 unless confirm("Create a pull-request for hotfix branch named: '#{hotfix}' ?")
|
45
47
|
octokit = Github::api
|
46
48
|
|
47
49
|
description = Github::get_pull_request_description(hotfix)
|
@@ -64,63 +66,49 @@ when 'finish'
|
|
64
66
|
when 'merge'
|
65
67
|
fail_on_local_changes
|
66
68
|
dev_branch = Git::development_branch
|
69
|
+
hotfix = current_hotfix_branch
|
67
70
|
|
68
|
-
Git::run_safe("git fetch")
|
69
|
-
|
70
|
-
if ARGV[1]
|
71
|
-
hotfix = BRANCH_PREFIX + ARGV[1]
|
72
|
-
else
|
73
|
-
hotfix = Git::current_branch
|
74
|
-
end
|
71
|
+
Git::run_safe(["git fetch"])
|
75
72
|
|
76
|
-
exit 1
|
73
|
+
exit 1 unless confirm("Merge hotfix named: '#{hotfix}' ?")
|
77
74
|
|
78
75
|
description = Github::get_pull_request_description_from_api(hotfix, 'stable')
|
79
|
-
|
80
|
-
# Checkout the branch to make sure we have it locally.
|
81
|
-
Git::run_safe("git checkout \"#{hotfix}\"")
|
82
|
-
Git::run_safe("git rebase --preserve-merges origin/#{hotfix}")
|
83
|
-
|
84
|
-
# Merge into stable
|
85
|
-
Git::run_safe("git checkout stable")
|
86
|
-
|
87
|
-
# pull the latest changes and rebase the unpushed commits if any.
|
88
|
-
Git::run_safe("git rebase --preserve-merges origin/stable")
|
89
|
-
|
90
|
-
# merge the hotfix branch into stable
|
91
|
-
Git::run_safe("git merge --no-ff --edit -m #{description.shellescape} \"#{hotfix}\"")
|
92
|
-
|
76
|
+
descriptionDev = Github::get_pull_request_description_from_api(hotfix, dev_branch)
|
93
77
|
# init any submodules in the stable branch
|
94
|
-
Git::submodules_update
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
78
|
+
update = Git::submodules_update("get")
|
79
|
+
|
80
|
+
Git::run_safe([
|
81
|
+
# Checkout the branch to make sure we have it locally.
|
82
|
+
"git checkout \"#{hotfix}\"",
|
83
|
+
"git rebase --preserve-merges origin/#{hotfix}",
|
84
|
+
# Merge into stable
|
85
|
+
"git checkout stable",
|
86
|
+
# pull the latest changes and rebase the unpushed commits if any.
|
87
|
+
"git rebase --preserve-merges origin/stable",
|
88
|
+
# merge the hotfix branch into stable
|
89
|
+
"git merge --no-ff --edit -m #{description.shellescape} \"#{hotfix}\"",
|
90
|
+
"#{update}",
|
91
|
+
# push the the merge to our origin
|
92
|
+
# Git::run_safe("git push origin")
|
93
|
+
# Merge into master
|
94
|
+
"git checkout #{dev_branch}",
|
95
|
+
# pull the latest changes and rebase the unpushed master commits if any.
|
96
|
+
"git rebase origin/#{dev_branch}",
|
97
|
+
# merge the hotfix branch into master
|
98
|
+
"git merge --no-ff --edit -m #{descriptionDev.shellescape} \"#{hotfix}\"",
|
99
|
+
# init any submodules in the master branch. Note: no need to change
|
100
|
+
# directories before calling git submodule since we are already in the
|
101
|
+
# projects top-level directory
|
102
|
+
"#{update}",
|
103
|
+
# push the the merge to our origin
|
104
|
+
# Git::run_safe("git push origin")
|
105
|
+
# delete the local hotfix branch
|
106
|
+
"git branch -d \"#{hotfix}\"",
|
107
|
+
# delete the remote hotfix branch -- we'll leave this off for now
|
108
|
+
# Git::run_safe("git push origin :\"#{hotfix}\"")
|
109
|
+
# checkout stable branch
|
110
|
+
"git checkout stable"
|
111
|
+
])
|
124
112
|
|
125
113
|
puts "Successfully merged hotfix branch: #{hotfix} into stable and #{dev_branch}"
|
126
114
|
puts "If you are satisfied with the result, do this:\n" + <<CMDS
|
@@ -140,3 +128,5 @@ when 'list'
|
|
140
128
|
else
|
141
129
|
display_hotfix_help
|
142
130
|
end
|
131
|
+
|
132
|
+
log_command("hotfix #{$0}")
|
data/lib/git.rb
CHANGED
@@ -4,6 +4,8 @@ module Git
|
|
4
4
|
return !clean
|
5
5
|
end
|
6
6
|
|
7
|
+
# Return the development branch specified by the
|
8
|
+
# feature.development-branch git config value
|
7
9
|
def self.development_branch
|
8
10
|
dev_branch = `git config feature.development-branch`.strip
|
9
11
|
if !dev_branch || $? != 0
|
@@ -14,7 +16,7 @@ module Git
|
|
14
16
|
dev_branch
|
15
17
|
end
|
16
18
|
|
17
|
-
# Returns an array of branches that aren't merged into the
|
19
|
+
# Returns an array of branches that aren't merged into the specified branch
|
18
20
|
def self.branches_not_merged_into(branch)
|
19
21
|
self::all_branches - self::merged_branches(branch)
|
20
22
|
end
|
@@ -53,23 +55,27 @@ module Git
|
|
53
55
|
def self.all_branches()
|
54
56
|
`git for-each-ref --sort=-committerdate --format='%(refname)' refs/heads refs/remotes`.
|
55
57
|
split("\n").
|
56
|
-
map {|branch| branch.sub(/refs\/\w+\//, '') }.
|
58
|
+
map {|branch| branch.sub(/refs\/\w+\//, '') }.
|
59
|
+
uniq.
|
60
|
+
reject {|branch| branch =~ %r{\w+/HEAD} }
|
57
61
|
end
|
58
62
|
|
59
|
-
#
|
63
|
+
# Returns the name of the currently checked out branch, or nil if detached.
|
60
64
|
def self.current_branch()
|
61
65
|
ref = `git symbolic-ref -q HEAD`.strip
|
62
66
|
ref.split('/').last
|
63
67
|
end
|
64
68
|
|
65
|
-
#
|
69
|
+
# Returns the SHA1 hash that the specified branch or symbol points to
|
66
70
|
def self.branch_hash(branch)
|
67
71
|
`git rev-parse --verify --quiet "#{branch}" 2>/dev/null`.strip
|
68
72
|
end
|
69
73
|
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
74
|
+
# Returns formatted string containing:
|
75
|
+
#
|
76
|
+
# commit_hash Author Name (relative date)
|
77
|
+
#
|
78
|
+
# for the specified branch or commit
|
73
79
|
def self.branch_info(branch)
|
74
80
|
# branch info format: hash author (relative date)
|
75
81
|
format = "%h %an %Cgreen(%ar)%Creset"
|
@@ -78,10 +84,18 @@ module Git
|
|
78
84
|
sprintf "%-30s %s", simple_branch, branch_info
|
79
85
|
end
|
80
86
|
|
81
|
-
def self.run_safe(
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
def self.run_safe(commands)
|
88
|
+
while command = commands.shift
|
89
|
+
puts "> " + command
|
90
|
+
unless system(command)
|
91
|
+
puts "\tFailed on \`#{command}\`"
|
92
|
+
puts "\tWould have run:"
|
93
|
+
commands.each do |a|
|
94
|
+
puts "\t" + a
|
95
|
+
exit
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
85
99
|
end
|
86
100
|
|
87
101
|
def self.show_stashes_saved_on(branch = nil)
|
@@ -128,7 +142,7 @@ module Git
|
|
128
142
|
|
129
143
|
def self.stashes
|
130
144
|
# Do we even have a stash?
|
131
|
-
|
145
|
+
unless File.exist? '.git/refs/stash'
|
132
146
|
return []
|
133
147
|
end
|
134
148
|
|
@@ -146,19 +160,35 @@ module Git
|
|
146
160
|
end
|
147
161
|
end
|
148
162
|
|
163
|
+
##
|
164
|
+
# Switch to the specified branch.
|
165
|
+
# Because we use submodules, we have to check for updates to those
|
166
|
+
# submodules when we checkout a branch
|
167
|
+
#
|
168
|
+
# args: --clean - remove every unstaged file, including non-existant
|
169
|
+
# submodules
|
170
|
+
#
|
149
171
|
def self.switch_branch(branch)
|
150
|
-
self.run_safe("git checkout \"#{branch}\"")
|
172
|
+
self.run_safe(["git checkout \"#{branch}\""])
|
151
173
|
self.submodules_update
|
152
|
-
self.run_safe("git clean -ffd") if ARGV.include?('--clean')
|
174
|
+
self.run_safe(["git clean -ffd"]) if ARGV.include?('--clean')
|
153
175
|
|
154
176
|
self.show_stashes_saved_on(branch)
|
155
177
|
end
|
156
178
|
|
157
|
-
|
179
|
+
##
|
180
|
+
# Update / initialize submodules from the TLD
|
181
|
+
#
|
182
|
+
def self.submodules_update(mode = nil)
|
158
183
|
# capture only the path, not the newline
|
159
184
|
basedir = `git rev-parse --show-toplevel`.split("\n").first
|
185
|
+
command = "cd #{basedir} && git submodule --quiet update --init --recursive"
|
160
186
|
|
161
|
-
|
187
|
+
if mode == "get"
|
188
|
+
return command
|
189
|
+
else
|
190
|
+
Git::run_safe([command])
|
191
|
+
end
|
162
192
|
end
|
163
193
|
|
164
194
|
##
|
@@ -167,4 +197,8 @@ module Git
|
|
167
197
|
def self.commit_message(ref)
|
168
198
|
`git log -1 --format="%B" #{ref}`.strip
|
169
199
|
end
|
200
|
+
|
201
|
+
def self.git_dir()
|
202
|
+
`git rev-parse --git-dir`.strip
|
203
|
+
end
|
170
204
|
end
|
data/lib/github.rb
CHANGED
@@ -54,7 +54,7 @@ module Github
|
|
54
54
|
end
|
55
55
|
|
56
56
|
##
|
57
|
-
# Returns a hash containing username and github oauth token
|
57
|
+
# Returns a hash containing the username and github oauth token
|
58
58
|
#
|
59
59
|
# Prompts the user for credentials if the token isn't stored in git config
|
60
60
|
##
|
@@ -73,11 +73,11 @@ module Github
|
|
73
73
|
|
74
74
|
auth = auth || octokit.create_authorization(authorization_info)
|
75
75
|
|
76
|
-
success =
|
76
|
+
success =
|
77
77
|
system("git config --global github.user #{username}") &&
|
78
78
|
system("git config --global github.token #{auth[:token]}")
|
79
79
|
|
80
|
-
|
80
|
+
unless success
|
81
81
|
puts "Couldn't set git config"
|
82
82
|
exit
|
83
83
|
end
|
@@ -154,7 +154,7 @@ Body of pull-request
|
|
154
154
|
|
155
155
|
def self.get_pull_request_description_from_api(branch_name, into_branch)
|
156
156
|
octokit = Github::api
|
157
|
-
# Should succeed if authentication is
|
157
|
+
# Should succeed if authentication is set up.
|
158
158
|
pulls = octokit.pulls(Github::get_github_repo)
|
159
159
|
pull = pulls.find {|pull| branch_name == pull[:head][:ref] }
|
160
160
|
|