git-smart 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +28 -13
- data/Rakefile +4 -1
- data/VERSION +1 -1
- data/bin/git-smart-log +7 -0
- data/docs/smart-pull.html +45 -16
- data/git-smart.gemspec +5 -3
- data/lib/commands/smart-log.rb +9 -0
- data/lib/commands/smart-pull.rb +5 -0
- data/lib/git-smart/git_repo.rb +14 -3
- data/spec/spec_helper.rb +3 -3
- metadata +7 -4
data/README.md
CHANGED
@@ -7,15 +7,14 @@ Adds some additional git commands to add some smarts to your workflow. These com
|
|
7
7
|
0. It should do the 'right thing' in all situations - an inexperienced git user should be guided away from making simple mistakes.
|
8
8
|
0. It should make every attempt to explain to the user what decisions it has made, and why.
|
9
9
|
0. All git commands that modify the repository should be shown to the user - hopefully this helps the user eventually learn the underlying git commands, and when they're relevant.
|
10
|
-
0. All git commands, destructive or not, and their output should be shown to the user with the -v/--verbose flag. (not implemented yet)
|
11
10
|
|
12
|
-
|
11
|
+
## Installing
|
13
12
|
|
14
13
|
All you need to do is grab the gem:
|
15
14
|
|
16
15
|
gem install git-smart
|
17
16
|
|
18
|
-
|
17
|
+
This will add an executable for each command, e.g. `git-smart-pull`. You call them using git's simple syntax for [custom commands](http://www.nullstyle.com/2007/06/22/create-custom-commands-in-git/), e.g. `git smart-pull`. They'll be removed when you uninstall the gem.
|
19
18
|
|
20
19
|
You almost certainly want to run this as well, to allow git commands to be output with colour:
|
21
20
|
|
@@ -23,21 +22,37 @@ You almost certainly want to run this as well, to allow git commands to be outpu
|
|
23
22
|
|
24
23
|
Git normally only colours output when being run from the terminal, not from within scripts like these. This sorts that right out.
|
25
24
|
|
26
|
-
|
25
|
+
## Get smart!
|
27
26
|
|
28
|
-
|
27
|
+
There's only three commands at this point, but there'll be more!
|
29
28
|
|
30
|
-
|
31
|
-
git smart-merge <branchname>
|
29
|
+
### smart-pull
|
32
30
|
|
33
|
-
|
31
|
+
Run `git smart-pull` whenever you would have run `git pull`. It doesn't take any arguments, it'll use the tracking branch configuration or assume 'origin/same-branch-name'.
|
34
32
|
|
35
|
-
|
33
|
+
In brief, it'll detect the best way to grab the changes from the server and update your local branch, using a `git rebase -p` if there's no easier way. It'll also stash/pop local changes if need be.
|
36
34
|
|
37
|
-
|
38
|
-
- [smart-merge](http://github-displayer.heroku.com/geelen/git-smart/raw/master/docs/smart-merge.html)
|
35
|
+
Read what it does in detail: [smart-pull](http://github-displayer.heroku.com/geelen/git-smart/raw/master/docs/smart-pull.html)
|
39
36
|
|
40
|
-
|
37
|
+
Recommended alias to use: `gup`
|
38
|
+
|
39
|
+
### smart-merge
|
40
|
+
|
41
|
+
Run `git smart-merge` when you would have run `git merge`. This is basically a wrapper around `git merge --no-ff`, which should have been the default anyway. It also does a stash/pop if required, and reports a bit of helpful output.
|
42
|
+
|
43
|
+
Details here: [smart-merge](http://github-displayer.heroku.com/geelen/git-smart/raw/master/docs/smart-merge.html)
|
44
|
+
|
45
|
+
Recommended alias to use: `gm`
|
46
|
+
|
47
|
+
### smart-log
|
48
|
+
|
49
|
+
Big hat tip to [@ben\_h](http://twitter.com/ben_h) for this one - it's an alias to a completely badass git log format that not many people know about.
|
50
|
+
|
51
|
+
Details here: [smart-log](http://github-displayer.heroku.com/geelen/git-smart/raw/master/docs/smart-log.html)
|
52
|
+
|
53
|
+
Recommended alias to use: `gl`
|
54
|
+
|
55
|
+
## Contributing to git-smart
|
41
56
|
|
42
57
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
43
58
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -47,7 +62,7 @@ The code for each of these commands has been annotated with comments and rendere
|
|
47
62
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
48
63
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
49
64
|
|
50
|
-
|
65
|
+
## Copyright
|
51
66
|
|
52
67
|
Copyright (c) 2011 Glen Maddern. See LICENSE.txt for
|
53
68
|
further details.
|
data/Rakefile
CHANGED
@@ -47,7 +47,9 @@ end
|
|
47
47
|
|
48
48
|
desc "Generate the rocco docs"
|
49
49
|
task :rocco do
|
50
|
-
|
50
|
+
base_dir = File.dirname(__FILE__)
|
51
|
+
%x[cd #{base_dir}/lib/commands && rocco *.rb -o ../../docs]
|
52
|
+
%x[cd #{base_dir} && git add docs]
|
51
53
|
end
|
52
54
|
|
53
55
|
task :release => :rocco
|
@@ -72,6 +74,7 @@ GitSmart.run('#{cmd}', ARGV)
|
|
72
74
|
}
|
73
75
|
}
|
74
76
|
`chmod a+x #{filename}`
|
77
|
+
`cd #{base_dir} && git add #{filename}`
|
75
78
|
puts "Wrote #{filename}"
|
76
79
|
}
|
77
80
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/bin/git-smart-log
ADDED
data/docs/smart-pull.html
CHANGED
@@ -161,6 +161,20 @@ uses internally.</p>
|
|
161
161
|
<div class="octowrap">
|
162
162
|
<a class="octothorpe" href="#section-11">#</a>
|
163
163
|
</div>
|
164
|
+
<p>Report how many commits are new locally, since that’s useful information.</p>
|
165
|
+
</td>
|
166
|
+
<td class=code>
|
167
|
+
<div class='highlight'><pre> <span class="n">new_commits_locally</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">rev_list</span><span class="p">(</span><span class="n">merge_base</span><span class="p">,</span> <span class="n">head</span><span class="p">)</span>
|
168
|
+
<span class="k">if</span> <span class="o">!</span><span class="n">new_commits_locally</span><span class="o">.</span><span class="n">empty?</span>
|
169
|
+
<span class="n">note</span> <span class="s2">"You have </span><span class="si">#{</span><span class="n">new_commits_locally</span><span class="o">.</span><span class="n">length</span><span class="si">}</span><span class="s2"> new commit</span><span class="si">#{</span><span class="s1">'s'</span> <span class="k">if</span> <span class="n">new_commits_locally</span><span class="o">.</span><span class="n">length</span> <span class="o">!=</span> <span class="mi">1</span><span class="si">}</span><span class="s2"> on '</span><span class="si">#{</span><span class="n">branch</span><span class="si">}</span><span class="s2">'."</span>
|
170
|
+
<span class="k">end</span></pre></div>
|
171
|
+
</td>
|
172
|
+
</tr>
|
173
|
+
<tr id='section-12'>
|
174
|
+
<td class=docs>
|
175
|
+
<div class="octowrap">
|
176
|
+
<a class="octothorpe" href="#section-12">#</a>
|
177
|
+
</div>
|
164
178
|
<p>By comparing the merge_base to both HEAD and the remote, we can
|
165
179
|
determine whether both or only one have moved on.
|
166
180
|
If the remote hasn’t changed, we’re already up to date, so there’s nothing
|
@@ -173,14 +187,14 @@ to pull.</p>
|
|
173
187
|
<span class="k">else</span></pre></div>
|
174
188
|
</td>
|
175
189
|
</tr>
|
176
|
-
<tr id='section-
|
190
|
+
<tr id='section-13'>
|
177
191
|
<td class=docs>
|
178
192
|
<div class="octowrap">
|
179
|
-
<a class="octothorpe" href="#section-
|
193
|
+
<a class="octothorpe" href="#section-13">#</a>
|
180
194
|
</div>
|
181
195
|
<p>If the remote <em>has</em> moved on, we actually have some work to do:</p>
|
182
196
|
|
183
|
-
<p>First, report how many commits are new on remote. Because that’s useful information.</p>
|
197
|
+
<p>First, report how many commits are new on remote. Because that’s useful information, too.</p>
|
184
198
|
</td>
|
185
199
|
<td class=code>
|
186
200
|
<div class='highlight'><pre> <span class="n">new_commits_on_remote</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">rev_list</span><span class="p">(</span><span class="n">merge_base</span><span class="p">,</span> <span class="n">remote</span><span class="p">)</span>
|
@@ -188,10 +202,10 @@ to pull.</p>
|
|
188
202
|
<span class="n">note</span> <span class="s2">"There </span><span class="si">#{</span><span class="n">is_are</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="n">new_commits_on_remote</span><span class="o">.</span><span class="n">length</span><span class="si">}</span><span class="s2"> new commit</span><span class="si">#{</span><span class="n">s_or_not</span><span class="si">}</span><span class="s2"> on '</span><span class="si">#{</span><span class="n">upstream_branch</span><span class="si">}</span><span class="s2">'."</span></pre></div>
|
189
203
|
</td>
|
190
204
|
</tr>
|
191
|
-
<tr id='section-
|
205
|
+
<tr id='section-14'>
|
192
206
|
<td class=docs>
|
193
207
|
<div class="octowrap">
|
194
|
-
<a class="octothorpe" href="#section-
|
208
|
+
<a class="octothorpe" href="#section-14">#</a>
|
195
209
|
</div>
|
196
210
|
<p>Next, detect if there are local changes and stash them.</p>
|
197
211
|
</td>
|
@@ -205,10 +219,10 @@ to pull.</p>
|
|
205
219
|
<span class="n">success_messages</span> <span class="o">=</span> <span class="o">[]</span></pre></div>
|
206
220
|
</td>
|
207
221
|
</tr>
|
208
|
-
<tr id='section-
|
222
|
+
<tr id='section-15'>
|
209
223
|
<td class=docs>
|
210
224
|
<div class="octowrap">
|
211
|
-
<a class="octothorpe" href="#section-
|
225
|
+
<a class="octothorpe" href="#section-15">#</a>
|
212
226
|
</div>
|
213
227
|
<p>Then, bring the local branch up to date.</p>
|
214
228
|
|
@@ -222,10 +236,10 @@ to pull.</p>
|
|
222
236
|
<span class="k">else</span></pre></div>
|
223
237
|
</td>
|
224
238
|
</tr>
|
225
|
-
<tr id='section-
|
239
|
+
<tr id='section-16'>
|
226
240
|
<td class=docs>
|
227
241
|
<div class="octowrap">
|
228
|
-
<a class="octothorpe" href="#section-
|
242
|
+
<a class="octothorpe" href="#section-16">#</a>
|
229
243
|
</div>
|
230
244
|
<p>If our local branch has new commits, we need to rebase them on top of master.</p>
|
231
245
|
|
@@ -239,10 +253,10 @@ instead of ignoring them. For a description as to why, see my <a href="(https://
|
|
239
253
|
<span class="k">end</span></pre></div>
|
240
254
|
</td>
|
241
255
|
</tr>
|
242
|
-
<tr id='section-
|
256
|
+
<tr id='section-17'>
|
243
257
|
<td class=docs>
|
244
258
|
<div class="octowrap">
|
245
|
-
<a class="octothorpe" href="#section-
|
259
|
+
<a class="octothorpe" href="#section-17">#</a>
|
246
260
|
</div>
|
247
261
|
<p>If we stashed before, pop now.</p>
|
248
262
|
</td>
|
@@ -253,19 +267,34 @@ instead of ignoring them. For a description as to why, see my <a href="(https://
|
|
253
267
|
<span class="k">end</span></pre></div>
|
254
268
|
</td>
|
255
269
|
</tr>
|
256
|
-
<tr id='section-
|
270
|
+
<tr id='section-18'>
|
257
271
|
<td class=docs>
|
258
272
|
<div class="octowrap">
|
259
|
-
<a class="octothorpe" href="#section-
|
273
|
+
<a class="octothorpe" href="#section-18">#</a>
|
260
274
|
</div>
|
261
275
|
<p>Display a nice completion message in large, friendly letters.</p>
|
262
|
-
|
263
276
|
</td>
|
264
277
|
<td class=code>
|
265
278
|
<div class='highlight'><pre> <span class="n">success</span> <span class="o">[</span><span class="s2">"All good."</span><span class="p">,</span> <span class="o">*</span><span class="n">success_messages</span><span class="o">].</span><span class="n">join</span><span class="p">(</span><span class="s2">" "</span><span class="p">)</span>
|
266
|
-
<span class="k">end</span>
|
279
|
+
<span class="k">end</span></pre></div>
|
280
|
+
</td>
|
281
|
+
</tr>
|
282
|
+
<tr id='section-19'>
|
283
|
+
<td class=docs>
|
284
|
+
<div class="octowrap">
|
285
|
+
<a class="octothorpe" href="#section-19">#</a>
|
286
|
+
</div>
|
287
|
+
<p>Still to do:</p>
|
288
|
+
|
289
|
+
<ul>
|
290
|
+
<li>Ensure ORIG_HEAD is correctly set at the end of each run.</li>
|
291
|
+
<li>If the rebase fails, and you’ve done a stash, remind the user to unstash</li>
|
292
|
+
</ul>
|
293
|
+
|
267
294
|
|
268
|
-
|
295
|
+
</td>
|
296
|
+
<td class=code>
|
297
|
+
<div class='highlight'><pre> <span class="k">end</span>
|
269
298
|
<span class="k">end</span></pre></div>
|
270
299
|
</td>
|
271
300
|
</tr>
|
data/git-smart.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{git-smart}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Glen Maddern"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-06}
|
13
13
|
s.description = %q{Installs some additional 'smart' git commands, like `git smart-pull`.}
|
14
14
|
s.email = %q{glenmaddern@gmail.com}
|
15
|
-
s.executables = ["git-smart-pull", "git-smart-merge"]
|
15
|
+
s.executables = ["git-smart-log", "git-smart-pull", "git-smart-merge"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
18
18
|
"README.md"
|
@@ -24,12 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
+
"bin/git-smart-log",
|
27
28
|
"bin/git-smart-merge",
|
28
29
|
"bin/git-smart-pull",
|
29
30
|
"docs/images/git-smart.png",
|
30
31
|
"docs/smart-merge.html",
|
31
32
|
"docs/smart-pull.html",
|
32
33
|
"git-smart.gemspec",
|
34
|
+
"lib/commands/smart-log.rb",
|
33
35
|
"lib/commands/smart-merge.rb",
|
34
36
|
"lib/commands/smart-pull.rb",
|
35
37
|
"lib/core_ext/array.rb",
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#This is a super simple alias for the most badass of log outputs that git
|
2
|
+
#offers. Uses git log --graph under the hood.
|
3
|
+
#
|
4
|
+
#Thanks to [@ben_h](http://twitter.com/ben_h) for this one!
|
5
|
+
GitSmart.register 'smart-log' do |repo, args|
|
6
|
+
#Super simple, passes the args through to git log, but
|
7
|
+
#ratchets up the badassness quotient.
|
8
|
+
repo.log_to_shell('--pretty=format:%Cblue%h%d%Creset %ar %Cgreen%an%Creset %s', '--graph', *args)
|
9
|
+
end
|
data/lib/commands/smart-pull.rb
CHANGED
@@ -105,5 +105,10 @@ GitSmart.register 'smart-pull' do |repo, args|
|
|
105
105
|
success ["All good.", *success_messages].join(" ")
|
106
106
|
end
|
107
107
|
|
108
|
+
#Still to do:
|
109
|
+
#
|
110
|
+
#* Ensure ORIG_HEAD is correctly set at the end of each run.
|
111
|
+
#* If the rebase fails, and you've done a stash, remind the user to unstash
|
112
|
+
|
108
113
|
end
|
109
114
|
end
|
data/lib/git-smart/git_repo.rb
CHANGED
@@ -89,12 +89,16 @@ class GitRepo
|
|
89
89
|
git!('rebase', '-p', upstream)
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
92
|
+
def read_log(nr)
|
93
93
|
git('log', '--oneline', '-n', nr.to_s).split("\n").map { |l| l.split(" ",2) }
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
97
|
-
|
96
|
+
def last_commit_messages(nr)
|
97
|
+
read_log(nr).map(&:last)
|
98
|
+
end
|
99
|
+
|
100
|
+
def log_to_shell(*args)
|
101
|
+
git_shell('log', *args)
|
98
102
|
end
|
99
103
|
|
100
104
|
def merge_no_ff!(target)
|
@@ -116,6 +120,13 @@ class GitRepo
|
|
116
120
|
output
|
117
121
|
end
|
118
122
|
|
123
|
+
def git_shell(*args)
|
124
|
+
puts "Executing: #{['git', *args].join(" ")}"
|
125
|
+
Dir.chdir(@dir) {
|
126
|
+
system('git', *args)
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
119
130
|
def config(name)
|
120
131
|
remote = git('config', name).chomp
|
121
132
|
remote.empty? ? nil : remote
|
data/spec/spec_helper.rb
CHANGED
@@ -53,12 +53,12 @@ end
|
|
53
53
|
|
54
54
|
RSpec::Matchers.define :have_last_few_commits do |expected|
|
55
55
|
failure_message_for_should do |dir|
|
56
|
-
"expected '#{dir}' to have last few commits of #{expected.inspect}, got #{GitRepo.new(dir).
|
56
|
+
"expected '#{dir}' to have last few commits of #{expected.inspect}, got #{GitRepo.new(dir).last_commit_messages(expected.length).inspect}"
|
57
57
|
end
|
58
58
|
failure_message_for_should_not do |actual|
|
59
|
-
"expected '#{dir}' to not have git status of #{expected.inspect}, got #{GitRepo.new(dir).
|
59
|
+
"expected '#{dir}' to not have git status of #{expected.inspect}, got #{GitRepo.new(dir).last_commit_messages(expected.length).inspect}"
|
60
60
|
end
|
61
61
|
match do |dir|
|
62
|
-
GitRepo.new(dir).
|
62
|
+
GitRepo.new(dir).last_commit_messages(expected.length) == expected
|
63
63
|
end
|
64
64
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-smart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Glen Maddern
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-06 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -111,6 +111,7 @@ dependencies:
|
|
111
111
|
description: Installs some additional 'smart' git commands, like `git smart-pull`.
|
112
112
|
email: glenmaddern@gmail.com
|
113
113
|
executables:
|
114
|
+
- git-smart-log
|
114
115
|
- git-smart-pull
|
115
116
|
- git-smart-merge
|
116
117
|
extensions: []
|
@@ -125,12 +126,14 @@ files:
|
|
125
126
|
- README.md
|
126
127
|
- Rakefile
|
127
128
|
- VERSION
|
129
|
+
- bin/git-smart-log
|
128
130
|
- bin/git-smart-merge
|
129
131
|
- bin/git-smart-pull
|
130
132
|
- docs/images/git-smart.png
|
131
133
|
- docs/smart-merge.html
|
132
134
|
- docs/smart-pull.html
|
133
135
|
- git-smart.gemspec
|
136
|
+
- lib/commands/smart-log.rb
|
134
137
|
- lib/commands/smart-merge.rb
|
135
138
|
- lib/commands/smart-pull.rb
|
136
139
|
- lib/core_ext/array.rb
|