git_shizzle 0.2.6

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +71 -0
  6. data/Guardfile +23 -0
  7. data/Thorfile +5 -0
  8. data/bin/quick-git +8 -0
  9. data/doc.txt +8 -0
  10. data/git_shizzle.gemspec +42 -0
  11. data/lib/commands.rb +86 -0
  12. data/lib/git_shizzle/cli.rb +29 -0
  13. data/lib/git_shizzle/dsl/command.rb +41 -0
  14. data/lib/git_shizzle/dsl/command_collection.rb +50 -0
  15. data/lib/git_shizzle/dsl/command_context.rb +19 -0
  16. data/lib/git_shizzle/dsl/command_definition_error.rb +15 -0
  17. data/lib/git_shizzle/dsl/command_not_found_error.rb +9 -0
  18. data/lib/git_shizzle/dsl/dsl.rb +27 -0
  19. data/lib/git_shizzle/dsl/duplicate_command_definition_error.rb +9 -0
  20. data/lib/git_shizzle/dsl/no_command_file_found_error.rb +5 -0
  21. data/lib/git_shizzle/dsl.rb +8 -0
  22. data/lib/git_shizzle/error.rb +5 -0
  23. data/lib/git_shizzle/git/file.rb +42 -0
  24. data/lib/git_shizzle/git/git.rb +67 -0
  25. data/lib/git_shizzle/git.rb +8 -0
  26. data/lib/git_shizzle/index_specifications/base.rb +31 -0
  27. data/lib/git_shizzle/index_specifications/combined.rb +51 -0
  28. data/lib/git_shizzle/index_specifications/errors.rb +21 -0
  29. data/lib/git_shizzle/index_specifications/everything.rb +17 -0
  30. data/lib/git_shizzle/index_specifications/exclusive_range.rb +24 -0
  31. data/lib/git_shizzle/index_specifications/file.rb +22 -0
  32. data/lib/git_shizzle/index_specifications/range.rb +24 -0
  33. data/lib/git_shizzle/index_specifications.rb +10 -0
  34. data/lib/git_shizzle/version.rb +5 -0
  35. data/lib/git_shizzle.rb +53 -0
  36. data/spec/git-shizzle/builtin_commands/checkout_spec.rb +49 -0
  37. data/spec/git-shizzle/builtin_commands/diff_cached_spec.rb +53 -0
  38. data/spec/git-shizzle/builtin_commands/diff_spec.rb +49 -0
  39. data/spec/git-shizzle/builtin_commands/stage_patch_spec.rb +32 -0
  40. data/spec/git-shizzle/builtin_commands/stage_spec.rb +75 -0
  41. data/spec/git-shizzle/builtin_commands/track_spec.rb +41 -0
  42. data/spec/git-shizzle/builtin_commands/unstage_spec.rb +68 -0
  43. data/spec/git-shizzle/command_spec.rb +14 -0
  44. data/spec/git-shizzle/dsl_spec.rb +48 -0
  45. data/spec/git-shizzle/git_spec.rb +15 -0
  46. data/spec/git-shizzle/index_spec.rb +154 -0
  47. data/spec/git-shizzle/status_parser_spec.rb +60 -0
  48. data/spec/helpers/git_repository.rb +46 -0
  49. data/spec/spec_helper.rb +6 -0
  50. metadata +252 -0
