nit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/README.md +205 -15
  4. data/Rakefile +11 -0
  5. data/Thorfile +19 -0
  6. data/bin/nit +4 -0
  7. data/lib/nit/CHANGES.mk +7 -0
  8. data/lib/nit/app.rb +80 -0
  9. data/lib/nit/commit.rb +7 -0
  10. data/lib/nit/config.rb +81 -0
  11. data/lib/nit/files.rb +60 -0
  12. data/lib/nit/ignore.rb +36 -0
  13. data/lib/nit/lines.rb +63 -0
  14. data/lib/nit/status.rb +94 -0
  15. data/lib/nit/version.rb +1 -1
  16. data/lib/nit.rb +0 -3
  17. data/nit.gemspec +6 -3
  18. data/test/config_test.rb +15 -0
  19. data/test/dummies/stage/.gitignore +1 -0
  20. data/test/dummies/stage/brandnew.rb +0 -0
  21. data/test/dummies/stage/git/COMMIT_EDITMSG +21 -0
  22. data/test/dummies/stage/git/HEAD +1 -0
  23. data/test/dummies/stage/git/config +5 -0
  24. data/test/dummies/stage/git/description +1 -0
  25. data/test/dummies/stage/git/hooks/applypatch-msg.sample +15 -0
  26. data/test/dummies/stage/git/hooks/commit-msg.sample +24 -0
  27. data/test/dummies/stage/git/hooks/post-update.sample +8 -0
  28. data/test/dummies/stage/git/hooks/pre-applypatch.sample +14 -0
  29. data/test/dummies/stage/git/hooks/pre-commit.sample +50 -0
  30. data/test/dummies/stage/git/hooks/pre-rebase.sample +169 -0
  31. data/test/dummies/stage/git/hooks/prepare-commit-msg.sample +36 -0
  32. data/test/dummies/stage/git/hooks/update.sample +128 -0
  33. data/test/dummies/stage/git/index +0 -0
  34. data/test/dummies/stage/git/info/exclude +6 -0
  35. data/test/dummies/stage/git/logs/HEAD +2 -0
  36. data/test/dummies/stage/git/logs/refs/heads/master +2 -0
  37. data/test/dummies/stage/git/objects/0f/e4f83176db6842cd95f439f1edad3cb8483b4e +0 -0
  38. data/test/dummies/stage/git/objects/5c/0d92dd14afeb4c2bcd11bc3f072390be598a73 +1 -0
  39. data/test/dummies/stage/git/objects/60/bd895ee4a908b754f1980491c0e0852c29a8cd +0 -0
  40. data/test/dummies/stage/git/objects/b7/5ac79d08245a3a8a662520dd90f80be097cc44 +1 -0
  41. data/test/dummies/stage/git/objects/c1/172bf75d73a630c467f1e1448c44d9188fe23e +0 -0
  42. data/test/dummies/stage/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  43. data/test/dummies/stage/git/refs/heads/master +1 -0
  44. data/test/dummies/stage/new.rb +0 -0
  45. data/test/dummies/stage/on_stage.rb +1 -0
  46. data/test/dummies/stage/staged.rb +1 -0
  47. data/test/files_test.rb +45 -0
  48. data/test/ignore_test.rb +46 -0
  49. data/test/lines_test.rb +26 -0
  50. data/test/nit_test.rb +48 -0
  51. data/test/status_test.rb +88 -0
  52. data/test/test_helper.rb +2 -0
  53. metadata +122 -19
