lolcommits 0.6.4 → 0.6.5
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.
- checksums.yaml +8 -8
- data/CHANGELOG.md +3 -0
- data/bin/lolcommits +8 -4
- data/features/lolcommits.feature +117 -25
- data/features/step_definitions/lolcommits_steps.rb +90 -8
- data/lib/core_ext/mercurial-ruby/command.rb +36 -0
- data/lib/core_ext/mercurial-ruby/shell.rb +16 -0
- data/lib/core_ext/string.rb +9 -0
- data/lib/lolcommits.rb +13 -1
- data/lib/lolcommits/{git_info.rb → backends/git_info.rb} +9 -1
- data/lib/lolcommits/backends/installation_git.rb +121 -0
- data/lib/lolcommits/backends/installation_mercurial.rb +88 -0
- data/lib/lolcommits/backends/mercurial_info.rb +81 -0
- data/lib/lolcommits/cli/fatals.rb +10 -6
- data/lib/lolcommits/cli/timelapse_gif.rb +1 -1
- data/lib/lolcommits/configuration.rb +6 -1
- data/lib/lolcommits/installation.rb +13 -101
- data/lib/lolcommits/plugins/lol_protonet.rb +1 -1
- data/lib/lolcommits/plugins/lol_slack.rb +1 -1
- data/lib/lolcommits/plugins/lolsrv.rb +2 -2
- data/lib/lolcommits/plugins/uploldz.rb +4 -4
- data/lib/lolcommits/runner.rb +11 -4
- data/lib/lolcommits/vcs_info.rb +63 -0
- data/lib/lolcommits/version.rb +1 -1
- data/lolcommits.gemspec +1 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDZhY2Q5NDc0OTVjMzA5ZDE4MmFkNzc3OTc4YTBkM2UxNGQzOTcyNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2EwYjliMDA0ZmFmYThhOWVhNDUyMjlkMGMyZTA0ODAzNDE0ZTk5Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmYzMmU0YjJjYjlmNTk4ODFlNDM0MDVkZDlhOWQzODI3ZTE0ZGM4ZTg4NjY1
|
10
|
+
ZDBhODFlNWU0NDUyODA0Y2FjNTM5YzVkNzk5MDNlNzI0ODlmMTgwYjE5Njc5
|
11
|
+
ZWU2NjY0MmM0MTc5NzcwZjhkODU0ZDAyODFkMmM3ODU4YTcyY2M=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmQzZGVjYWE3YWU5ZjViOWZhNTZlYTFiOGMwNTE3OTA5MWEzMzFmZTFjYjc0
|
14
|
+
ODliNTdjOGVkNzJhMWFhODlhZTczZjk4NTdjNTQ3NDI1MTUxODMxYmZiNDI2
|
15
|
+
Njc1MThhMmVlZDBkYmI2NThjNDJiYjFmMTBjNDZkMWY0ZWUwYjE=
|
data/CHANGELOG.md
CHANGED
data/bin/lolcommits
CHANGED
@@ -113,7 +113,7 @@ def do_configure
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def do_last
|
116
|
-
Fatals.
|
116
|
+
Fatals.die_if_not_vcs_repo!
|
117
117
|
lolimage = configuration.most_recent
|
118
118
|
if lolimage.nil?
|
119
119
|
warn 'No lolcommits have been captured for this repository yet.'
|
@@ -132,9 +132,11 @@ def change_dir_to_root_or_repo!
|
|
132
132
|
loop do
|
133
133
|
cur = File.expand_path('.')
|
134
134
|
nxt = File.expand_path('..', cur)
|
135
|
-
if
|
136
|
-
|
135
|
+
if nxt == cur
|
136
|
+
warn 'Repository root not found'
|
137
|
+
return
|
137
138
|
end
|
139
|
+
return if VCSInfo.repo_root?
|
138
140
|
Dir.chdir(nxt)
|
139
141
|
end
|
140
142
|
end
|
@@ -304,6 +306,8 @@ Fatals.die_on_fatal_platform_conditions!
|
|
304
306
|
#
|
305
307
|
change_dir_to_root_or_repo!
|
306
308
|
|
309
|
+
# TODO: Allow local backend definitions?
|
310
|
+
|
307
311
|
#
|
308
312
|
# load system local plugins
|
309
313
|
#
|
@@ -326,7 +330,7 @@ elsif Choice.choices[:devices]
|
|
326
330
|
elsif Choice.choices[:last]
|
327
331
|
do_last
|
328
332
|
elsif Choice.choices[:browse]
|
329
|
-
Fatals.
|
333
|
+
Fatals.die_if_not_vcs_repo!
|
330
334
|
Launcher.open_folder(configuration.loldir)
|
331
335
|
elsif Choice.choices[:gif]
|
332
336
|
TimelapseGif.new(configuration).run(Choice.choices[:gif])
|
data/features/lolcommits.feature
CHANGED
@@ -24,31 +24,31 @@ Feature: Basic UI functionality
|
|
24
24
|
Given I am in a git repo
|
25
25
|
When I successfully run `lolcommits --enable`
|
26
26
|
Then the output should contain "installed lolcommit hook to:"
|
27
|
-
And the lolcommits post-commit hook should be properly installed
|
27
|
+
And the lolcommits git post-commit hook should be properly installed
|
28
28
|
And the exit status should be 0
|
29
29
|
|
30
|
-
Scenario: Enable in a git repo that already has a post-commit hook
|
30
|
+
Scenario: Enable in a git repo that already has a git post-commit hook
|
31
31
|
Given I am in a git repo
|
32
|
-
And a post-commit hook with "#!/bin/sh\n\n/my/own/script"
|
32
|
+
And a git post-commit hook with "#!/bin/sh\n\n/my/own/script"
|
33
33
|
When I successfully run `lolcommits --enable`
|
34
34
|
Then the output should contain "installed lolcommit hook to:"
|
35
|
-
And the lolcommits post-commit hook should be properly installed
|
36
|
-
And the post-commit hook should contain "#!/bin/sh"
|
37
|
-
And the post-commit hook should contain "/my/own/script"
|
35
|
+
And the lolcommits git post-commit hook should be properly installed
|
36
|
+
And the git post-commit hook should contain "#!/bin/sh"
|
37
|
+
And the git post-commit hook should contain "/my/own/script"
|
38
38
|
And the exit status should be 0
|
39
39
|
|
40
|
-
Scenario: Enable in a git repo that has post-commit hook with a bad shebang
|
40
|
+
Scenario: Enable in a git repo that has git post-commit hook with a bad shebang
|
41
41
|
Given I am in a git repo
|
42
|
-
And a post-commit hook with "#!/bin/ruby"
|
42
|
+
And a git post-commit hook with "#!/bin/ruby"
|
43
43
|
And I run `lolcommits --enable`
|
44
44
|
Then the output should contain "doesn't start with a good shebang"
|
45
|
-
And the post-commit hook should not contain "lolcommits --capture"
|
45
|
+
And the git post-commit hook should not contain "lolcommits --capture"
|
46
46
|
And the exit status should be 1
|
47
47
|
|
48
48
|
Scenario: Enable in a git repo passing capture arguments
|
49
49
|
Given I am in a git repo
|
50
50
|
When I successfully run `lolcommits --enable -w 5 --fork`
|
51
|
-
Then the post-commit hook should contain "lolcommits --capture -w 5 --fork"
|
51
|
+
Then the git post-commit hook should contain "lolcommits --capture -w 5 --fork"
|
52
52
|
And the exit status should be 0
|
53
53
|
|
54
54
|
Scenario: Disable in a enabled git repo
|
@@ -63,7 +63,7 @@ Feature: Basic UI functionality
|
|
63
63
|
When I run `lolcommits --enable`
|
64
64
|
Then the output should contain:
|
65
65
|
"""
|
66
|
-
You don't appear to be in the base directory of a
|
66
|
+
You don't appear to be in the base directory of a supported vcs project.
|
67
67
|
"""
|
68
68
|
And the exit status should be 1
|
69
69
|
|
@@ -77,7 +77,7 @@ Feature: Basic UI functionality
|
|
77
77
|
And a file named "~/.lolcommits/forked/tmp_snapshot.jpg" should not exist
|
78
78
|
And there should be exactly 1 jpg in "~/.lolcommits/forked"
|
79
79
|
|
80
|
-
Scenario: Commiting in an enabled repo triggers successful capture
|
80
|
+
Scenario: Commiting in an enabled git repo triggers successful capture
|
81
81
|
Given I am in a git repo named "myrepo" with lolcommits enabled
|
82
82
|
When I do a git commit
|
83
83
|
Then the output should contain "*** Preserving this moment in history."
|
@@ -85,7 +85,7 @@ Feature: Basic UI functionality
|
|
85
85
|
And a file named "~/.lolcommits/myrepo/tmp_snapshot.jpg" should not exist
|
86
86
|
And there should be exactly 1 jpg in "~/.lolcommits/myrepo"
|
87
87
|
|
88
|
-
Scenario: Commiting in enabled repo subdirectory triggers successful capture
|
88
|
+
Scenario: Commiting in enabled git repo subdirectory triggers successful capture
|
89
89
|
Given I am in a git repo named "testcapture" with lolcommits enabled
|
90
90
|
And a directory named "subdir"
|
91
91
|
And an empty file named "subdir/FOOBAR"
|
@@ -158,7 +158,7 @@ Feature: Basic UI functionality
|
|
158
158
|
When I successfully run `lolcommits --test --show-config`
|
159
159
|
Then the output should match /loltext:\s+enabled: false/
|
160
160
|
|
161
|
-
Scenario: test capture should work regardless of whether in a
|
161
|
+
Scenario: test capture should work regardless of whether in a lolrepo
|
162
162
|
Given I am in a directory named "nothingtoseehere"
|
163
163
|
When I run `lolcommits --test --capture`
|
164
164
|
Then the output should contain "*** Capturing in test mode."
|
@@ -171,13 +171,13 @@ Feature: Basic UI functionality
|
|
171
171
|
Then a directory named "~/.lolcommits/test" should exist
|
172
172
|
And a directory named "~/.lolcommits/randomgitrepo" should not exist
|
173
173
|
|
174
|
-
Scenario: last command should work properly when in a lolrepo
|
174
|
+
Scenario: last command should work properly when in a git lolrepo
|
175
175
|
Given I am in a git repo
|
176
176
|
And its loldir has 2 lolimages
|
177
177
|
When I run `lolcommits --last`
|
178
178
|
Then the exit status should be 0
|
179
179
|
|
180
|
-
Scenario: last command should work properly when in a lolrepo subdirectory
|
180
|
+
Scenario: last command should work properly when in a git lolrepo subdirectory
|
181
181
|
Given I am in a git repo
|
182
182
|
And its loldir has 2 lolimages
|
183
183
|
And a directory named "randomdir"
|
@@ -185,7 +185,7 @@ Feature: Basic UI functionality
|
|
185
185
|
When I run `lolcommits --last`
|
186
186
|
Then the output should not contain:
|
187
187
|
"""
|
188
|
-
|
188
|
+
Unknown VCS
|
189
189
|
"""
|
190
190
|
And the exit status should be 0
|
191
191
|
|
@@ -195,7 +195,7 @@ Feature: Basic UI functionality
|
|
195
195
|
When I run `lolcommits --last`
|
196
196
|
Then the output should contain:
|
197
197
|
"""
|
198
|
-
|
198
|
+
Unknown VCS
|
199
199
|
"""
|
200
200
|
And the exit status should be 1
|
201
201
|
|
@@ -209,13 +209,13 @@ Feature: Basic UI functionality
|
|
209
209
|
"""
|
210
210
|
Then the exit status should be 1
|
211
211
|
|
212
|
-
Scenario: browse command should work properly when in a lolrepo
|
212
|
+
Scenario: browse command should work properly when in a git lolrepo
|
213
213
|
Given I am in a git repo
|
214
214
|
And its loldir has 2 lolimages
|
215
215
|
When I run `lolcommits --browse`
|
216
216
|
Then the exit status should be 0
|
217
217
|
|
218
|
-
Scenario: browse command should work properly when in a lolrepo subdirectory
|
218
|
+
Scenario: browse command should work properly when in a git lolrepo subdirectory
|
219
219
|
Given I am in a git repo
|
220
220
|
And its loldir has 2 lolimages
|
221
221
|
And a directory named "subdir"
|
@@ -223,7 +223,7 @@ Feature: Basic UI functionality
|
|
223
223
|
When I run `lolcommits --browse`
|
224
224
|
Then the output should not contain:
|
225
225
|
"""
|
226
|
-
|
226
|
+
Unknown VCS
|
227
227
|
"""
|
228
228
|
And the exit status should be 0
|
229
229
|
|
@@ -233,11 +233,11 @@ Feature: Basic UI functionality
|
|
233
233
|
When I run `lolcommits --browse`
|
234
234
|
Then the output should contain:
|
235
235
|
"""
|
236
|
-
|
236
|
+
Unknown VCS
|
237
237
|
"""
|
238
238
|
And the exit status should be 1
|
239
239
|
|
240
|
-
Scenario: handle commit messages with quotation marks
|
240
|
+
Scenario: handle git commit messages with quotation marks
|
241
241
|
Given I am in a git repo with lolcommits enabled
|
242
242
|
When I successfully run `git commit --allow-empty -m 'no "air quotes" bae'`
|
243
243
|
Then the exit status should be 0
|
@@ -278,9 +278,101 @@ Feature: Basic UI functionality
|
|
278
278
|
"""
|
279
279
|
And the exit status should be 1
|
280
280
|
|
281
|
-
Scenario: Enable on windows platform setting PATH in post-commit hook
|
281
|
+
Scenario: Enable on windows platform setting PATH in git post-commit hook
|
282
282
|
Given I am using a "win32" platform
|
283
283
|
And I am in a git repo
|
284
284
|
When I successfully run `lolcommits --enable`
|
285
|
-
Then the post-commit hook should contain "set path"
|
285
|
+
Then the git post-commit hook should contain "set path"
|
286
286
|
And the exit status should be 0
|
287
|
+
|
288
|
+
Scenario: Enable in a naked mercurial repo
|
289
|
+
Given I am in a mercurial repo
|
290
|
+
When I successfully run `lolcommits --enable`
|
291
|
+
Then the output should contain "installed lolcommit hook to:"
|
292
|
+
And the lolcommits mercurial post-commit hook should be properly installed
|
293
|
+
And the exit status should be 0
|
294
|
+
|
295
|
+
Scenario: Enable in a mercurial repo that already has a mercurial post-commit hook
|
296
|
+
Given I am in a mercurial repo
|
297
|
+
And a mercurial post-commit hook with "[hooks]\npost-commit.mine = /my/own/script"
|
298
|
+
When I successfully run `lolcommits --enable`
|
299
|
+
Then the output should contain "installed lolcommit hook to:"
|
300
|
+
And the lolcommits mercurial post-commit hook should be properly installed
|
301
|
+
And the mercurial post-commit hook should contain "post-commit.mine = /my/own/script"
|
302
|
+
And the exit status should be 0
|
303
|
+
|
304
|
+
Scenario: Enable in a mercurial repo passing capture arguments
|
305
|
+
Given I am in a mercurial repo
|
306
|
+
When I successfully run `lolcommits --enable -w 5 --fork`
|
307
|
+
Then the mercurial post-commit hook should contain "lolcommits --capture -w 5 --fork"
|
308
|
+
And the exit status should be 0
|
309
|
+
|
310
|
+
Scenario: Disable in a enabled mercurial repo
|
311
|
+
Given I am in a mercurial repo with lolcommits enabled
|
312
|
+
When I successfully run `lolcommits --disable`
|
313
|
+
Then the output should contain "uninstalled"
|
314
|
+
And a file named ".hg/hgrc" should exist
|
315
|
+
And the exit status should be 0
|
316
|
+
|
317
|
+
Scenario: Commiting in an enabled mercurial repo triggers successful capture
|
318
|
+
Given I am in a mercurial repo named "myrepo" with lolcommits enabled
|
319
|
+
When I do a mercurial commit
|
320
|
+
Then the output should contain "*** Preserving this moment in history."
|
321
|
+
And a directory named "~/.lolcommits/myrepo" should exist
|
322
|
+
And a file named "~/.lolcommits/myrepo/tmp_snapshot.jpg" should not exist
|
323
|
+
And there should be exactly 1 jpg in "~/.lolcommits/myrepo"
|
324
|
+
|
325
|
+
Scenario: Commiting in enabled mercurial repo subdirectory triggers successful capture
|
326
|
+
Given I am in a mercurial repo named "testcapture" with lolcommits enabled
|
327
|
+
And a directory named "subdir"
|
328
|
+
And an empty file named "subdir/FOOBAR"
|
329
|
+
When I cd to "subdir/"
|
330
|
+
And I do a mercurial commit
|
331
|
+
Then the output should contain "*** Preserving this moment in history."
|
332
|
+
And a directory named "~/.lolcommits/testcapture" should exist
|
333
|
+
And a directory named "~/.lolcommits/subdir" should not exist
|
334
|
+
And there should be exactly 1 jpg in "~/.lolcommits/testcapture"
|
335
|
+
|
336
|
+
Scenario: last command should work properly when in a mercurial lolrepo
|
337
|
+
Given I am in a mercurial repo
|
338
|
+
And its loldir has 2 lolimages
|
339
|
+
When I run `lolcommits --last`
|
340
|
+
Then the exit status should be 0
|
341
|
+
|
342
|
+
Scenario: last command should work properly when in a mercurial lolrepo subdirectory
|
343
|
+
Given I am in a mercurial repo
|
344
|
+
And its loldir has 2 lolimages
|
345
|
+
And a directory named "randomdir"
|
346
|
+
And I cd to "randomdir"
|
347
|
+
When I run `lolcommits --last`
|
348
|
+
Then the output should not contain:
|
349
|
+
"""
|
350
|
+
Unknown VCS
|
351
|
+
"""
|
352
|
+
And the exit status should be 0
|
353
|
+
|
354
|
+
Scenario: browse command should work properly when in a mercurial lolrepo
|
355
|
+
Given I am in a mercurial repo
|
356
|
+
And its loldir has 2 lolimages
|
357
|
+
When I run `lolcommits --browse`
|
358
|
+
Then the exit status should be 0
|
359
|
+
|
360
|
+
Scenario: browse command should work properly when in a mercurial lolrepo subdirectory
|
361
|
+
Given I am in a mercurial repo
|
362
|
+
And its loldir has 2 lolimages
|
363
|
+
And a directory named "subdir"
|
364
|
+
And I cd to "subdir"
|
365
|
+
When I run `lolcommits --browse`
|
366
|
+
Then the output should not contain:
|
367
|
+
"""
|
368
|
+
Unknown VCS
|
369
|
+
"""
|
370
|
+
And the exit status should be 0
|
371
|
+
|
372
|
+
Scenario: handle mercurial commit messages with quotation marks
|
373
|
+
Given I am in a mercurial repo with lolcommits enabled
|
374
|
+
When I successfully run `touch meh`
|
375
|
+
And I successfully run `hg add meh`
|
376
|
+
And I successfully run `hg commit -m 'no "air quotes" bae'`
|
377
|
+
Then the exit status should be 0
|
378
|
+
And there should be exactly 1 jpg in its loldir
|
@@ -2,12 +2,16 @@
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'aruba/api'
|
4
4
|
|
5
|
-
def
|
5
|
+
def postcommit_hook_git
|
6
6
|
'.git/hooks/post-commit'
|
7
7
|
end
|
8
8
|
|
9
|
+
def postcommit_hook_mercurial
|
10
|
+
'.hg/hgrc'
|
11
|
+
end
|
12
|
+
|
9
13
|
def default_repo
|
10
|
-
'
|
14
|
+
'myrepo'
|
11
15
|
end
|
12
16
|
|
13
17
|
def default_loldir
|
@@ -53,24 +57,77 @@ Given(/^I am in a git repo with lolcommits enabled$/) do
|
|
53
57
|
)
|
54
58
|
end
|
55
59
|
|
56
|
-
Given(/^a post\-commit hook with "(.*?)"$/) do |file_content|
|
60
|
+
Given(/^a git post\-commit hook with "(.*?)"$/) do |file_content|
|
57
61
|
steps %(
|
58
|
-
Given a file named "#{
|
62
|
+
Given a file named "#{postcommit_hook_git}" with:
|
59
63
|
"""
|
60
64
|
#{file_content}
|
61
65
|
"""
|
62
66
|
)
|
63
67
|
end
|
64
68
|
|
65
|
-
Then(/^the lolcommits post\-commit hook should be properly installed$/) do
|
69
|
+
Then(/^the lolcommits git post\-commit hook should be properly installed$/) do
|
70
|
+
steps %(
|
71
|
+
Then the git post-commit hook should contain "lolcommits --capture"
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
Then(/^the git post\-commit hook (should|should not) contain "(.*?)"$/) do |should, content|
|
76
|
+
steps %(
|
77
|
+
Then the file "#{postcommit_hook_git}" #{should} contain "#{content}"
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
Given(/^a mercurial repo named "(.*?)"$/) do |repo_name|
|
82
|
+
steps %(
|
83
|
+
Given I successfully run `hg init "#{repo_name}"`
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
Given(/^I am in a mercurial repo named "(.*?)"$/) do |repo|
|
66
88
|
steps %(
|
67
|
-
|
89
|
+
Given a mercurial repo named "#{repo}"
|
90
|
+
And I cd to "#{repo}"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
Given(/^I am in a mercurial repo$/) do
|
95
|
+
steps %(
|
96
|
+
Given I am in a mercurial repo named "#{default_repo}"
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
Given(/^I am in a mercurial repo named "(.*?)" with lolcommits enabled$/) do |repo|
|
101
|
+
steps %(
|
102
|
+
Given I am in a mercurial repo named "#{repo}"
|
103
|
+
And I successfully run `lolcommits --enable`
|
68
104
|
)
|
69
105
|
end
|
70
106
|
|
71
|
-
|
107
|
+
Given(/^I am in a mercurial repo with lolcommits enabled$/) do
|
72
108
|
steps %(
|
73
|
-
|
109
|
+
Given I am in a mercurial repo named "#{default_repo}" with lolcommits enabled
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
Given(/^a mercurial post\-commit hook with "(.*?)"$/) do |file_content|
|
114
|
+
steps %(
|
115
|
+
Given a file named "#{postcommit_hook_mercurial}" with:
|
116
|
+
"""
|
117
|
+
#{file_content}
|
118
|
+
"""
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
Then(/^the lolcommits mercurial post\-commit hook should be properly installed$/) do
|
123
|
+
steps %(
|
124
|
+
Then the mercurial post-commit hook should contain "lolcommits --capture"
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
Then(/^the mercurial post\-commit hook (should|should not) contain "(.*?)"$/) do |should, content|
|
129
|
+
steps %(
|
130
|
+
Then the file "#{postcommit_hook_mercurial}" #{should} contain "#{content}"
|
74
131
|
)
|
75
132
|
end
|
76
133
|
|
@@ -132,6 +189,31 @@ Then(/^there should be (\d+) commit entries in the git log$/) do |n|
|
|
132
189
|
expect(n.to_i).to eq `git shortlog | grep -E '^[ ]+\w+' | wc -l`.chomp.to_i
|
133
190
|
end
|
134
191
|
|
192
|
+
When(/^I do a mercurial commit with commit message "(.*?)"$/) do |commit_msg|
|
193
|
+
filename = Faker::Lorem.words(1).first
|
194
|
+
steps %(
|
195
|
+
Given a 98 byte file named "#{filename}"
|
196
|
+
And I successfully run `hg add #{filename}`
|
197
|
+
And I successfully run `hg commit -m "#{commit_msg}"`
|
198
|
+
)
|
199
|
+
end
|
200
|
+
|
201
|
+
When(/^I do a mercurial commit$/) do
|
202
|
+
step %(I do a mercurial commit with commit message "#{Faker::Lorem.sentence}")
|
203
|
+
end
|
204
|
+
|
205
|
+
When(/^I do (\d+) mercurial commits$/) do |n|
|
206
|
+
n.to_i.times do
|
207
|
+
step %(I do a mercurial commit)
|
208
|
+
sleep 0.1
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
Then(/^there should be (\d+) commit entries in the mercurial log$/) do |n|
|
213
|
+
sleep 1 # let the file writing catch up
|
214
|
+
expect(n.to_i).to eq `hg log | grep '^changeset:' | wc -l`.chomp.to_i
|
215
|
+
end
|
216
|
+
|
135
217
|
Given(/^I am using a "(.*?)" platform$/) do |host_os_name|
|
136
218
|
set_env 'LOLCOMMITS_FAKE_HOST_OS', host_os_name
|
137
219
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# need to use popen3 on windows - popen4 always eventually calls fork
|
2
|
+
if Lolcommits::Platform.platform_windows?
|
3
|
+
|
4
|
+
module Mercurial
|
5
|
+
class Command
|
6
|
+
private
|
7
|
+
|
8
|
+
def execution_proc
|
9
|
+
proc do
|
10
|
+
debug(command)
|
11
|
+
result = ''
|
12
|
+
error = ''
|
13
|
+
status = nil
|
14
|
+
Open3.popen3(command) do |_stdin, stdout, stderr, wait_thread|
|
15
|
+
Timeout.timeout(timeout) do
|
16
|
+
while (tmp = stdout.read(102_400))
|
17
|
+
result += tmp
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
while (tmp = stderr.read(1024))
|
22
|
+
error += tmp
|
23
|
+
end
|
24
|
+
status = if RUBY_VERSION =~ /^1\.8/
|
25
|
+
error.empty? ? 0 : 1
|
26
|
+
else
|
27
|
+
wait_thread.value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
raise_error_if_needed(status, error)
|
31
|
+
result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# windows command line doesn't like single quotes
|
2
|
+
module Mercurial
|
3
|
+
class Shell
|
4
|
+
def self.interpolate_arguments(cmd_with_args)
|
5
|
+
cmd_with_args.shift.tap do |cmd|
|
6
|
+
cmd.gsub!(/\?/) do
|
7
|
+
if Lolcommits::Platform.platform_windows?
|
8
|
+
"\"#{cmd_with_args.shift}\""
|
9
|
+
else
|
10
|
+
cmd_with_args.shift.to_s.enclose_in_single_quotes
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/lolcommits.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
$LOAD_PATH.unshift File.expand_path('.')
|
3
3
|
|
4
4
|
require 'core_ext/class'
|
5
|
+
require 'core_ext/string'
|
5
6
|
require 'mini_magick'
|
6
7
|
require 'core_ext/mini_magick/utilities'
|
7
8
|
require 'fileutils'
|
@@ -9,15 +10,26 @@ require 'git'
|
|
9
10
|
require 'open3'
|
10
11
|
require 'methadone'
|
11
12
|
require 'date'
|
13
|
+
require 'mercurial-ruby'
|
14
|
+
require 'core_ext/mercurial-ruby/shell'
|
12
15
|
|
13
16
|
require 'lolcommits/version'
|
14
17
|
require 'lolcommits/configuration'
|
15
18
|
require 'lolcommits/capturer'
|
16
|
-
require 'lolcommits/
|
19
|
+
require 'lolcommits/vcs_info'
|
17
20
|
require 'lolcommits/installation'
|
18
21
|
require 'lolcommits/plugin'
|
19
22
|
require 'lolcommits/platform'
|
20
23
|
|
24
|
+
# after lolcommits/platform, so that we can do platform-conditional override
|
25
|
+
require 'core_ext/mercurial-ruby/command'
|
26
|
+
|
27
|
+
# backends
|
28
|
+
require 'lolcommits/backends/installation_git'
|
29
|
+
require 'lolcommits/backends/installation_mercurial'
|
30
|
+
require 'lolcommits/backends/git_info'
|
31
|
+
require 'lolcommits/backends/mercurial_info'
|
32
|
+
|
21
33
|
require 'lolcommits/plugins/loltext'
|
22
34
|
require 'lolcommits/plugins/dot_com'
|
23
35
|
require 'lolcommits/plugins/tranzlate'
|
@@ -1,12 +1,20 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Lolcommits
|
3
|
-
class GitInfo
|
3
|
+
class GitInfo < VCSInfo
|
4
4
|
include Methadone::CLILogging
|
5
5
|
attr_accessor :sha, :message, :repo_internal_path, :repo, :url,
|
6
6
|
:author_name, :author_email, :branch
|
7
7
|
|
8
8
|
GIT_URL_REGEX = %r{.*[:]([\/\w\-]*).git}
|
9
9
|
|
10
|
+
def self.repo_root?(path = '.')
|
11
|
+
File.directory?(File.join(path, '.git'))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.local_name(path = '.')
|
15
|
+
File.basename(Git.open(path).dir.to_s)
|
16
|
+
end
|
17
|
+
|
10
18
|
def initialize
|
11
19
|
debug 'GitInfo: parsed the following values from commit:'
|
12
20
|
debug "GitInfo: \t#{message}"
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Lolcommits
|
3
|
+
#
|
4
|
+
# Methods to handle enabling and disabling of lolcommits
|
5
|
+
#
|
6
|
+
class InstallationGit
|
7
|
+
HOOK_PATH = File.join '.git', 'hooks', 'post-commit'
|
8
|
+
HOOK_DIR = File.join '.git', 'hooks'
|
9
|
+
|
10
|
+
#
|
11
|
+
# IF --ENABLE, DO ENABLE
|
12
|
+
#
|
13
|
+
def self.do_enable
|
14
|
+
unless File.directory?('.git')
|
15
|
+
fatal "You don't appear to be in the base directory of a git project."
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
# its possible a hooks dir doesnt exist, so create it if so
|
20
|
+
Dir.mkdir(HOOK_DIR) unless File.directory?(HOOK_DIR)
|
21
|
+
|
22
|
+
# should add a shebang (or not) adding will rewrite hook file
|
23
|
+
add_shebang = false
|
24
|
+
if hook_file_exists?
|
25
|
+
# clear away any existing lolcommits hook
|
26
|
+
remove_existing_hook! if lolcommits_hook_exists?
|
27
|
+
|
28
|
+
# if file is empty we should add a shebang (and rewrite hook)
|
29
|
+
if File.read(HOOK_PATH).strip.empty?
|
30
|
+
add_shebang = true
|
31
|
+
elsif !good_shebang?
|
32
|
+
# look for good shebang in existing hook, abort if none found
|
33
|
+
warn "the existing hook (at #{HOOK_PATH}) doesn't start with a good shebang; like #!/bin/sh"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
else
|
37
|
+
add_shebang = true
|
38
|
+
end
|
39
|
+
|
40
|
+
File.open(HOOK_PATH, add_shebang ? 'w' : 'a') do |f|
|
41
|
+
f.write("#!/bin/sh\n") if add_shebang
|
42
|
+
f.write(hook_script)
|
43
|
+
end
|
44
|
+
|
45
|
+
FileUtils.chmod 0755, HOOK_PATH
|
46
|
+
HOOK_PATH
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# IF --DISABLE, DO DISABLE
|
51
|
+
#
|
52
|
+
def self.do_disable
|
53
|
+
if lolcommits_hook_exists?
|
54
|
+
remove_existing_hook!
|
55
|
+
info "uninstalled lolcommits hook (from #{HOOK_PATH})"
|
56
|
+
elsif File.exist?(HOOK_PATH)
|
57
|
+
info "couldn't find an lolcommits hook (at #{HOOK_PATH})"
|
58
|
+
if File.read(HOOK_PATH) =~ /lolcommit/
|
59
|
+
info "warning: an older-style lolcommit hook may still exist, edit #{HOOK_PATH} to remove it manually"
|
60
|
+
end
|
61
|
+
else
|
62
|
+
info "no post commit hook found (at #{HOOK_PATH}), so there is nothing to uninstall"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.hook_script
|
67
|
+
ruby_path = Lolcommits::Platform.command_which('ruby', true)
|
68
|
+
imagick_path = Lolcommits::Platform.command_which('identify', true)
|
69
|
+
|
70
|
+
if Lolcommits::Platform.platform_windows?
|
71
|
+
hook_export = "set path \"#{ruby_path};#{imagick_path};%PATH%\"\n"
|
72
|
+
else
|
73
|
+
locale_export = "export LANG=\"#{ENV['LANG']}\"\n"
|
74
|
+
hook_export = "export PATH=\"#{ruby_path}:#{imagick_path}:$PATH\"\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
capture_cmd = 'lolcommits --capture'
|
78
|
+
capture_args = " #{ARGV[1..-1].join(' ')}" if ARGV.length > 1
|
79
|
+
|
80
|
+
<<-EOS
|
81
|
+
### lolcommits hook (begin) ###
|
82
|
+
if [ ! -d "$GIT_DIR/rebase-merge" ]; then
|
83
|
+
#{locale_export}#{hook_export}#{capture_cmd}#{capture_args}
|
84
|
+
fi
|
85
|
+
### lolcommits hook (end) ###
|
86
|
+
EOS
|
87
|
+
end
|
88
|
+
|
89
|
+
# does a git hook exist at all?
|
90
|
+
def self.hook_file_exists?
|
91
|
+
File.exist?(HOOK_PATH)
|
92
|
+
end
|
93
|
+
|
94
|
+
# does a git hook exist with lolcommits commands?
|
95
|
+
def self.lolcommits_hook_exists?
|
96
|
+
hook_file_exists? &&
|
97
|
+
File.read(HOOK_PATH).to_s =~ /lolcommits.*\(begin\)(.*\n)*.*lolcommits.*\(end\)/
|
98
|
+
end
|
99
|
+
|
100
|
+
# does the git hook file have a good shebang?
|
101
|
+
def self.good_shebang?
|
102
|
+
File.read(HOOK_PATH).lines.first =~ %r{^\#\!\/bin\/.*sh}
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.remove_existing_hook!
|
106
|
+
hook = File.read(HOOK_PATH)
|
107
|
+
out = File.open(HOOK_PATH, 'w')
|
108
|
+
skip = false
|
109
|
+
|
110
|
+
hook.lines.each do |line|
|
111
|
+
skip = true if !skip && (line =~ /lolcommits.*\(begin\)/)
|
112
|
+
|
113
|
+
out << line unless skip
|
114
|
+
|
115
|
+
skip = false if skip && (line =~ /lolcommits.*\(end\)/)
|
116
|
+
end
|
117
|
+
|
118
|
+
out.close
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Lolcommits
|
3
|
+
#
|
4
|
+
# Methods to handle enabling and disabling of lolcommits
|
5
|
+
#
|
6
|
+
class InstallationMercurial
|
7
|
+
HOOK_SECTION = 'hooks'.freeze
|
8
|
+
HOOK_OPERATIONS = %w(commit record crecord).freeze
|
9
|
+
|
10
|
+
#
|
11
|
+
# IF --ENABLE, DO ENABLE
|
12
|
+
#
|
13
|
+
def self.do_enable
|
14
|
+
unless File.directory?('.hg')
|
15
|
+
fatal "You don't appear to be in the base directory of a mercurial project."
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
if lolcommits_hook_exists?
|
20
|
+
# clear away any existing lolcommits hook
|
21
|
+
remove_existing_hook!
|
22
|
+
end
|
23
|
+
|
24
|
+
config = repository.config
|
25
|
+
HOOK_OPERATIONS.each do |op|
|
26
|
+
config.add_setting(HOOK_SECTION, "post-#{op}.lolcommits", hook_script)
|
27
|
+
end
|
28
|
+
config.path
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# IF --DISABLE, DO DISABLE
|
33
|
+
#
|
34
|
+
def self.do_disable
|
35
|
+
config = repository.config
|
36
|
+
if lolcommits_hook_exists?
|
37
|
+
remove_existing_hook!
|
38
|
+
info "uninstalled lolcommits hook (from #{config.path})"
|
39
|
+
elsif config.exists?
|
40
|
+
info "couldn't find an lolcommits hook (at #{config.path})"
|
41
|
+
else
|
42
|
+
info "no post commit hook found (at #{config.path}), so there is nothing to uninstall"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.hook_script
|
47
|
+
ruby_path = Lolcommits::Platform.command_which('ruby', true)
|
48
|
+
imagick_path = Lolcommits::Platform.command_which('identify', true)
|
49
|
+
capture_cmd = 'lolcommits --capture'
|
50
|
+
|
51
|
+
if Lolcommits::Platform.platform_windows?
|
52
|
+
capture_cmd = "set path=#{ruby_path};#{imagick_path};%PATH%&&#{capture_cmd}"
|
53
|
+
else
|
54
|
+
locale_export = "LANG=\"#{ENV['LANG']}\""
|
55
|
+
hook_export = "PATH=\"#{ruby_path}:#{imagick_path}:$PATH\""
|
56
|
+
capture_cmd = "#{locale_export} #{hook_export} #{capture_cmd}"
|
57
|
+
end
|
58
|
+
|
59
|
+
capture_args = ARGV[1..-1].join(' ') if ARGV.length > 1
|
60
|
+
"#{capture_cmd} #{capture_args}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.repository
|
64
|
+
Mercurial::Repository.open('.')
|
65
|
+
end
|
66
|
+
|
67
|
+
# does a mercurial hook exist with lolcommits commands?
|
68
|
+
def self.lolcommits_hook_exists?
|
69
|
+
config = repository.config
|
70
|
+
config.exists? && config.setting_exists?(HOOK_SECTION, 'post-commit.lolcommits')
|
71
|
+
end
|
72
|
+
|
73
|
+
# can we load the hgrc?
|
74
|
+
def self.valid_hgrc?
|
75
|
+
repository.config.exists?
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.remove_existing_hook!
|
79
|
+
config = repository.config
|
80
|
+
HOOK_OPERATIONS.each do |op|
|
81
|
+
setting = "post-#{op}.lolcommits"
|
82
|
+
if config.setting_exists?(HOOK_SECTION, setting)
|
83
|
+
config.delete_setting!(HOOK_SECTION, setting)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Lolcommits
|
3
|
+
class MercurialInfo < VCSInfo
|
4
|
+
include Methadone::CLILogging
|
5
|
+
attr_accessor :sha, :message, :repo_internal_path, :repo, :url,
|
6
|
+
:author_name, :author_email, :branch
|
7
|
+
|
8
|
+
def self.repo_root?(path = '.')
|
9
|
+
File.directory?(File.join(path, '.hg'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.local_name(path = '.')
|
13
|
+
File.basename(File.dirname(Mercurial::Repository.open(path).dothg_path))
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
# mercurial sets HG_RESULT for post- hooks
|
18
|
+
if ENV.key?('HG_RESULT') && ENV['HG_RESULT'] != '0'
|
19
|
+
debug 'Aborting lolcommits hook from failed operation'
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
Mercurial.configure do |conf|
|
24
|
+
conf.hg_binary_path = 'hg'
|
25
|
+
end
|
26
|
+
debug 'MercurialInfo: parsed the following values from commit:'
|
27
|
+
debug "MercurialInfo: \t#{message}"
|
28
|
+
debug "MercurialInfo: \t#{sha}"
|
29
|
+
debug "MercurialInfo: \t#{repo_internal_path}"
|
30
|
+
debug "MercurialInfo: \t#{repo}"
|
31
|
+
debug "MercurialInfo: \t#{branch}"
|
32
|
+
debug "MercurialInfo: \t#{author_name}" if author_name
|
33
|
+
debug "MercurialInfo: \t#{author_email}" if author_email
|
34
|
+
end
|
35
|
+
|
36
|
+
def branch
|
37
|
+
@branch ||= last_commit.branch_name
|
38
|
+
end
|
39
|
+
|
40
|
+
def message
|
41
|
+
@message ||= begin
|
42
|
+
message = last_commit.message || ''
|
43
|
+
message.split("\n").first
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def sha
|
48
|
+
@sha ||= last_commit.id[0..10]
|
49
|
+
end
|
50
|
+
|
51
|
+
def repo_internal_path
|
52
|
+
@repo_internal_path ||= repository.dothg_path
|
53
|
+
end
|
54
|
+
|
55
|
+
def url
|
56
|
+
@url ||= repository.path
|
57
|
+
end
|
58
|
+
|
59
|
+
def repo
|
60
|
+
@repo ||= File.basename(File.dirname(repo_internal_path))
|
61
|
+
end
|
62
|
+
|
63
|
+
def author_name
|
64
|
+
@author_name ||= last_commit.author
|
65
|
+
end
|
66
|
+
|
67
|
+
def author_email
|
68
|
+
@author_email ||= last_commit.author_email
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def repository(path = '.')
|
74
|
+
@repository ||= Mercurial::Repository.open(path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def last_commit
|
78
|
+
@commit ||= repository.commits.parent
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -64,12 +64,16 @@ module Lolcommits
|
|
64
64
|
|
65
65
|
# If we are not in a git repo, we can't do git related things!
|
66
66
|
# Die with an informative error message in that case.
|
67
|
-
def self.
|
68
|
-
debug 'Checking for valid
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
def self.die_if_not_vcs_repo!
|
68
|
+
debug 'Checking for valid vcs repo'
|
69
|
+
current = File.expand_path('.')
|
70
|
+
parent = File.dirname(current)
|
71
|
+
while current != parent
|
72
|
+
return if VCSInfo.repo_root?(current)
|
73
|
+
current = parent
|
74
|
+
parent = File.dirname(current)
|
75
|
+
end
|
76
|
+
fatal 'Unknown VCS'
|
73
77
|
exit 1
|
74
78
|
end
|
75
79
|
end
|
@@ -15,7 +15,7 @@ module Lolcommits
|
|
15
15
|
# Runs the history timeline animator task thingy
|
16
16
|
# param args [String] the arg passed to the gif command on CLI (optional)
|
17
17
|
def run(args = nil)
|
18
|
-
Fatals.
|
18
|
+
Fatals.die_if_not_vcs_repo!
|
19
19
|
|
20
20
|
case args
|
21
21
|
when 'today'
|
@@ -23,7 +23,12 @@ module Lolcommits
|
|
23
23
|
|
24
24
|
def loldir
|
25
25
|
return @loldir if @loldir
|
26
|
-
basename ||=
|
26
|
+
basename ||= if VCSInfo.repo_root?
|
27
|
+
VCSInfo.local_name
|
28
|
+
else
|
29
|
+
File.basename(Dir.getwd)
|
30
|
+
end
|
31
|
+
basename.sub!(/^\./, 'dot')
|
27
32
|
basename.sub!(/ /, '-')
|
28
33
|
@loldir = Configuration.loldir_for(basename)
|
29
34
|
end
|
@@ -4,48 +4,25 @@ module Lolcommits
|
|
4
4
|
# Methods to handle enabling and disabling of lolcommits
|
5
5
|
#
|
6
6
|
class Installation
|
7
|
-
|
8
|
-
|
7
|
+
def self.backend
|
8
|
+
if GitInfo.repo_root?
|
9
|
+
InstallationGit
|
10
|
+
elsif MercurialInfo.repo_root?
|
11
|
+
InstallationMercurial
|
12
|
+
else
|
13
|
+
fatal "You don't appear to be in the base directory of a supported vcs project."
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
end
|
9
17
|
|
10
18
|
#
|
11
19
|
# IF --ENABLE, DO ENABLE
|
12
20
|
#
|
13
21
|
def self.do_enable
|
14
|
-
|
15
|
-
fatal "You don't appear to be in the base directory of a git project."
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
|
19
|
-
# its possible a hooks dir doesnt exist, so create it if so
|
20
|
-
Dir.mkdir(HOOK_DIR) unless File.directory?(HOOK_DIR)
|
21
|
-
|
22
|
-
# should add a shebang (or not) adding will rewrite hook file
|
23
|
-
add_shebang = false
|
24
|
-
if hook_file_exists?
|
25
|
-
# clear away any existing lolcommits hook
|
26
|
-
remove_existing_hook! if lolcommits_hook_exists?
|
27
|
-
|
28
|
-
# if file is empty we should add a shebang (and rewrite hook)
|
29
|
-
if File.read(HOOK_PATH).strip.empty?
|
30
|
-
add_shebang = true
|
31
|
-
elsif !good_shebang?
|
32
|
-
# look for good shebang in existing hook, abort if none found
|
33
|
-
warn "the existing hook (at #{HOOK_PATH}) doesn't start with a good shebang; like #!/bin/sh"
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
else
|
37
|
-
add_shebang = true
|
38
|
-
end
|
39
|
-
|
40
|
-
File.open(HOOK_PATH, add_shebang ? 'w' : 'a') do |f|
|
41
|
-
f.write("#!/bin/sh\n") if add_shebang
|
42
|
-
f.write(hook_script)
|
43
|
-
end
|
44
|
-
|
45
|
-
FileUtils.chmod 0755, HOOK_PATH
|
22
|
+
path = backend.do_enable
|
46
23
|
|
47
24
|
info 'installed lolcommit hook to:'
|
48
|
-
info " -> #{File.expand_path(
|
25
|
+
info " -> #{File.expand_path(path)}"
|
49
26
|
info '(to remove later, you can use: lolcommits --disable)'
|
50
27
|
# we dont symlink, but rather install a small stub that calls the one from path
|
51
28
|
# that way, as gem version changes, script updates even if new file thus breaking symlink
|
@@ -55,72 +32,7 @@ module Lolcommits
|
|
55
32
|
# IF --DISABLE, DO DISABLE
|
56
33
|
#
|
57
34
|
def self.do_disable
|
58
|
-
|
59
|
-
remove_existing_hook!
|
60
|
-
info "uninstalled lolcommits hook (from #{HOOK_PATH})"
|
61
|
-
elsif File.exist?(HOOK_PATH)
|
62
|
-
info "couldn't find an lolcommits hook (at #{HOOK_PATH})"
|
63
|
-
if File.read(HOOK_PATH) =~ /lolcommit/
|
64
|
-
info "warning: an older-style lolcommit hook may still exist, edit #{HOOK_PATH} to remove it manually"
|
65
|
-
end
|
66
|
-
else
|
67
|
-
info "no post commit hook found (at #{HOOK_PATH}), so there is nothing to uninstall"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.hook_script
|
72
|
-
ruby_path = Lolcommits::Platform.command_which('ruby', true)
|
73
|
-
imagick_path = Lolcommits::Platform.command_which('identify', true)
|
74
|
-
|
75
|
-
if Lolcommits::Platform.platform_windows?
|
76
|
-
hook_export = "set path \"#{ruby_path};#{imagick_path};%PATH%\"\n"
|
77
|
-
else
|
78
|
-
locale_export = "export LANG=\"#{ENV['LANG']}\"\n"
|
79
|
-
hook_export = "export PATH=\"#{ruby_path}:#{imagick_path}:$PATH\"\n"
|
80
|
-
end
|
81
|
-
|
82
|
-
capture_cmd = 'lolcommits --capture'
|
83
|
-
capture_args = " #{ARGV[1..-1].join(' ')}" if ARGV.length > 1
|
84
|
-
|
85
|
-
<<-EOS
|
86
|
-
### lolcommits hook (begin) ###
|
87
|
-
if [ ! -d "$GIT_DIR/rebase-merge" ]; then
|
88
|
-
#{locale_export}#{hook_export}#{capture_cmd}#{capture_args}
|
89
|
-
fi
|
90
|
-
### lolcommits hook (end) ###
|
91
|
-
EOS
|
92
|
-
end
|
93
|
-
|
94
|
-
# does a git hook exist at all?
|
95
|
-
def self.hook_file_exists?
|
96
|
-
File.exist?(HOOK_PATH)
|
97
|
-
end
|
98
|
-
|
99
|
-
# does a git hook exist with lolcommits commands?
|
100
|
-
def self.lolcommits_hook_exists?
|
101
|
-
hook_file_exists? &&
|
102
|
-
File.read(HOOK_PATH).to_s =~ /lolcommits.*\(begin\)(.*\n)*.*lolcommits.*\(end\)/
|
103
|
-
end
|
104
|
-
|
105
|
-
# does the git hook file have a good shebang?
|
106
|
-
def self.good_shebang?
|
107
|
-
File.read(HOOK_PATH).lines.first =~ %r{^\#\!\/bin\/.*sh}
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.remove_existing_hook!
|
111
|
-
hook = File.read(HOOK_PATH)
|
112
|
-
out = File.open(HOOK_PATH, 'w')
|
113
|
-
skip = false
|
114
|
-
|
115
|
-
hook.lines.each do |line|
|
116
|
-
skip = true if !skip && (line =~ /lolcommits.*\(begin\)/)
|
117
|
-
|
118
|
-
out << line unless skip
|
119
|
-
|
120
|
-
skip = false if skip && (line =~ /lolcommits.*\(end\)/)
|
121
|
-
end
|
122
|
-
|
123
|
-
out.close
|
35
|
+
backend.do_disable
|
124
36
|
end
|
125
37
|
end
|
126
38
|
end
|
@@ -27,7 +27,7 @@ module Lolcommits
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def message
|
30
|
-
"commited some #{random_adjective} #{random_object} to #{runner.
|
30
|
+
"commited some #{random_adjective} #{random_object} to #{runner.vcs_info.repo}@#{runner.sha} (#{runner.vcs_info.branch}) "
|
31
31
|
end
|
32
32
|
|
33
33
|
def random_object
|
@@ -52,7 +52,7 @@ module Lolcommits
|
|
52
52
|
:token => configuration['access_token'],
|
53
53
|
:filetype => 'jpg',
|
54
54
|
:filename => runner.sha,
|
55
|
-
:title => runner.message + "[#{runner.
|
55
|
+
:title => runner.message + "[#{runner.vcs_info.repo}]",
|
56
56
|
:channels => configuration['channels'])
|
57
57
|
|
58
58
|
debug response
|
@@ -40,8 +40,8 @@ module Lolcommits
|
|
40
40
|
def upload(file, sha)
|
41
41
|
RestClient.post(configuration['server'] + '/uplol',
|
42
42
|
:lol => File.new(file),
|
43
|
-
:url => runner.
|
44
|
-
:repo => runner.
|
43
|
+
:url => runner.vcs_info.url + sha,
|
44
|
+
:repo => runner.vcs_info.repo,
|
45
45
|
:date => File.ctime(file),
|
46
46
|
:sha => sha)
|
47
47
|
rescue => e
|
@@ -21,7 +21,7 @@ module Lolcommits
|
|
21
21
|
def run_postcapture
|
22
22
|
return unless valid_configuration?
|
23
23
|
|
24
|
-
if runner.
|
24
|
+
if runner.vcs_info.repo.empty?
|
25
25
|
puts 'Repo is empty, skipping upload'
|
26
26
|
else
|
27
27
|
debug "Posting capture to #{configuration['endpoint']}"
|
@@ -29,9 +29,9 @@ module Lolcommits
|
|
29
29
|
{
|
30
30
|
:file => File.new(runner.main_image),
|
31
31
|
:message => runner.message,
|
32
|
-
:repo => runner.
|
33
|
-
:author_name => runner.
|
34
|
-
:author_email => runner.
|
32
|
+
:repo => runner.vcs_info.repo,
|
33
|
+
:author_name => runner.vcs_info.author_name,
|
34
|
+
:author_email => runner.vcs_info.author_email,
|
35
35
|
:sha => runner.sha,
|
36
36
|
:key => configuration['optional_key']
|
37
37
|
},
|
data/lib/lolcommits/runner.rb
CHANGED
@@ -4,7 +4,7 @@ require 'lolcommits/platform'
|
|
4
4
|
module Lolcommits
|
5
5
|
class Runner
|
6
6
|
attr_accessor :capture_delay, :capture_stealth, :capture_device, :message,
|
7
|
-
:sha, :snapshot_loc, :main_image, :config, :
|
7
|
+
:sha, :snapshot_loc, :main_image, :config, :vcs_info,
|
8
8
|
:capture_animate
|
9
9
|
|
10
10
|
include Methadone::CLILogging
|
@@ -15,9 +15,16 @@ module Lolcommits
|
|
15
15
|
end
|
16
16
|
|
17
17
|
return unless sha.nil? || message.nil?
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if GitInfo.repo_root?
|
19
|
+
self.vcs_info = GitInfo.new
|
20
|
+
elsif MercurialInfo.repo_root?
|
21
|
+
self.vcs_info = MercurialInfo.new
|
22
|
+
else
|
23
|
+
raise('Unknown VCS')
|
24
|
+
end
|
25
|
+
|
26
|
+
self.sha = vcs_info.sha if sha.nil?
|
27
|
+
self.message = vcs_info.message if message.nil?
|
21
28
|
end
|
22
29
|
|
23
30
|
# wrap run to handle things that should happen before and after
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Lolcommits
|
3
|
+
# base class ala plugin.rb
|
4
|
+
class VCSInfo
|
5
|
+
include Methadone::CLILogging
|
6
|
+
attr_accessor :sha, :message, :repo_internal_path, :repo, :url,
|
7
|
+
:author_name, :author_email, :branch
|
8
|
+
|
9
|
+
def self.repo_root?(path = '.')
|
10
|
+
GitInfo.repo_root?(path) || MercurialInfo.repo_root?(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.base_message(method)
|
14
|
+
raise NotImplementedError, "#{self.class.name} is a base class; implement '#{method}' in a subclass", caller
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.local_name(path = '.')
|
18
|
+
if GitInfo.repo_root?(path)
|
19
|
+
GitInfo.local_name(path)
|
20
|
+
elsif MercurialInfo.repo_root?(path)
|
21
|
+
MercurialInfo.local_name(path)
|
22
|
+
else
|
23
|
+
raise "'#{File.expand_path(path)}' is not the root of a supported VCS"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
base_message(__method__)
|
29
|
+
end
|
30
|
+
|
31
|
+
def branch
|
32
|
+
base_message(__method__)
|
33
|
+
end
|
34
|
+
|
35
|
+
def message
|
36
|
+
base_message(__method__)
|
37
|
+
end
|
38
|
+
|
39
|
+
def sha
|
40
|
+
base_message(__method__)
|
41
|
+
end
|
42
|
+
|
43
|
+
def repo_internal_path
|
44
|
+
base_message(__method__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def url
|
48
|
+
base_message(__method__)
|
49
|
+
end
|
50
|
+
|
51
|
+
def repo
|
52
|
+
base_message(__method__)
|
53
|
+
end
|
54
|
+
|
55
|
+
def author_name
|
56
|
+
base_message(__method__)
|
57
|
+
end
|
58
|
+
|
59
|
+
def author_email
|
60
|
+
base_message(__method__)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/lolcommits/version.rb
CHANGED
data/lolcommits.gemspec
CHANGED
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.add_runtime_dependency('launchy', '~> 2.4.3')
|
43
43
|
s.add_runtime_dependency('methadone', '~> 1.8.0')
|
44
44
|
s.add_runtime_dependency('open4', '~> 1.3.4')
|
45
|
+
s.add_runtime_dependency('mercurial-ruby', '~> 0')
|
45
46
|
|
46
47
|
# plugin gems
|
47
48
|
s.add_runtime_dependency('twitter', '~> 5.13.0') # twitter
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolcommits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Rothenberg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -179,6 +179,20 @@ dependencies:
|
|
179
179
|
- - ~>
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: 1.3.4
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: mercurial-ruby
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ~>
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
type: :runtime
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ~>
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
182
196
|
- !ruby/object:Gem::Dependency
|
183
197
|
name: twitter
|
184
198
|
requirement: !ruby/object:Gem::Requirement
|
@@ -423,8 +437,15 @@ files:
|
|
423
437
|
- features/support/env.rb
|
424
438
|
- features/support/path_helpers.rb
|
425
439
|
- lib/core_ext/class.rb
|
440
|
+
- lib/core_ext/mercurial-ruby/command.rb
|
441
|
+
- lib/core_ext/mercurial-ruby/shell.rb
|
426
442
|
- lib/core_ext/mini_magick/utilities.rb
|
443
|
+
- lib/core_ext/string.rb
|
427
444
|
- lib/lolcommits.rb
|
445
|
+
- lib/lolcommits/backends/git_info.rb
|
446
|
+
- lib/lolcommits/backends/installation_git.rb
|
447
|
+
- lib/lolcommits/backends/installation_mercurial.rb
|
448
|
+
- lib/lolcommits/backends/mercurial_info.rb
|
428
449
|
- lib/lolcommits/capturer.rb
|
429
450
|
- lib/lolcommits/capturer/capture_cygwin.rb
|
430
451
|
- lib/lolcommits/capturer/capture_fake.rb
|
@@ -438,7 +459,6 @@ files:
|
|
438
459
|
- lib/lolcommits/cli/process_runner.rb
|
439
460
|
- lib/lolcommits/cli/timelapse_gif.rb
|
440
461
|
- lib/lolcommits/configuration.rb
|
441
|
-
- lib/lolcommits/git_info.rb
|
442
462
|
- lib/lolcommits/installation.rb
|
443
463
|
- lib/lolcommits/platform.rb
|
444
464
|
- lib/lolcommits/plugin.rb
|
@@ -453,6 +473,7 @@ files:
|
|
453
473
|
- lib/lolcommits/plugins/tranzlate.rb
|
454
474
|
- lib/lolcommits/plugins/uploldz.rb
|
455
475
|
- lib/lolcommits/runner.rb
|
476
|
+
- lib/lolcommits/vcs_info.rb
|
456
477
|
- lib/lolcommits/version.rb
|
457
478
|
- lolcommits.gemspec
|
458
479
|
- test/images/test_image.jpg
|