@@ -0,0 +1,154 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+ require 'git_shizzle'
3
+
4
+ describe 'Indexes specified on the CLI' do
5
+
6
+ let(:git) { GitShizzle::Git::Git.new(repo) }
7
+ subject { GitShizzle::QuickGit.new(git) }
8
+ let(:number_of_untracked_files) { 10 }
9
+
10
+ before (:each) do
11
+ number_of_untracked_files.times.each do |i|
12
+ create 'untracked-%02d' % (i + 1)
13
+ end
14
+ end
15
+
16
+ def assert_index_status(*status)
17
+ number_of_untracked_files.times.each do |i|
18
+ expected_status = status[i] || status[-1]
19
+ git.status[i].index_status.should == expected_status
20
+ end
21
+ end
22
+
23
+ describe 'indexes' do
24
+ context 'when no index is specified' do
25
+ it 'should fail' do
26
+ expect { subject.track }.to raise_error(GitShizzle::IndexSpecifications::NoFilesError, "No files for command 'track'.")
27
+ end
28
+ end
29
+
30
+ context 'when specifying an index' do
31
+ it 'should operate on the file mapped to the index' do
32
+ subject.track 1
33
+
34
+ assert_index_status :added, :untracked
35
+ end
36
+ end
37
+
38
+ context 'when specifying a string index' do
39
+ it 'should operate on the file mapped to the index' do
40
+ subject.track '1'
41
+
42
+ assert_index_status :added, :untracked
43
+ end
44
+ end
45
+
46
+ context 'when specifying a non-numeric index' do
47
+ it 'should fail' do
48
+ expect { subject.track 'a' }.to raise_error(GitShizzle::IndexSpecifications::IndexParserError, /Could not parse index 'a'/)
49
+
50
+ assert_index_status :untracked
51
+ end
52
+ end
53
+
54
+ context 'when specifying an index outside of the range of available indexes' do
55
+ it 'should fail' do
56
+ expect { subject.track 42 }.to raise_error(GitShizzle::IndexSpecifications::IndexSpecificationError, 'Could not determine files for indexes: 42')
57
+
58
+ assert_index_status :untracked
59
+ end
60
+ end
61
+
62
+ context 'when specifying the same index twice' do
63
+ it 'should operate on the file mapped to the index once' do
64
+ subject.track 1, 1
65
+
66
+ assert_index_status :added, :untracked
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'ranges' do
72
+ context 'when a specifying an inclusive range' do
73
+ it 'should operate on each file in the range' do
74
+ subject.track '1..3'
75
+
76
+ assert_index_status :added, :added, :added, :untracked
77
+ end
78
+ end
79
+
80
+ context 'when a specifying an exclusive range' do
81
+ it 'should operate on each file in the range' do
82
+ subject.track '1...3'
83
+
84
+ assert_index_status :added, :added, :untracked
85
+ end
86
+ end
87
+
88
+ context 'when specifying a non-numeric range' do
89
+ it 'should fail' do
90
+ expect { subject.track 'a..z' }.to raise_error(GitShizzle::IndexSpecifications::IndexParserError, /Could not parse index 'a\.\.z'/)
91
+
92
+ assert_index_status :untracked
93
+ end
94
+ end
95
+
96
+ context 'when specifying a non-numeric exclusive range' do
97
+ it 'should fail' do
98
+ expect { subject.track 'a...z' }.to raise_error(GitShizzle::IndexSpecifications::IndexParserError, /Could not parse index 'a\.\.\.z'/)
99
+
100
+ assert_index_status :untracked
101
+ end
102
+ end
103
+
104
+ context 'when specifying a range outside of the range of available indexes' do
105
+ it 'should fail' do
106
+ expect { subject.track '11..15' }.to raise_error(GitShizzle::IndexSpecifications::IndexSpecificationError, 'Could not determine files for indexes: 11, 12, 13, 14, 15')
107
+
108
+ assert_index_status :untracked
109
+ end
110
+ end
111
+
112
+ context 'when specifying a range partly outside of the range of available indexes' do
113
+ it 'should fail' do
114
+ expect { subject.track '9..15' }.to raise_error(GitShizzle::IndexSpecifications::IndexSpecificationError, 'Could not determine files for indexes: 11, 12, 13, 14, 15')
115
+
116
+ assert_index_status :untracked
117
+ end
118
+ end
119
+
120
+ context 'when specifying overlapping index and range' do
121
+ it 'should operate on each file in the range once' do
122
+ subject.track 1, 2, 3, '1..3', '1...3'
123
+
124
+ assert_index_status :added, :added, :added, :untracked
125
+ end
126
+ end
127
+ end
128
+
129
+ describe 'current directory' do
130
+ context 'when a specifying the current directory' do
131
+ it 'should operate on each file' do
132
+ subject.track '.'
133
+
134
+ assert_index_status :added
135
+ end
136
+ end
137
+
138
+ context 'when a specifying the current directory and a file index' do
139
+ it 'should operate on each file' do
140
+ subject.track 1, '.'
141
+
142
+ assert_index_status :added
143
+ end
144
+ end
145
+
146
+ context 'when a specifying the current directory and a file index outside of the range of available indexes' do
147
+ it 'should operate on each file' do
148
+ expect { subject.track 42, '.' }.to raise_error(GitShizzle::IndexSpecifications::IndexSpecificationError, 'Could not determine files for indexes: 42')
149
+
150
+ assert_index_status :untracked
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+ require 'git_shizzle'
3
+
4
+ describe 'File index, status and path parsed from `git status`' do
5
+
6
+ let(:git) { GitShizzle::Git::Git.new(repo) }
7
+ subject { GitShizzle::QuickGit.new(git) }
8
+
9
+ context 'when file name does not contain spaces' do
10
+ it 'should be able to parse' do
11
+ create 'file-name'
12
+
13
+ git.status.count.should == 1
14
+ end
15
+ end
16
+
17
+ context 'when file name contains spaces' do
18
+ it 'should be able to parse' do
19
+ create 'file name'
20
+
21
+ git.status.count.should == 1
22
+ end
23
+ end
24
+
25
+ context 'when two files are untracked' do
26
+ it 'should be able to parse' do
27
+ create 'file-1'
28
+ create 'file-2'
29
+
30
+ git.status.count.should == 2
31
+ end
32
+ end
33
+
34
+ context 'when tracked file was renamed and staged' do
35
+ context 'no other files exist' do
36
+ it 'should be able to parse indexes' do
37
+ create 'file'
38
+ stage
39
+ `git commit -m 'added file'`
40
+ move 'file', 'renamed-file'
41
+ stage
42
+
43
+ git.status.count.should == 1
44
+ end
45
+ end
46
+
47
+ context 'untracked files exist' do
48
+ it 'should be able to parse indexes' do
49
+ create 'file'
50
+ stage
51
+ `git commit -m 'added file'`
52
+ move 'file', 'renamed-file'
53
+ stage
54
+ create 'untracked'
55
+
56
+ git.status.count.should == 2
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,46 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+ require 'securerandom'
4
+
5
+ module GitRepository
6
+ extend RSpec::SharedContext
7
+
8
+ let(:repo) { @repo }
9
+ before(:each) { create_sample_repo }
10
+ after(:each) { remove_sample_repo }
11
+
12
+ def create_sample_repo
13
+ @previous_dir = Dir.pwd
14
+ @repo = Dir.mktmpdir 'git_shizzle'
15
+ Dir.chdir(@repo)
16
+ `git init`
17
+ `git config user.name somebody`
18
+ `git config user.email somebody@example.com`
19
+ end
20
+
21
+ def create(file)
22
+ FileUtils.touch file
23
+ modify(file)
24
+ end
25
+
26
+ def modify(file)
27
+ File.write file, ::SecureRandom.uuid
28
+ end
29
+
30
+ def move(src, dst)
31
+ FileUtils.mv src, dst, :verbose => true
32
+ end
33
+
34
+ def delete(file)
35
+ FileUtils.rm file
36
+ end
37
+
38
+ def stage(file = nil)
39
+ `git add --all #{file}`
40
+ end
41
+
42
+ def remove_sample_repo
43
+ Dir.chdir(@previous_dir)
44
+ FileUtils.rm_rf @repo
45
+ end
46
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'helpers/git_repository'
3
+
4
+ RSpec.configure do |config|
5
+ config.include GitRepository
6
+ end
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_shizzle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.6
5
+ platform: ruby
6
+ authors:
7
+ - Bjoern Rochel
8
+ - Alexander Groß
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.16'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.16'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-mocks
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: guard-bundler
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: win32console
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: ruby_gntp
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: wdm
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: git_shizzle lets you quickly operate on the file lists printed by `git
155
+ status`. Imagine a number before each line of the status output and use that index
156
+ to specify the file you want to operate on. For example, to stage the first file
157
+ in the list of "Changes not staged for commit", run `quick-git stage 1`.
158
+ email:
159
+ - bjoern@bjro.de
160
+ - agross@therightstuff.de
161
+ executables:
162
+ - quick-git
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - ".gitignore"
167
+ - ".rspec"
168
+ - Gemfile
169
+ - Gemfile.lock
170
+ - Guardfile
171
+ - Thorfile
172
+ - bin/quick-git
173
+ - doc.txt
174
+ - git_shizzle.gemspec
175
+ - lib/commands.rb
176
+ - lib/git_shizzle.rb
177
+ - lib/git_shizzle/cli.rb
178
+ - lib/git_shizzle/dsl.rb
179
+ - lib/git_shizzle/dsl/command.rb
180
+ - lib/git_shizzle/dsl/command_collection.rb
181
+ - lib/git_shizzle/dsl/command_context.rb
182
+ - lib/git_shizzle/dsl/command_definition_error.rb
183
+ - lib/git_shizzle/dsl/command_not_found_error.rb
184
+ - lib/git_shizzle/dsl/dsl.rb
185
+ - lib/git_shizzle/dsl/duplicate_command_definition_error.rb
186
+ - lib/git_shizzle/dsl/no_command_file_found_error.rb
187
+ - lib/git_shizzle/error.rb
188
+ - lib/git_shizzle/git.rb
189
+ - lib/git_shizzle/git/file.rb
190
+ - lib/git_shizzle/git/git.rb
191
+ - lib/git_shizzle/index_specifications.rb
192
+ - lib/git_shizzle/index_specifications/base.rb
193
+ - lib/git_shizzle/index_specifications/combined.rb
194
+ - lib/git_shizzle/index_specifications/errors.rb
195
+ - lib/git_shizzle/index_specifications/everything.rb
196
+ - lib/git_shizzle/index_specifications/exclusive_range.rb
197
+ - lib/git_shizzle/index_specifications/file.rb
198
+ - lib/git_shizzle/index_specifications/range.rb
199
+ - lib/git_shizzle/version.rb
200
+ - spec/git-shizzle/builtin_commands/checkout_spec.rb
201
+ - spec/git-shizzle/builtin_commands/diff_cached_spec.rb
202
+ - spec/git-shizzle/builtin_commands/diff_spec.rb
203
+ - spec/git-shizzle/builtin_commands/stage_patch_spec.rb
204
+ - spec/git-shizzle/builtin_commands/stage_spec.rb
205
+ - spec/git-shizzle/builtin_commands/track_spec.rb
206
+ - spec/git-shizzle/builtin_commands/unstage_spec.rb
207
+ - spec/git-shizzle/command_spec.rb
208
+ - spec/git-shizzle/dsl_spec.rb
209
+ - spec/git-shizzle/git_spec.rb
210
+ - spec/git-shizzle/index_spec.rb
211
+ - spec/git-shizzle/status_parser_spec.rb
212
+ - spec/helpers/git_repository.rb
213
+ - spec/spec_helper.rb
214
+ homepage: http://grossweber.com
215
+ licenses:
216
+ - BSD
217
+ metadata: {}
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubyforge_project:
234
+ rubygems_version: 2.0.14
235
+ signing_key:
236
+ specification_version: 4
237
+ summary: Quickly operate on the git working copy and the index
238
+ test_files:
239
+ - spec/git-shizzle/builtin_commands/checkout_spec.rb
240
+ - spec/git-shizzle/builtin_commands/diff_cached_spec.rb
241
+ - spec/git-shizzle/builtin_commands/diff_spec.rb
242
+ - spec/git-shizzle/builtin_commands/stage_patch_spec.rb
243
+ - spec/git-shizzle/builtin_commands/stage_spec.rb
244
+ - spec/git-shizzle/builtin_commands/track_spec.rb
245
+ - spec/git-shizzle/builtin_commands/unstage_spec.rb
246
+ - spec/git-shizzle/command_spec.rb
247
+ - spec/git-shizzle/dsl_spec.rb
248
+ - spec/git-shizzle/git_spec.rb
249
+ - spec/git-shizzle/index_spec.rb
250
+ - spec/git-shizzle/status_parser_spec.rb
251
+ - spec/helpers/git_repository.rb
252
+ - spec/spec_helper.rb