File without changes
@@ -0,0 +1 @@
1
+ bu
@@ -0,0 +1 @@
1
+ yo!
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class NitFileTest < MiniTest::Spec
4
+ it { Nit::File.new("new.rb", "<line 1>").to_s.must_equal "new.rb" }
5
+ end
6
+
7
+ class FilesTest < MiniTest::Spec
8
+ subject { Nit::Files.new(["on_stage.rb", "stage.rb", "stagedive.mk"]) }
9
+
10
+ describe "#[]" do
11
+ it { subject[100].must_equal nil }
12
+ it { subject[0].to_s.must_equal "on_stage.rb" }
13
+ it { subject["0"].to_s.must_equal "on_stage.rb" }
14
+ end
15
+
16
+ describe "#index" do
17
+ it { subject.index("on_stage.rb").must_equal 0 }
18
+ #it { subject.index(Nit::File.new("on_stage.rb", "<line 1>")).must_equal 0 }
19
+ end
20
+
21
+ # methods that should be in a separate class, like CliIndexer or so.
22
+ describe "#evaluate" do
23
+ it { subject.evaluate([1,2]).must_equal ["stage.rb", "stagedive.mk"] }
24
+ end
25
+
26
+ describe "#list" do
27
+ it { subject.list([0, 1]).must_equal "on_stage.rb stage.rb" }
28
+ end
29
+ end
30
+
31
+ class CharIndexerTest < MiniTest::Spec
32
+ subject { Nit::Files.new(["on_stage.rb", "stage.rb", "stagedive.mk"], Nit::Files::CharIndexer) }
33
+
34
+ describe "#evaluate" do
35
+ it { subject.evaluate(["b","c"]).must_equal ["stage.rb", "stagedive.mk"] }
36
+ it { subject.evaluate(["bc"]).must_equal ["stage.rb", "stagedive.mk"] }
37
+
38
+ it { subject.index("stage.rb").must_equal "b" }
39
+ end
40
+
41
+ describe "#list" do
42
+ it { subject.list(["b","c"]).must_equal "stage.rb stagedive.mk" }
43
+ it { subject.list(["bc"]).must_equal "stage.rb stagedive.mk" }
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ class IgnoreTest < StatusTest
4
+ let (:config) { cfg = Nit::Config.new; cfg.indexer = "IntegerIndexer"; cfg }
5
+
6
+ after do
7
+ config.send(:file).rm!
8
+ end
9
+
10
+ it "ignores invalid indexes" do
11
+ Nit::Ignore.new(config).call(output, [100])
12
+ config.ignored_files.must_equal []
13
+ end
14
+
15
+ it "what" do
16
+ config.ignored_files.must_equal []
17
+
18
+ Nit::Ignore.new(config).call(output, [0,1])
19
+
20
+ config.ignored_files.must_equal ["on_stage.rb", "staged.rb"]
21
+ end
22
+
23
+ describe "ignore (no arguments)" do
24
+ it "blanks when nothing ignored" do
25
+ Nit::Ignore.new(config).call(output, []).must_equal nil
26
+ end
27
+
28
+ it "shows ignored files" do
29
+ Nit::Ignore.new(config).call(output, [1])
30
+
31
+ Nit::Ignore.new(config).call(output, []).must_equal <<-EOF
32
+ Ignored files:
33
+ [0] staged.rb
34
+ EOF
35
+ # FIXME: why is <<- not working?
36
+ end
37
+ end
38
+
39
+ describe "unignore 1 2" do
40
+ it "what" do
41
+ Nit::Ignore.new(config).call(output, [0,1])
42
+ Nit::Unignore.new(config).call(output, [1])
43
+ config.ignored_files.must_equal ["on_stage.rb"]
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ class LinesTest < StatusTest
2
+ describe "#files" do
3
+ it do
4
+ Nit::Lines.new(output).files.map(&:to_s).must_equal([
5
+ "on_stage.rb",
6
+ "staged.rb",
7
+ "brandnew.rb",
8
+ "new.rb",
9
+ "../lib/new.rb"])
10
+ end
11
+ end
12
+
13
+ describe "#to_s" do
14
+ let (:output) { "1\n2" }
15
+ it { Nit::Lines.new(output).to_s.must_equal(output) }
16
+ end
17
+
18
+ describe "Line" do
19
+ let (:lines) { Nit::Lines.new("stage\nrocks") }
20
+ subject { lines[0] }
21
+
22
+ it { subject.to_s.must_equal "stage" }
23
+ it { subject.delete
24
+ lines.to_s.must_equal "rocks"}
25
+ end
26
+ end
data/test/nit_test.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ # this is like an integration test just checking if the "click paths" work.
4
+ class NitTest < MiniTest::Spec
5
+ let (:on_stage_line) { "modified: on_stage.rb [a]" }
6
+
7
+ describe "nit status" do
8
+ it "numbers files to stage" do # TODO: 2BRM, moved to status_test.
9
+ #nit("status").must_match /modified\:\s+on_stage\.rb\s+[a]/
10
+ nit("status").must_match on_stage_line
11
+ end
12
+ end
13
+
14
+ describe "nit" do
15
+ it "delegates to status" do
16
+ nit("").must_match on_stage_line
17
+ end
18
+ end
19
+
20
+ def nit(args)
21
+ output = ""
22
+ Dir.chdir "test/dummies/stage" do
23
+ `cp -R git .git`
24
+ output = `../../../bin/nit #{args}`
25
+ `rm -rf .git`
26
+ end
27
+ output
28
+ end
29
+ end
30
+
31
+ class DynamicCommandTest < NitTest
32
+ it "evaluates indexes and invokes git command with it" do
33
+ # how to capture STDERR: https://www.ruby-forum.com/topic/1103519#982117
34
+ nit(" checkout e 2>&1").must_match "error: pathspec 'new.rb' did not match any file(s) known to git."
35
+ end
36
+ end
37
+
38
+ class DiffTest < NitTest
39
+ it { nit(" diff b").must_match "a\/staged.rb" }
40
+ end
41
+
42
+ class NitWithCharIndexerTest < NitTest
43
+ it do
44
+ out = nit(" diff ab")
45
+ out.must_match "a\/staged.rb"
46
+ out.must_match "a\/on_stage.rb"
47
+ end
48
+ end
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ class StatusTest < MiniTest::Spec
4
+ let (:config) do
5
+ Nit::Config.new.tap do |cfg| # TODO: test with all combinations?
6
+ cfg.indexer = "IntegerIndexer"
7
+ cfg.index_renderer = "PrependIndexRenderer"
8
+ end
9
+ end
10
+
11
+ let (:output) do <<-EOF
12
+ # On branch master
13
+ # Changes not staged for commit:
14
+ # (use "git add <file>..." to update what will be committed)
15
+ # (use "git checkout -- <file>..." to discard changes in working directory)
16
+ #
17
+ #\tmodified: on_stage.rb
18
+ #\tmodified: staged.rb
19
+ #
20
+ # Untracked files:
21
+ # (use "git add <file>..." to include in what will be committed)
22
+ #
23
+ #\tbrandnew.rb
24
+ #\tnew.rb
25
+ #\t../lib/new.rb
26
+ no changes added to commit (use "git add" and/or "git commit -a")
27
+ EOF
28
+ end
29
+ subject { Nit::Status.new(config) }
30
+
31
+
32
+ describe "indexing" do
33
+ it "numbers files" do
34
+ console = subject.call(output)
35
+ console.must_match "modified: [0] on_stage.rb"
36
+ console.must_match "modified: [1] staged.rb"
37
+ console.must_match "[2] brandnew.rb"
38
+ console.must_match "[3] new.rb"
39
+ end
40
+ end
41
+
42
+ describe "char indexing" do
43
+ it "indexes files" do
44
+ config.indexer = "CharIndexer"
45
+
46
+ console = subject.call(output)
47
+ console.must_match "modified: [a] on_stage.rb"
48
+ console.must_match "modified: [b] staged.rb"
49
+ console.must_match "[c] brandnew.rb"
50
+ console.must_match "[d] new.rb"
51
+ end
52
+ end
53
+
54
+ describe "ignoring" do
55
+ after do
56
+ config.send(:file).rm!
57
+ end
58
+
59
+ it "doesn't show ignored files count per default" do
60
+ subject.call(output).wont_match(/Ignored files:/)
61
+ end
62
+
63
+ it "shows ignored files when ignoring" do
64
+ config.ignored_files = ["new.rb", "brandnew.rb", "staged.rb"] # TODO: make this more generic.
65
+
66
+ console = subject.call(output)
67
+ console.must_match "[1] ../lib/new.rb" # this file has a new index since all other ignored.
68
+ console.must_match "Ignored files: 3"
69
+ console.wont_match " staged.rb"
70
+ console.wont_match " new.rb"
71
+ console.wont_match " brandnew.rb"
72
+ console.must_match " ../lib/new.rb"
73
+ end
74
+
75
+ it "also ignores files when commiting" do
76
+ config.ignored_files = ["new.rb", "brandnew.rb", "staged.rb"] # TODO: make this more generic.
77
+
78
+ commit = Nit::Commit.new(config)
79
+ commit.instance_eval do
80
+ def system(command)
81
+ command
82
+ end
83
+ end
84
+
85
+ commit.call(output, [1]).must_equal "git add ../lib/new.rb && git commit"
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'nit/app'
metadata CHANGED
@@ -1,20 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nick Sutterer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-23 00:00:00.000000000 Z
11
+ date: 2013-08-12 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
31
  - - ~>
