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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +71 -0
- data/Guardfile +23 -0
- data/Thorfile +5 -0
- data/bin/quick-git +8 -0
- data/doc.txt +8 -0
- data/git_shizzle.gemspec +42 -0
- data/lib/commands.rb +86 -0
- data/lib/git_shizzle/cli.rb +29 -0
- data/lib/git_shizzle/dsl/command.rb +41 -0
- data/lib/git_shizzle/dsl/command_collection.rb +50 -0
- data/lib/git_shizzle/dsl/command_context.rb +19 -0
- data/lib/git_shizzle/dsl/command_definition_error.rb +15 -0
- data/lib/git_shizzle/dsl/command_not_found_error.rb +9 -0
- data/lib/git_shizzle/dsl/dsl.rb +27 -0
- data/lib/git_shizzle/dsl/duplicate_command_definition_error.rb +9 -0
- data/lib/git_shizzle/dsl/no_command_file_found_error.rb +5 -0
- data/lib/git_shizzle/dsl.rb +8 -0
- data/lib/git_shizzle/error.rb +5 -0
- data/lib/git_shizzle/git/file.rb +42 -0
- data/lib/git_shizzle/git/git.rb +67 -0
- data/lib/git_shizzle/git.rb +8 -0
- data/lib/git_shizzle/index_specifications/base.rb +31 -0
- data/lib/git_shizzle/index_specifications/combined.rb +51 -0
- data/lib/git_shizzle/index_specifications/errors.rb +21 -0
- data/lib/git_shizzle/index_specifications/everything.rb +17 -0
- data/lib/git_shizzle/index_specifications/exclusive_range.rb +24 -0
- data/lib/git_shizzle/index_specifications/file.rb +22 -0
- data/lib/git_shizzle/index_specifications/range.rb +24 -0
- data/lib/git_shizzle/index_specifications.rb +10 -0
- data/lib/git_shizzle/version.rb +5 -0
- data/lib/git_shizzle.rb +53 -0
- data/spec/git-shizzle/builtin_commands/checkout_spec.rb +49 -0
- data/spec/git-shizzle/builtin_commands/diff_cached_spec.rb +53 -0
- data/spec/git-shizzle/builtin_commands/diff_spec.rb +49 -0
- data/spec/git-shizzle/builtin_commands/stage_patch_spec.rb +32 -0
- data/spec/git-shizzle/builtin_commands/stage_spec.rb +75 -0
- data/spec/git-shizzle/builtin_commands/track_spec.rb +41 -0
- data/spec/git-shizzle/builtin_commands/unstage_spec.rb +68 -0
- data/spec/git-shizzle/command_spec.rb +14 -0
- data/spec/git-shizzle/dsl_spec.rb +48 -0
- data/spec/git-shizzle/git_spec.rb +15 -0
- data/spec/git-shizzle/index_spec.rb +154 -0
- data/spec/git-shizzle/status_parser_spec.rb +60 -0
- data/spec/helpers/git_repository.rb +46 -0
- data/spec/spec_helper.rb +6 -0
- metadata +252 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df6e2b253b4bd24dc1609846aa5239ecd70d4c46
|
4
|
+
data.tar.gz: 386a45ca3f5e6064667d963fe4c350410cc52087
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1926c4e558290bc166966612f45620339be6ca516651941e58b86a44442f2dff82e84613ca817ca6e1e221435d9a514b4238d02fcb89f85d0aea19a67742d9cf
|
7
|
+
data.tar.gz: bd37c769b451a9402addc6207378faec6c0657fb9f87a75be7d4d89b40d165637685ef35d6bb59d60e51c5da4d05cf8fa050772c1da1c2422ed22d33dd72e5e1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
git_shizzle (0.2.5)
|
5
|
+
thor (~> 0.16)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
celluloid (0.15.2)
|
11
|
+
timers (~> 1.1.0)
|
12
|
+
coderay (1.1.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
ffi (1.9.3-x86-mingw32)
|
15
|
+
formatador (0.2.4)
|
16
|
+
guard (2.4.0)
|
17
|
+
formatador (>= 0.2.4)
|
18
|
+
listen (~> 2.1)
|
19
|
+
lumberjack (~> 1.0)
|
20
|
+
pry (>= 0.9.12)
|
21
|
+
thor (>= 0.18.1)
|
22
|
+
guard-bundler (2.0.0)
|
23
|
+
bundler (~> 1.0)
|
24
|
+
guard (~> 2.2)
|
25
|
+
guard-rspec (4.2.6)
|
26
|
+
guard (~> 2.1)
|
27
|
+
rspec (>= 2.14, < 4.0)
|
28
|
+
listen (2.4.1)
|
29
|
+
celluloid (>= 0.15.2)
|
30
|
+
rb-fsevent (>= 0.9.3)
|
31
|
+
rb-inotify (>= 0.9)
|
32
|
+
lumberjack (1.0.4)
|
33
|
+
method_source (0.8.2)
|
34
|
+
pry (0.9.12.6-x86-mingw32)
|
35
|
+
coderay (~> 1.0)
|
36
|
+
method_source (~> 0.8)
|
37
|
+
slop (~> 3.4)
|
38
|
+
win32console (~> 1.3)
|
39
|
+
rake (10.1.1)
|
40
|
+
rb-fsevent (0.9.4)
|
41
|
+
rb-inotify (0.9.3)
|
42
|
+
ffi (>= 0.5.0)
|
43
|
+
rspec (2.14.1)
|
44
|
+
rspec-core (~> 2.14.0)
|
45
|
+
rspec-expectations (~> 2.14.0)
|
46
|
+
rspec-mocks (~> 2.14.0)
|
47
|
+
rspec-core (2.14.7)
|
48
|
+
rspec-expectations (2.14.5)
|
49
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
50
|
+
rspec-mocks (2.14.5)
|
51
|
+
ruby_gntp (0.3.4)
|
52
|
+
slop (3.4.7)
|
53
|
+
thor (0.18.1)
|
54
|
+
timers (1.1.0)
|
55
|
+
wdm (0.1.0)
|
56
|
+
win32console (1.3.2-x86-mingw32)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
x86-mingw32
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
git_shizzle!
|
63
|
+
guard
|
64
|
+
guard-bundler
|
65
|
+
guard-rspec
|
66
|
+
rake
|
67
|
+
rspec
|
68
|
+
rspec-mocks
|
69
|
+
ruby_gntp
|
70
|
+
wdm
|
71
|
+
win32console
|
data/Guardfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
case RbConfig::CONFIG['target_os']
|
2
|
+
when /windows|bccwin|cygwin|djgpp|mingw|mswin|wince/i
|
3
|
+
notification :gntp, :host => 'localhost'
|
4
|
+
when /linux/i
|
5
|
+
notification :notifysend
|
6
|
+
when /mac|darwin/i
|
7
|
+
notification :growl
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'bundler' do
|
11
|
+
watch('Gemfile')
|
12
|
+
watch(/^.+\.gemspec/)
|
13
|
+
end
|
14
|
+
|
15
|
+
guard 'rspec',
|
16
|
+
:all_on_start => true,
|
17
|
+
:all_after_pass => false,
|
18
|
+
:notification => true,
|
19
|
+
:cmd => 'bundle exec rspec --format documentation --tag ~@draft' do
|
20
|
+
watch(%r{^spec/.+_spec\.rb$})
|
21
|
+
watch(%r{^lib/(.+)\.rb$})
|
22
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
23
|
+
end
|
data/Thorfile
ADDED
data/bin/quick-git
ADDED
data/doc.txt
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
stage 1 ==> index
|
2
|
+
stage 1 2 3 4 ==> index
|
3
|
+
stage 1..3 ==> index
|
4
|
+
stage . ==> index
|
5
|
+
diff 1 => show diff on modified tracked file
|
6
|
+
unstage 1 ==> remove from index
|
7
|
+
track 1 => add untracked file into index
|
8
|
+
checkout 1 => discard working directory changes of tracked file
|
data/git_shizzle.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'rbconfig'
|
4
|
+
require 'git_shizzle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'git_shizzle'
|
8
|
+
s.version = GitShizzle::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Bjoern Rochel', 'Alexander Groß']
|
11
|
+
s.email = ['bjoern@bjro.de', 'agross@therightstuff.de']
|
12
|
+
s.homepage = 'http://grossweber.com'
|
13
|
+
s.licenses = ['BSD']
|
14
|
+
s.description = %q{git_shizzle lets you quickly operate on the file lists printed by `git status`. Imagine a number before each line of the status output and use that index to specify the file you want to operate on. For example, to stage the first file in the list of "Changes not staged for commit", run `quick-git stage 1`.}
|
15
|
+
s.summary = %q{Quickly operate on the git working copy and the index}
|
16
|
+
|
17
|
+
s.add_dependency 'thor', '~> 0.16'
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
s.add_development_dependency 'rspec'
|
21
|
+
s.add_development_dependency 'rspec-mocks'
|
22
|
+
s.add_development_dependency 'guard'
|
23
|
+
s.add_development_dependency 'guard-rspec'
|
24
|
+
s.add_development_dependency 'guard-bundler'
|
25
|
+
|
26
|
+
case RbConfig::CONFIG['target_os']
|
27
|
+
when /windows|bccwin|cygwin|djgpp|mingw|mswin|wince/i
|
28
|
+
s.add_development_dependency 'win32console'
|
29
|
+
s.add_development_dependency 'ruby_gntp'
|
30
|
+
s.add_development_dependency 'wdm'
|
31
|
+
when /linux/i
|
32
|
+
s.add_development_dependency 'rb-inotify', '~> 0.8.8'
|
33
|
+
when /mac|darwin/i
|
34
|
+
s.add_development_dependency 'rb-fsevent'
|
35
|
+
s.add_development_dependency 'growl'
|
36
|
+
end
|
37
|
+
|
38
|
+
s.files = `git ls-files`.split("\n")
|
39
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
40
|
+
s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
41
|
+
s.require_paths = ['lib']
|
42
|
+
end
|
data/lib/commands.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
desc 'stage files'
|
4
|
+
command :stage do
|
5
|
+
applies_to do |index, work_tree|
|
6
|
+
work_tree == :modified || work_tree == :deleted
|
7
|
+
end
|
8
|
+
|
9
|
+
action do |index, work_tree, path|
|
10
|
+
case work_tree
|
11
|
+
when :modified
|
12
|
+
['add --', path]
|
13
|
+
when :deleted
|
14
|
+
['rm --', path]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'stage patches'
|
20
|
+
command :stage_with_patch do
|
21
|
+
applies_to do |index, work_tree|
|
22
|
+
work_tree == :modified
|
23
|
+
end
|
24
|
+
|
25
|
+
action do |index, work_tree, path|
|
26
|
+
case work_tree
|
27
|
+
when :modified
|
28
|
+
['add --patch --', path]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'track files'
|
34
|
+
command :track do
|
35
|
+
applies_to do |index, work_tree|
|
36
|
+
index == :untracked || work_tree == :untracked
|
37
|
+
end
|
38
|
+
|
39
|
+
action do |index, work_tree, path|
|
40
|
+
['add --', path] if work_tree == :untracked
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'diff files'
|
45
|
+
command :diff do
|
46
|
+
applies_to do |index, work_tree|
|
47
|
+
work_tree == :modified || work_tree == :deleted
|
48
|
+
end
|
49
|
+
|
50
|
+
action do |index, work_tree, path|
|
51
|
+
['diff --', path]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'diff cached (staged) files'
|
56
|
+
command :diff_cached do
|
57
|
+
applies_to do |index, work_tree|
|
58
|
+
index == :modified || index == :deleted
|
59
|
+
end
|
60
|
+
|
61
|
+
action do |index, work_tree, path|
|
62
|
+
['diff --cached --', path]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'checkout files'
|
67
|
+
command :checkout do
|
68
|
+
applies_to do |index, work_tree|
|
69
|
+
work_tree == :modified || work_tree == :deleted
|
70
|
+
end
|
71
|
+
|
72
|
+
action do |index, work_tree, path|
|
73
|
+
['checkout --', path]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'unstage files'
|
78
|
+
command :unstage do
|
79
|
+
applies_to do |index, work_tree|
|
80
|
+
index == :modified || index == :deleted || index == :added
|
81
|
+
end
|
82
|
+
|
83
|
+
action do |index, work_tree, path|
|
84
|
+
['reset HEAD --', path]
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'git_shizzle'
|
5
|
+
|
6
|
+
module GitShizzle
|
7
|
+
class Cli < Thor
|
8
|
+
package_name 'GitShizzle'
|
9
|
+
|
10
|
+
commands = GitShizzle::Dsl::CommandCollection.new
|
11
|
+
commands.load
|
12
|
+
|
13
|
+
commands.each do |command|
|
14
|
+
desc "#{command.identifier}", "#{command.description} by index or range"
|
15
|
+
define_method(command.identifier) do |*indexes|
|
16
|
+
begin
|
17
|
+
shizzle.send(:run, command.identifier, *indexes)
|
18
|
+
rescue GitShizzle::Error => e
|
19
|
+
puts e.message
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def shizzle
|
26
|
+
@shizzle ||= GitShizzle::QuickGit.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Dsl
|
4
|
+
class Command
|
5
|
+
attr_reader :identifier, :description
|
6
|
+
|
7
|
+
def initialize(identifier, description, block)
|
8
|
+
@identifier = identifier
|
9
|
+
@description = description
|
10
|
+
|
11
|
+
GitShizzle::Dsl::CommandContext.new(self).instance_eval &block
|
12
|
+
end
|
13
|
+
|
14
|
+
def applicable_files(git_status)
|
15
|
+
git_status.find_all do |file|
|
16
|
+
@filter.call(file.index_status, file.work_tree_status, file.path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def invoke(git, files)
|
21
|
+
raise GitShizzle::IndexSpecifications::NoFilesError.new(@identifier) if files.empty?
|
22
|
+
|
23
|
+
files.
|
24
|
+
map { |file| @action.call(file.index_status, file.work_tree_status, file.path) }.
|
25
|
+
group_by { |group| group[0] }.
|
26
|
+
each_pair { |command, command_paths| git.command command, paths_for(command_paths) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def paths_for(command_paths)
|
30
|
+
command_paths.map { |a| a[1] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_filter(block)
|
34
|
+
@filter = block
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_action(block)
|
38
|
+
@action = block
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Dsl
|
4
|
+
class CommandCollection
|
5
|
+
def initialize
|
6
|
+
@commands = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_command(command)
|
10
|
+
raise DuplicateCommandDefinitionError.new(command) if @commands.any? { |c| c.identifier == command.identifier}
|
11
|
+
|
12
|
+
@commands << command
|
13
|
+
end
|
14
|
+
|
15
|
+
def load(contents = nil)
|
16
|
+
data = contents
|
17
|
+
|
18
|
+
unless data
|
19
|
+
filenames = ['commands', 'Commands', 'commands.rb', 'Commands.rb'].map do |f|
|
20
|
+
"#{File.dirname(__FILE__)}/../../#{f}"
|
21
|
+
end
|
22
|
+
filename = filenames.find { |f| File.file?(f) }
|
23
|
+
raise GitShizzle::Dsl::NoCommandFileFoundError.new if filename.nil?
|
24
|
+
|
25
|
+
data = File.read(filename)
|
26
|
+
end
|
27
|
+
|
28
|
+
dsl.instance_eval(data, "./#{filename}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def each(&block)
|
32
|
+
@commands.each do |command|
|
33
|
+
if block_given?
|
34
|
+
block.call command
|
35
|
+
else
|
36
|
+
yield command
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def find(identifier)
|
42
|
+
@commands.find { |c| c.identifier == identifier } or raise GitShizzle::Dsl::CommandNotFoundError.new(identifier)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def dsl
|
47
|
+
GitShizzle::Dsl::Dsl.new(self)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Dsl
|
4
|
+
class CommandContext
|
5
|
+
def initialize(command)
|
6
|
+
@command = command
|
7
|
+
end
|
8
|
+
|
9
|
+
def applies_to(&block)
|
10
|
+
raise CommandDefinitionError.new(@command, '#applies_to requires a block.') unless block_given?
|
11
|
+
@command.set_filter block
|
12
|
+
end
|
13
|
+
|
14
|
+
def action(&block)
|
15
|
+
raise CommandDefinitionError.new(@command, '#action requires a block.') unless block_given?
|
16
|
+
@command.set_action block
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Dsl
|
4
|
+
class CommandDefinitionError < GitShizzle::Error
|
5
|
+
def initialize(command_or_identifier, message)
|
6
|
+
if command_or_identifier.respond_to? :identifier
|
7
|
+
identifier = command_or_identifier.identifier
|
8
|
+
else
|
9
|
+
identifier = command_or_identifier
|
10
|
+
end
|
11
|
+
|
12
|
+
super "Command '#{identifier}': #{message}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Dsl
|
4
|
+
class Dsl
|
5
|
+
def initialize(commands)
|
6
|
+
@commands = commands
|
7
|
+
end
|
8
|
+
|
9
|
+
def desc(description)
|
10
|
+
@description = description
|
11
|
+
end
|
12
|
+
|
13
|
+
def command(identifier, &block)
|
14
|
+
raise CommandDefinitionError.new(identifier, '#command requires a block.') unless block_given?
|
15
|
+
|
16
|
+
command = Command.new(identifier, @description, block)
|
17
|
+
@commands.add_command(command)
|
18
|
+
|
19
|
+
reset_description
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def reset_description
|
24
|
+
@description = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Git
|
4
|
+
class File
|
5
|
+
attr_reader :status_line, :index_status, :work_tree_status, :path
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
@status_line = params[:status_line]
|
9
|
+
@path = params[:path]
|
10
|
+
@index_status = map params[:status][0]
|
11
|
+
@work_tree_status = map params[:status][1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
"Path: #{path}: work tree #{@work_tree_status}, index #{@index_status}"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def map(status_code)
|
20
|
+
case status_code
|
21
|
+
when '?'
|
22
|
+
:untracked
|
23
|
+
when 'M'
|
24
|
+
:modified
|
25
|
+
when 'A'
|
26
|
+
:added
|
27
|
+
when 'D'
|
28
|
+
:deleted
|
29
|
+
when 'C'
|
30
|
+
:copied
|
31
|
+
when 'R'
|
32
|
+
:renamed
|
33
|
+
when 'U'
|
34
|
+
:unmerged
|
35
|
+
when ' '
|
36
|
+
nil
|
37
|
+
else
|
38
|
+
raise "Unexpected file status code '#{status_code}' for file #{@path} (status line was: #{@status_line})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::Git
|
4
|
+
class GitExecuteError < GitShizzle::Error;
|
5
|
+
end
|
6
|
+
|
7
|
+
class Git
|
8
|
+
def initialize(repo_location)
|
9
|
+
@repo_location = repo_location
|
10
|
+
end
|
11
|
+
|
12
|
+
def status
|
13
|
+
Dir.chdir(@repo_location) do
|
14
|
+
status = command 'status --porcelain -z', [], :verbose => false, :redirect_io => true
|
15
|
+
status
|
16
|
+
.each_line("\x00")
|
17
|
+
.select { |line| line =~ /^[\p{Lu}\x20\?!]{2}\s/ }
|
18
|
+
.each_with_index.map do |line, index|
|
19
|
+
File.new(:index => index,
|
20
|
+
:status => line[0..1],
|
21
|
+
:path => line[3..-1].delete("\000"),
|
22
|
+
:status_line => line)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def command(cmd, opts = [], params = { }, &block)
|
28
|
+
opts = [opts].flatten.map { |s| escape(s) }.join(' ')
|
29
|
+
|
30
|
+
git_cmd = "git #{cmd} #{opts}"
|
31
|
+
echo git_cmd, params.fetch(:verbose, true)
|
32
|
+
|
33
|
+
out = run_command(git_cmd, params, &block)
|
34
|
+
|
35
|
+
if $?.exitstatus > 0
|
36
|
+
if $?.exitstatus == 1 && out == ''
|
37
|
+
return ''
|
38
|
+
end
|
39
|
+
raise GitShizzle::Git::GitExecuteError.new(git_cmd + ':' + out.to_s)
|
40
|
+
end
|
41
|
+
out
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def escape(s)
|
46
|
+
escaped = s.to_s.gsub('\'', '\'\\\'\'')
|
47
|
+
%Q{"#{escaped}"}
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_command(git_cmd, params = { }, &block)
|
51
|
+
if block_given?
|
52
|
+
IO.popen(git_cmd, &block)
|
53
|
+
else
|
54
|
+
if params.fetch(:redirect_io, false)
|
55
|
+
git_cmd += ' 2>&1'
|
56
|
+
`#{git_cmd}`.chomp
|
57
|
+
else
|
58
|
+
system git_cmd
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def echo(msg, verbose)
|
64
|
+
puts(msg) if verbose && defined?(Thor)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module GitShizzle::IndexSpecifications
|
4
|
+
class Base
|
5
|
+
def include?(index)
|
6
|
+
false
|
7
|
+
end
|
8
|
+
|
9
|
+
def register_match(index)
|
10
|
+
matches << index
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches
|
14
|
+
@matches ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def unmatched
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def assert_numeric(index, *spec)
|
22
|
+
spec << index if spec.empty?
|
23
|
+
|
24
|
+
all_numeric = spec.all? { |s|
|
25
|
+
s.is_a? Numeric or /\d+/.match(s)
|
26
|
+
}
|
27
|
+
|
28
|
+
raise IndexParserError.new(index) unless all_numeric
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|