autocommit 0.1.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f59c1b5a458d6ebba8b6a3d6220471ab519df10
4
+ data.tar.gz: e21217309eb883b068867360888dd10a0fa59a0d
5
+ SHA512:
6
+ metadata.gz: 396411898427fe1dd1844cb965c7f0521c7c6cb2bc9b74236aef7a2444b1331b2602628753e5a4bf45515b95ecb53a12fc67c2cb641a0e05e5474920ec13bbb6
7
+ data.tar.gz: 323d1824abd1a5e217286c536f2eed0238b00624729f2bf9ac44cfb2a843337ed6ba6de7f3243057af8a252c48fb912cbe2e8bfdafdaadd8db7a4fb55c2aa97e
@@ -0,0 +1,2 @@
1
+ �iK���`�߷`&k��"A�M�g����i���*�C[��W�0��PEM�;5���Y�Ug�')
2
+ �g.BD? ��Ě�;�N��f�`��Z*��?������"�#��eR��G���X� �y��2'�jsC-M�m6�<B.��%�*�P�R�2v�h�Z'�<N0�S4������lX�0�C����H6�n�FD χ�
@@ -0,0 +1,4 @@
1
+ ��m�"�;K��0
2
+ ��W?�~�Xצ�@/NnN
3
+ ��Rk�Zs�����J�Q�k��l14�{�����d̓lk �*l^4\�ȧ�K�"V��^lA�}�v� >z��PԞO�`�&T�]�썏�����7�����W��3���P�n
4
+ )HhI2�1�S���T�cs��h۸’0_c��Kq�B��O0��GP$�hV��C:K_@ ���x:E�}����ђF��#�z�N�8��F�V�m�4����}��
@@ -0,0 +1,11 @@
1
+ Autotest.add_hook(:initialize) {|at|
2
+ at.add_exception(/\.git/)
3
+ at.add_exception(/coverage/)
4
+ at.add_exception(/wiki/)
5
+ at.add_exception(/gemspec/)
6
+ at.add_exception(/autocommit-.*.gem/)
7
+
8
+ at.add_mapping %r{spec/helpers/.*rb} do |f, _|
9
+ Dir["spec/autocommit/**/*.rb"]
10
+ end
11
+ }
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r helpers/simplecov
3
+ -r helpers/file_manipulation
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'kero/project'
3
+
4
+ prepend_repo_directories_to_paths
5
+
6
+ task :test => ["spec"]
7
+
8
+ RSpec::Core::RakeTask.new('spec')
9
+
10
+ Project::Rake::GemTask.new :gem
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'autocommit/git_committer'
4
+ require 'autocommit/gatherer'
5
+
6
+ dir = ARGV[0] || "."
7
+
8
+ committer = AutoCommit::GitCommitter.new dir
9
+ AutoCommit::Gatherer.new dir, committer
10
+
11
+ gets
@@ -0,0 +1,18 @@
1
+ require 'rb-inotify'
2
+
3
+ module AutoCommit
4
+ class Detector
5
+ def initialize dir, &block
6
+ @notifier = INotify::Notifier.new
7
+ @notifier.watch dir, :create, :modify, :delete, :moved_to, :moved_from, :recursive, &block
8
+ @t = Thread.new {
9
+ @notifier.run
10
+ }
11
+ end
12
+
13
+ def stop
14
+ @t.kill
15
+ @t.join
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ require 'autocommit/detector'
2
+ require 'thread'
3
+
4
+ Thread.abort_on_exception = true
5
+
6
+ module AutoCommit
7
+ class Gatherer
8
+ Delay = 0.25 # seconds
9
+
10
+ def initialize dir, committer
11
+ @dir = dir
12
+ @committer = committer
13
+ @mutex = Mutex.new
14
+ @list = []
15
+ Detector.new dir do |event|
16
+ trigger_commit event.absolute_name
17
+ end
18
+ end
19
+
20
+ def trigger_commit full_name
21
+ in_git_repo = full_name.start_with? File.join(@dir, ".git")
22
+ return if in_git_repo
23
+ @mutex.synchronize {
24
+ start_thread if @list.empty?
25
+ @list << Time.now
26
+ }
27
+ end
28
+
29
+ def start_thread
30
+ Thread.new {
31
+ delayed_commit
32
+ }
33
+ end
34
+
35
+ def delayed_commit
36
+ sleep Delay
37
+ commit
38
+ end
39
+
40
+ def commit
41
+ @mutex.synchronize {
42
+ @list.clear
43
+ # Prevent the next commit (>=0.25 seconds later, but still)
44
+ # from interfering with this one:
45
+ # commit from within the synchronized block
46
+ @committer.commit
47
+ }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module AutoCommit
2
+ class GitCommitter
3
+ def initialize dir
4
+ @dir = dir
5
+ end
6
+
7
+ def commit
8
+ puts `(cd #{@dir} && git add * '.[^.]*' && git commit -a -m 'automated commit')`
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,134 @@
1
+ require 'autocommit/detector'
2
+
3
+ describe "Detecting File Changes" do
4
+ def create_detector
5
+ `sync` # prevent setup from interfering with rb-inotify
6
+ @detector = AutoCommit::Detector.new TmpDir do |event|
7
+ path = event.absolute_name
8
+ path.slice! TmpDir
9
+ @changed << [path, event.flags]
10
+ end
11
+ # two tricks to let the Notifier really run
12
+ Thread.pass
13
+ sleep 0.001
14
+ end
15
+
16
+ before :each do
17
+ @changed = []
18
+ end
19
+
20
+ after :each do
21
+ @detector.stop
22
+ end
23
+
24
+ describe "Creation" do
25
+ before :each do
26
+ create_detector
27
+ end
28
+
29
+ it "of One file" do
30
+ create "bla.txt"
31
+ check ["bla.txt", [:create]]
32
+ end
33
+
34
+ it "of Two files" do
35
+ create "one", "two"
36
+ check ["one", [:create]], ["two", [:create]]
37
+ end
38
+
39
+ it "of a Directory" do
40
+ mkdir "sub"
41
+ check ["sub", [:create, :isdir]]
42
+ end
43
+ end
44
+
45
+ it "Deletion of a file" do
46
+ create "bla.txt"
47
+ create_detector
48
+ remove "bla.txt"
49
+ check ["bla.txt", [:delete]]
50
+ end
51
+
52
+ it "Rename of a file" do
53
+ create "bla.txt"
54
+ create_detector
55
+ move("bla.txt").to "real.rb"
56
+ check ["bla.txt", [:moved_from, :move]], ["real.rb", [:moved_to, :move]]
57
+ end
58
+
59
+ it "Modification of a file" do
60
+ create "bla.txt"
61
+ create_detector
62
+ modify "bla.txt"
63
+ check ["bla.txt", [:modify]]
64
+ end
65
+
66
+ describe "in a Sub-directory" do
67
+ before :each do
68
+ mkdir "sub"
69
+ end
70
+
71
+ it "Creation of a file" do
72
+ create_detector
73
+ create "sub/bla.txt"
74
+ check ["sub/bla.txt", [:create]]
75
+ end
76
+
77
+ it "Creation of a directory" do
78
+ create_detector
79
+ mkdir "sub/dir"
80
+ check ["sub/dir", [:create, :isdir]]
81
+ end
82
+
83
+ it "Modification of a file" do
84
+ create "sub/bla.txt"
85
+ modify "sub/bla.txt" # just for fun
86
+ create_detector
87
+ modify "sub/bla.txt"
88
+ check ["sub/bla.txt", [:modify]]
89
+ end
90
+
91
+ it "Removal of a file" do
92
+ create "sub/bla.txt"
93
+ create_detector
94
+ remove "sub/bla.txt"
95
+ check ["sub/bla.txt", [:delete]]
96
+ end
97
+
98
+ it "Move a file out of the directory" do
99
+ create "sub/bla.txt"
100
+ create_detector
101
+ move("sub/bla.txt").to "real.rb"
102
+ check ["sub/bla.txt", [:moved_from, :move]], ["real.rb", [:moved_to, :move]]
103
+ end
104
+
105
+ it "Move a file into the directory" do
106
+ create "bla.txt"
107
+ create_detector
108
+ move("bla.txt").to "sub/real.rb"
109
+ check ["bla.txt", [:moved_from, :move]], ["sub/real.rb", [:moved_to, :move]]
110
+ end
111
+ end
112
+
113
+ describe "in a New Sub-directory" do
114
+ before :each do
115
+ create_detector
116
+ mkdir "sub"
117
+ end
118
+
119
+ # This is a race, by the nature of inotify
120
+ it "Creation of a file" do
121
+ sleep 0.025 # give rb-inotify time to create a watcher on the dir
122
+ create "sub/bla.txt"
123
+ check ["sub", [:create, :isdir]], ["sub/bla.txt", [:create]]
124
+ end
125
+ end
126
+
127
+ def check *events
128
+ 10.times do
129
+ break if @changed == events
130
+ sleep 0.05
131
+ end
132
+ expect(@changed).to eq events
133
+ end
134
+ end
@@ -0,0 +1,50 @@
1
+ require 'autocommit/gatherer'
2
+ require 'autocommit/git_committer'
3
+
4
+ module AutoCommit
5
+ describe Gatherer do
6
+ Epsilon = Gatherer::Delay * 0.2
7
+
8
+ before :each do
9
+ @committer = double GitCommitter
10
+ @gatherer = Gatherer.new TmpDir, @committer
11
+ end
12
+
13
+ it "Triggers a delayed commit" do
14
+ @gatherer.trigger_commit "f"
15
+ sleep Gatherer::Delay - Epsilon
16
+ expect(@committer).to receive :commit
17
+ sleep 2 * Epsilon
18
+ end
19
+
20
+ it "Triggers twice with a large delay" do
21
+ expect(@committer).to receive(:commit).twice
22
+ @gatherer.trigger_commit "f"
23
+ sleep Gatherer::Delay + Epsilon
24
+ @gatherer.trigger_commit "g"
25
+ sleep Gatherer::Delay + Epsilon
26
+ end
27
+
28
+ it "Triggers once with a small delay" do
29
+ expect(@committer).to receive(:commit)
30
+ @gatherer.trigger_commit "f"
31
+ sleep 0.4 * Gatherer::Delay
32
+ @gatherer.trigger_commit "g"
33
+ sleep Gatherer::Delay + Epsilon
34
+ end
35
+
36
+ it "Triggers twice with a nice series of events" do
37
+ expect(@committer).to receive(:commit).twice
38
+ 4.times {
39
+ @gatherer.trigger_commit "f"
40
+ sleep 0.4 * Gatherer::Delay
41
+ }
42
+ sleep 0.8 * Gatherer::Delay + Epsilon
43
+ end
44
+
45
+ it "Does not trigger on a Git file" do
46
+ @gatherer.trigger_commit File.join(TmpDir, ".git/index")
47
+ sleep Gatherer::Delay + Epsilon
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,60 @@
1
+ require 'fileutils'
2
+
3
+ TmpDir = "/tmp/autocommit_#{$$}_#{rand 32768}_#{Time.now.to_i}/"
4
+
5
+ def create *files
6
+ files.each {|file|
7
+ File.open tmp(file), "w" do
8
+ end
9
+ }
10
+ end
11
+
12
+ def remove *files
13
+ files.each {|file|
14
+ File.delete tmp(file)
15
+ }
16
+ end
17
+
18
+ class Move
19
+ def initialize file
20
+ @file = file
21
+ end
22
+ def to dest
23
+ File.rename tmp(@file), tmp(dest)
24
+ end
25
+ end
26
+
27
+ def move *files
28
+ Move.new *files
29
+ end
30
+
31
+ def modify file
32
+ File.open tmp(file), "r+" do |f|
33
+ f.puts "Some random garbage #{rand 1234567890}"
34
+ end
35
+ end
36
+
37
+ def mkdir *dirs
38
+ dirs.each do |dir|
39
+ FileUtils.mkpath tmp(dir)
40
+ end
41
+ end
42
+
43
+ def tmp file
44
+ File.join TmpDir, file
45
+ end
46
+
47
+ RSpec.configure do |config|
48
+ config.before :each do
49
+ wipe_tmp_dir
50
+ Dir.mkdir TmpDir
51
+ end
52
+
53
+ config.after :each do
54
+ wipe_tmp_dir
55
+ end
56
+ end
57
+
58
+ def wipe_tmp_dir
59
+ FileUtils.rm_rf TmpDir
60
+ end
@@ -0,0 +1,8 @@
1
+ begin
2
+ require 'simplecov'
3
+ rescue LoadError
4
+ else
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ 0.1.2
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autocommit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Kero van Gelder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQUFADA8MQ0wCwYDVQQDDARrZXJv
14
+ MRYwFAYKCZImiZPyLGQBGRYGY2htZWVlMRMwEQYKCZImiZPyLGQBGRYDb3JnMB4X
15
+ DTE0MDUyNjEzMDA0NFoXDTE1MDUyNjEzMDA0NFowPDENMAsGA1UEAwwEa2VybzEW
16
+ MBQGCgmSJomT8ixkARkWBmNobWVlZTETMBEGCgmSJomT8ixkARkWA29yZzCCASIw
17
+ DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANWKyro55FOjGEF8OX5c08+gpMuR
18
+ wD6iDJ8Fs0Vwq4on7ttl/EgK+shIKQd1rN3Lmn50mA8d1oGWt37S0aiI7ftaqyXJ
19
+ +HL0Q+CaNKd0W9LFmVP1gCR7deIhXxxte2UkbgKjyR2kkxwEsRWSPXbAhZ0pZFq4
20
+ pmXjGavEwohU8eWEIXuWMmwQqWjmgvXDqCac6NEiT1A2RingYAiQRYoCSAP3yBIh
21
+ bBqf7QScRs4uiz7CdjKRKUfzWORUa00cpjHqtkkArAaS1R7UsIDrYMxE5yFpzsJP
22
+ fcyVORIKMkUVvTZFJm8+/aROlh6Yd5+dOZETYc+2+o3cjjdSKIIRTOhHPucCAwEA
23
+ AaNxMG8wCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFHqMQYP9eqdc
24
+ hvzhiVV3LM1DIYMAMBoGA1UdEQQTMBGBD2tlcm9AY2htZWVlLm9yZzAaBgNVHRIE
25
+ EzARgQ9rZXJvQGNobWVlZS5vcmcwDQYJKoZIhvcNAQEFBQADggEBADBFNSZBIuRy
26
+ USCX8gpY1hD+gIdG3b+7Nhk/L69cfLt0OFtc0jbfiI6aMzsHayAxy9+bTwXUMw76
27
+ XauvI70WhLdeQ1YDFbTC629JbH76nTKB35OsKFSXYB1Re8DdE8u3ualdO3SHVFA1
28
+ ZPK55V7iiKbN2L931wgSAJ8lRRy0n608j/PiEHUALyjH3VjJR3BAfpY8nbveszqn
29
+ vjUpGeCZqWkTAtUyzY6knKFOls68K2pS0dV9mcJKbAZz4AV9BEkMvS1yWgT7Cu8D
30
+ oHRHyhmiw1SBqAv2jEOUrsFBW/tBY1FAoqog9EBifetKUoawT0Omv2WGmeKI4r2R
31
+ xWkTnkWuoKU=
32
+ -----END CERTIFICATE-----
33
+ date: 2014-05-26 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rb-inotify
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.0.0
63
+ - !ruby/object:Gem::Dependency
64
+ name: kero
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.15.4
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.15.4
77
+ description: |
78
+ watch a directory for changes, and commit them
79
+ Designed to run when programming katas
80
+ email: kero@chello.nl
81
+ executables:
82
+ - autocommit
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - ".autotest"
87
+ - ".rspec"
88
+ - Rakefile
89
+ - bin/autocommit
90
+ - lib/autocommit/detector.rb
91
+ - lib/autocommit/gatherer.rb
92
+ - lib/autocommit/git_committer.rb
93
+ - spec/autocommit/detector_spec.rb
94
+ - spec/autocommit/gatherer_spec.rb
95
+ - spec/helpers/file_manipulation.rb
96
+ - spec/helpers/simplecov.rb
97
+ - version.txt
98
+ homepage: http://chmeee.org/project/autocommit
99
+ licenses:
100
+ - GPL-3
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: watch a directory for changes, and commit them
122
+ test_files:
123
+ - spec/helpers/file_manipulation.rb
124
+ - spec/helpers/simplecov.rb
125
+ - spec/autocommit/gatherer_spec.rb
126
+ - spec/autocommit/detector_spec.rb
127
+ - ".rspec"
128
+ - ".autotest"
Binary file