20
32
  - !ruby/object:Gem::Version
@@ -22,7 +34,6 @@ dependencies:
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
38
  - - ~>
28
39
  - !ruby/object:Gem::Version
@@ -30,23 +41,36 @@ dependencies:
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
- description: Nit improves your git workflows.
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: Improving your Git workflow since 2013.
47
70
  email:
48
71
  - apotonick@gmail.com
49
- executables: []
72
+ executables:
73
+ - nit
50
74
  extensions: []
51
75
  extra_rdoc_files: []
52
76
  files:
@@ -55,32 +79,111 @@ files:
55
79
  - LICENSE.txt
56
80
  - README.md
57
81
  - Rakefile
82
+ - Thorfile
83
+ - bin/nit
58
84
  - lib/nit.rb
85
+ - lib/nit/CHANGES.mk
86
+ - lib/nit/app.rb
87
+ - lib/nit/commit.rb
88
+ - lib/nit/config.rb
89
+ - lib/nit/files.rb
90
+ - lib/nit/ignore.rb
91
+ - lib/nit/lines.rb
92
+ - lib/nit/status.rb
59
93
  - lib/nit/version.rb
60
94
  - nit.gemspec
61
- homepage: ''
95
+ - test/config_test.rb
96
+ - test/dummies/stage/.gitignore
97
+ - test/dummies/stage/brandnew.rb
98
+ - test/dummies/stage/git/COMMIT_EDITMSG
99
+ - test/dummies/stage/git/HEAD
100
+ - test/dummies/stage/git/config
101
+ - test/dummies/stage/git/description
102
+ - test/dummies/stage/git/hooks/applypatch-msg.sample
103
+ - test/dummies/stage/git/hooks/commit-msg.sample
104
+ - test/dummies/stage/git/hooks/post-update.sample
105
+ - test/dummies/stage/git/hooks/pre-applypatch.sample
106
+ - test/dummies/stage/git/hooks/pre-commit.sample
107
+ - test/dummies/stage/git/hooks/pre-rebase.sample
108
+ - test/dummies/stage/git/hooks/prepare-commit-msg.sample
109
+ - test/dummies/stage/git/hooks/update.sample
110
+ - test/dummies/stage/git/index
111
+ - test/dummies/stage/git/info/exclude
112
+ - test/dummies/stage/git/logs/HEAD
113
+ - test/dummies/stage/git/logs/refs/heads/master
114
+ - test/dummies/stage/git/objects/0f/e4f83176db6842cd95f439f1edad3cb8483b4e
115
+ - test/dummies/stage/git/objects/5c/0d92dd14afeb4c2bcd11bc3f072390be598a73
116
+ - test/dummies/stage/git/objects/60/bd895ee4a908b754f1980491c0e0852c29a8cd
117
+ - test/dummies/stage/git/objects/b7/5ac79d08245a3a8a662520dd90f80be097cc44
118
+ - test/dummies/stage/git/objects/c1/172bf75d73a630c467f1e1448c44d9188fe23e
119
+ - test/dummies/stage/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
120
+ - test/dummies/stage/git/refs/heads/master
121
+ - test/dummies/stage/new.rb
122
+ - test/dummies/stage/on_stage.rb
123
+ - test/dummies/stage/staged.rb
124
+ - test/files_test.rb
125
+ - test/ignore_test.rb
126
+ - test/lines_test.rb
127
+ - test/nit_test.rb
128
+ - test/status_test.rb
129
+ - test/test_helper.rb
130
+ homepage: http://github.com/apotonick/nit
62
131
  licenses:
63
132
  - MIT
133
+ metadata: {}
64
134
  post_install_message:
65
135
  rdoc_options: []
66
136
  require_paths:
67
137
  - lib
68
138
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
139
  requirements:
71
- - - ! '>='
140
+ - - '>='
72
141
  - !ruby/object:Gem::Version
73
142
  version: '0'
74
143
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
144
  requirements:
77
- - - ! '>='
145
+ - - '>='
78
146
  - !ruby/object:Gem::Version
79
147
  version: '0'
80
148
  requirements: []
81
149
  rubyforge_project:
82
- rubygems_version: 1.8.25
150
+ rubygems_version: 2.0.3
83
151
  signing_key:
84
- specification_version: 3
152
+ specification_version: 4
85
153
  summary: Nit improves your git workflows.
86
- test_files: []
154
+ test_files:
155
+ - test/config_test.rb
156
+ - test/dummies/stage/.gitignore
157
+ - test/dummies/stage/brandnew.rb
158
+ - test/dummies/stage/git/COMMIT_EDITMSG
159
+ - test/dummies/stage/git/HEAD
160
+ - test/dummies/stage/git/config
161
+ - test/dummies/stage/git/description
162
+ - test/dummies/stage/git/hooks/applypatch-msg.sample
163
+ - test/dummies/stage/git/hooks/commit-msg.sample
164
+ - test/dummies/stage/git/hooks/post-update.sample
165
+ - test/dummies/stage/git/hooks/pre-applypatch.sample
166
+ - test/dummies/stage/git/hooks/pre-commit.sample
167
+ - test/dummies/stage/git/hooks/pre-rebase.sample
168
+ - test/dummies/stage/git/hooks/prepare-commit-msg.sample
169
+ - test/dummies/stage/git/hooks/update.sample
170
+ - test/dummies/stage/git/index
171
+ - test/dummies/stage/git/info/exclude
172
+ - test/dummies/stage/git/logs/HEAD
173
+ - test/dummies/stage/git/logs/refs/heads/master
174
+ - test/dummies/stage/git/objects/0f/e4f83176db6842cd95f439f1edad3cb8483b4e
175
+ - test/dummies/stage/git/objects/5c/0d92dd14afeb4c2bcd11bc3f072390be598a73
176
+ - test/dummies/stage/git/objects/60/bd895ee4a908b754f1980491c0e0852c29a8cd
177
+ - test/dummies/stage/git/objects/b7/5ac79d08245a3a8a662520dd90f80be097cc44
178
+ - test/dummies/stage/git/objects/c1/172bf75d73a630c467f1e1448c44d9188fe23e
179
+ - test/dummies/stage/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
180
+ - test/dummies/stage/git/refs/heads/master
181
+ - test/dummies/stage/new.rb
182
+ - test/dummies/stage/on_stage.rb
183
+ - test/dummies/stage/staged.rb
184
+ - test/files_test.rb
185
+ - test/ignore_test.rb
186
+ - test/lines_test.rb
187
+ - test/nit_test.rb
188
+ - test/status_test.rb
189
+ - test/test_helper.rb