git_wrapper 1.0.2 → 1.0.3

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 (36) hide show
  1. data/README.md +74 -74
  2. data/git_wrapper.gemspec +21 -21
  3. data/lib/git_wrapper/commands/add.rb +20 -20
  4. data/lib/git_wrapper/commands/branch.rb +72 -72
  5. data/lib/git_wrapper/commands/checkout.rb +20 -20
  6. data/lib/git_wrapper/commands/commit.rb +20 -20
  7. data/lib/git_wrapper/commands/config.rb +25 -25
  8. data/lib/git_wrapper/commands/diff.rb +27 -27
  9. data/lib/git_wrapper/commands/fetch.rb +20 -20
  10. data/lib/git_wrapper/commands/git.rb +43 -43
  11. data/lib/git_wrapper/commands/init.rb +15 -15
  12. data/lib/git_wrapper/commands/log.rb +81 -81
  13. data/lib/git_wrapper/commands/merge.rb +15 -15
  14. data/lib/git_wrapper/commands/pull.rb +20 -20
  15. data/lib/git_wrapper/commands/push.rb +26 -26
  16. data/lib/git_wrapper/commands/remote.rb +48 -48
  17. data/lib/git_wrapper/commands/remove.rb +15 -15
  18. data/lib/git_wrapper/commands/reset.rb +35 -35
  19. data/lib/git_wrapper/commands/revert.rb +22 -22
  20. data/lib/git_wrapper/commands/shell.rb +66 -66
  21. data/lib/git_wrapper/commands/show.rb +39 -39
  22. data/lib/git_wrapper/commands/status.rb +16 -16
  23. data/lib/git_wrapper/commands/tag.rb +53 -53
  24. data/lib/git_wrapper/repository.rb +208 -208
  25. data/lib/git_wrapper/results/diff_name_status.rb +27 -27
  26. data/lib/git_wrapper/results/file_status.rb +21 -21
  27. data/lib/git_wrapper/results/log_info.rb +22 -22
  28. data/lib/git_wrapper/results/status_porcelain.rb +39 -39
  29. data/lib/git_wrapper/version.rb +3 -3
  30. data/lib/git_wrapper.rb +46 -44
  31. data/spec/repository_spec.rb +888 -888
  32. data/spec/spec_helper.rb +9 -9
  33. data/spec/status_porcelain_parser_spec.rb +86 -86
  34. data/spec/support/helpers/file_helper.rb +40 -36
  35. data/spec/support/matchers/git_status_matchers.rb +39 -39
  36. metadata +17 -7
@@ -1,209 +1,209 @@
1
- module GitWrapper
2
- class Repository
3
- attr_reader :location
4
- attr_reader :log_output
5
- attr_reader :log_error
6
-
7
- def initialize(location)
8
- @location = location
9
- @log_output = []
10
- @log_error = []
11
- end
12
-
13
- def init
14
- FileUtils.mkpath(@location) unless Dir.exist?(@location)
15
- execute(Commands::Init.new(@location))
16
- end
17
-
18
- def init_bare
19
- FileUtils.mkpath(@location) unless Dir.exist?(@location)
20
- execute(Commands::Init.new(@location).bare)
21
- end
22
-
23
- def initialized?
24
- Dir.exist?("#{@location}/.git") || bare?
25
- end
26
-
27
- def bare?
28
- Dir.exist?("#{@location}/hooks") &&
29
- Dir.exist?("#{@location}/info") &&
30
- Dir.exist?("#{@location}/objects") &&
31
- Dir.exist?("#{@location}/refs")
32
- end
33
-
34
- def status
35
- execute(Commands::Status.new(@location))
36
- end
37
-
38
- def add(file_name)
39
- execute(Commands::Add.new(@location).file(file_name))
40
- end
41
-
42
- def add_all
43
- execute(Commands::Add.new(@location).all)
44
- end
45
-
46
- def commit(message, options={})
47
- command = Commands::Commit.new(@location).message(message)
48
- command.author(options[:author_name], options[:author_email]) if options[:author_name] && options[:author_email]
49
- execute(command)
50
- end
51
-
52
- def remove(file_name)
53
- execute(Commands::Remove.new(@location).file(file_name))
54
- end
55
-
56
- def remotes
57
- execute(Commands::Remote.new(@location).list)
58
- end
59
-
60
- def add_remote(name, url)
61
- execute(Commands::Remote.new(@location).name(name).add(url))
62
- end
63
-
64
- def remove_remote(name)
65
- execute(Commands::Remote.new(@location).name(name).remove)
66
- end
67
-
68
- def pull(remote='origin', branch='master')
69
- execute(Commands::Pull.new(@location).remote(remote).branch(branch))
70
- end
71
-
72
- def push(remote='origin', branch='master')
73
- execute(Commands::Push.new(@location).remote(remote).branch(branch))
74
- end
75
-
76
- def push_tags(remote='origin')
77
- execute(Commands::Push.new(@location).remote(remote).tags)
78
- end
79
-
80
- def show(file_name, commit=nil)
81
- command = Commands::Show.new(@location).file(file_name)
82
- command.commit(commit) unless commit.nil?
83
- execute(command)
84
- end
85
-
86
- def show_base(file_name)
87
- execute(Commands::Show.new(@location).file(file_name).base)
88
- end
89
-
90
- def show_mine(file_name)
91
- execute(Commands::Show.new(@location).file(file_name).mine)
92
- end
93
-
94
- def show_theirs(file_name)
95
- execute(Commands::Show.new(@location).file(file_name).theirs)
96
- end
97
-
98
- def log(options={})
99
- if options[:file_name]
100
- execute(Commands::Log.new(@location).file(options[:file_name]))
101
- elsif options[:commit]
102
- execute(Commands::Log.new(@location).commit(options[:commit]))
103
- else
104
- execute(Commands::Log.new(@location))
105
- end
106
- end
107
-
108
- def branches
109
- execute(Commands::Branch.new(@location).list)
110
- end
111
-
112
- def current_branch
113
- branch = execute(Commands::Branch.new(@location).current)
114
- branch.nil? ? 'master' : branch
115
- end
116
-
117
- def branch(name, commit=nil)
118
- if commit.nil?
119
- execute(Commands::Branch.new(@location).create(name))
120
- else
121
- execute(Commands::Branch.new(@location).create(name).from(commit))
122
- end
123
- end
124
-
125
- def remove_branch(name, remote=nil)
126
- if remote.nil?
127
- execute(Commands::Branch.new(@location).remove(name))
128
- else
129
- execute(Commands::Branch.new(@location).remove(name).remote(remote))
130
- end
131
- end
132
-
133
- def checkout(commit, new_branch=nil)
134
- if commit.nil?
135
- execute(Commands::Checkout.new(@location).commit(commit))
136
- else
137
- execute(Commands::Checkout.new(@location).commit(commit).into(new_branch))
138
- end
139
- end
140
-
141
- def tags
142
- execute(Commands::Tag.new(@location).list)
143
- end
144
-
145
- def tag(name, commit=nil)
146
- if commit.nil?
147
- execute(Commands::Tag.new(@location).create(name))
148
- else
149
- execute(Commands::Tag.new(@location).create(name).from(commit))
150
- end
151
- end
152
-
153
- def remove_tag(name)
154
- execute(Commands::Tag.new(@location).remove(name))
155
- end
156
-
157
- def merge(commit)
158
- execute(Commands::Merge.new(@location).commit(commit))
159
- end
160
-
161
- def fetch(remote=nil)
162
- if remote.nil?
163
- execute(Commands::Fetch.new(@location).all)
164
- else
165
- execute(Commands::Fetch.new(@location).remote(remote))
166
- end
167
- end
168
-
169
- def diff(commit)
170
- execute(Commands::Diff.new(@location).with(commit))
171
- end
172
-
173
- def diff_reverse(commit)
174
- execute(Commands::Diff.new(@location).with(commit).reverse)
175
- end
176
-
177
- def revert(commit)
178
- if log(:commit => commit).merge?
179
- execute(Commands::Revert.new(@location).merge(commit))
180
- else
181
- execute(Commands::Revert.new(@location).commit(commit))
182
- end
183
- end
184
-
185
- def reset(options={})
186
- command = Commands::Reset.new(@location)
187
- command.commit(options[:commit]) if options[:commit]
188
- command.send(options[:mode]) if options[:mode]
189
- execute(command)
190
- end
191
-
192
- def config(key=nil, value=nil)
193
- command = Commands::Config.new(@location)
194
- command.key(key) if key
195
- command.value(value) if value
196
- execute(command)
197
- end
198
-
199
- private
200
-
201
- def execute(command)
202
- result = command.execute
203
- @log_output << command.output
204
- @log_error << command.error
205
- result
206
- end
207
-
208
- end
1
+ module GitWrapper
2
+ class Repository
3
+ attr_reader :location
4
+ attr_reader :log_output
5
+ attr_reader :log_error
6
+
7
+ def initialize(location)
8
+ @location = location
9
+ @log_output = []
10
+ @log_error = []
11
+ end
12
+
13
+ def init
14
+ FileUtils.mkpath(@location) unless Dir.exist?(@location)
15
+ execute(Commands::Init.new(@location))
16
+ end
17
+
18
+ def init_bare
19
+ FileUtils.mkpath(@location) unless Dir.exist?(@location)
20
+ execute(Commands::Init.new(@location).bare)
21
+ end
22
+
23
+ def initialized?
24
+ Dir.exist?("#{@location}/.git") || bare?
25
+ end
26
+
27
+ def bare?
28
+ Dir.exist?("#{@location}/hooks") &&
29
+ Dir.exist?("#{@location}/info") &&
30
+ Dir.exist?("#{@location}/objects") &&
31
+ Dir.exist?("#{@location}/refs")
32
+ end
33
+
34
+ def status
35
+ execute(Commands::Status.new(@location))
36
+ end
37
+
38
+ def add(file_name)
39
+ execute(Commands::Add.new(@location).file(file_name))
40
+ end
41
+
42
+ def add_all
43
+ execute(Commands::Add.new(@location).all)
44
+ end
45
+
46
+ def commit(message, options={})
47
+ command = Commands::Commit.new(@location).message(message)
48
+ command.author(options[:author_name], options[:author_email]) if options[:author_name] && options[:author_email]
49
+ execute(command)
50
+ end
51
+
52
+ def remove(file_name)
53
+ execute(Commands::Remove.new(@location).file(file_name))
54
+ end
55
+
56
+ def remotes
57
+ execute(Commands::Remote.new(@location).list)
58
+ end
59
+
60
+ def add_remote(name, url)
61
+ execute(Commands::Remote.new(@location).name(name).add(url))
62
+ end
63
+
64
+ def remove_remote(name)
65
+ execute(Commands::Remote.new(@location).name(name).remove)
66
+ end
67
+
68
+ def pull(remote='origin', branch='master')
69
+ execute(Commands::Pull.new(@location).remote(remote).branch(branch))
70
+ end
71
+
72
+ def push(remote='origin', branch='master')
73
+ execute(Commands::Push.new(@location).remote(remote).branch(branch))
74
+ end
75
+
76
+ def push_tags(remote='origin')
77
+ execute(Commands::Push.new(@location).remote(remote).tags)
78
+ end
79
+
80
+ def show(file_name, commit=nil)
81
+ command = Commands::Show.new(@location).file(file_name)
82
+ command.commit(commit) unless commit.nil?
83
+ execute(command)
84
+ end
85
+
86
+ def show_base(file_name)
87
+ execute(Commands::Show.new(@location).file(file_name).base)
88
+ end
89
+
90
+ def show_mine(file_name)
91
+ execute(Commands::Show.new(@location).file(file_name).mine)
92
+ end
93
+
94
+ def show_theirs(file_name)
95
+ execute(Commands::Show.new(@location).file(file_name).theirs)
96
+ end
97
+
98
+ def log(options={})
99
+ if options[:file_name]
100
+ execute(Commands::Log.new(@location).file(options[:file_name]))
101
+ elsif options[:commit]
102
+ execute(Commands::Log.new(@location).commit(options[:commit]))
103
+ else
104
+ execute(Commands::Log.new(@location))
105
+ end
106
+ end
107
+
108
+ def branches
109
+ execute(Commands::Branch.new(@location).list)
110
+ end
111
+
112
+ def current_branch
113
+ branch = execute(Commands::Branch.new(@location).current)
114
+ branch.nil? ? 'master' : branch
115
+ end
116
+
117
+ def branch(name, commit=nil)
118
+ if commit.nil?
119
+ execute(Commands::Branch.new(@location).create(name))
120
+ else
121
+ execute(Commands::Branch.new(@location).create(name).from(commit))
122
+ end
123
+ end
124
+
125
+ def remove_branch(name, remote=nil)
126
+ if remote.nil?
127
+ execute(Commands::Branch.new(@location).remove(name))
128
+ else
129
+ execute(Commands::Branch.new(@location).remove(name).remote(remote))
130
+ end
131
+ end
132
+
133
+ def checkout(commit, new_branch=nil)
134
+ if commit.nil?
135
+ execute(Commands::Checkout.new(@location).commit(commit))
136
+ else
137
+ execute(Commands::Checkout.new(@location).commit(commit).into(new_branch))
138
+ end
139
+ end
140
+
141
+ def tags
142
+ execute(Commands::Tag.new(@location).list)
143
+ end
144
+
145
+ def tag(name, commit=nil)
146
+ if commit.nil?
147
+ execute(Commands::Tag.new(@location).create(name))
148
+ else
149
+ execute(Commands::Tag.new(@location).create(name).from(commit))
150
+ end
151
+ end
152
+
153
+ def remove_tag(name)
154
+ execute(Commands::Tag.new(@location).remove(name))
155
+ end
156
+
157
+ def merge(commit)
158
+ execute(Commands::Merge.new(@location).commit(commit))
159
+ end
160
+
161
+ def fetch(remote=nil)
162
+ if remote.nil?
163
+ execute(Commands::Fetch.new(@location).all)
164
+ else
165
+ execute(Commands::Fetch.new(@location).remote(remote))
166
+ end
167
+ end
168
+
169
+ def diff(commit)
170
+ execute(Commands::Diff.new(@location).with(commit))
171
+ end
172
+
173
+ def diff_reverse(commit)
174
+ execute(Commands::Diff.new(@location).with(commit).reverse)
175
+ end
176
+
177
+ def revert(commit)
178
+ if log(:commit => commit).merge?
179
+ execute(Commands::Revert.new(@location).merge(commit))
180
+ else
181
+ execute(Commands::Revert.new(@location).commit(commit))
182
+ end
183
+ end
184
+
185
+ def reset(options={})
186
+ command = Commands::Reset.new(@location)
187
+ command.commit(options[:commit]) if options[:commit]
188
+ command.send(options[:mode]) if options[:mode]
189
+ execute(command)
190
+ end
191
+
192
+ def config(key=nil, value=nil)
193
+ command = Commands::Config.new(@location)
194
+ command.key(key) if key
195
+ command.value(value) if value
196
+ execute(command)
197
+ end
198
+
199
+ private
200
+
201
+ def execute(command)
202
+ result = command.execute
203
+ @log_output << command.output
204
+ @log_error << command.error
205
+ result
206
+ end
207
+
208
+ end
209
209
  end
@@ -1,28 +1,28 @@
1
- module GitWrapper
2
- module Results
3
- class DiffNameStatus
4
- attr_reader :file_name
5
- attr_reader :status
6
-
7
- def initialize(file_name, status)
8
- @file_name = file_name
9
- @status = status
10
- end
11
-
12
- def self.parse(text)
13
- DiffNameStatus.new parse_file_name(text), parse_status(text)
14
- end
15
-
16
- private
17
-
18
- def self.parse_file_name(text)
19
- text[1..text.length].strip
20
- end
21
-
22
- def self.parse_status(text)
23
- FileStatus.value_of text[0]
24
- end
25
-
26
- end
27
- end
1
+ module GitWrapper
2
+ module Results
3
+ class DiffNameStatus
4
+ attr_reader :file_name
5
+ attr_reader :status
6
+
7
+ def initialize(file_name, status)
8
+ @file_name = file_name
9
+ @status = status
10
+ end
11
+
12
+ def self.parse(text)
13
+ DiffNameStatus.new parse_file_name(text), parse_status(text)
14
+ end
15
+
16
+ private
17
+
18
+ def self.parse_file_name(text)
19
+ text[1..text.length].strip
20
+ end
21
+
22
+ def self.parse_status(text)
23
+ FileStatus.value_of text[0]
24
+ end
25
+
26
+ end
27
+ end
28
28
  end
@@ -1,22 +1,22 @@
1
- module GitWrapper
2
- module Results
3
- module FileStatus
4
- STATUSES = {
5
- 'A' => :new_file,
6
- 'M' => :modified,
7
- 'D' => :deleted,
8
- 'R' => :renamed,
9
- 'UU' => :merge_conflict,
10
- 'AA' => :merge_conflict,
11
- 'C' => :copied,
12
- 'T' => :type_changed,
13
- 'X' => :unknown
14
- }
15
-
16
- def self.value_of(char)
17
- return :untracked unless STATUSES.key?(char)
18
- STATUSES[char]
19
- end
20
- end
21
- end
1
+ module GitWrapper
2
+ module Results
3
+ module FileStatus
4
+ STATUSES = {
5
+ 'A' => :new_file,
6
+ 'M' => :modified,
7
+ 'D' => :deleted,
8
+ 'R' => :renamed,
9
+ 'UU' => :merge_conflict,
10
+ 'AA' => :merge_conflict,
11
+ 'C' => :copied,
12
+ 'T' => :type_changed,
13
+ 'X' => :unknown
14
+ }
15
+
16
+ def self.value_of(char)
17
+ return :untracked unless STATUSES.key?(char)
18
+ STATUSES[char]
19
+ end
20
+ end
21
+ end
22
22
  end
@@ -1,23 +1,23 @@
1
- module GitWrapper
2
- module Results
3
- class LogInfo
4
- def initialize(attributes)
5
- attributes.each do |name, value|
6
- define_singleton_method name, lambda { value }
7
- end
8
- end
9
-
10
- def parents
11
- parent_hashes.split
12
- end
13
-
14
- def abbreviated_parents
15
- abbreviated_parent_hashes.split
16
- end
17
-
18
- def merge?
19
- parents.length == 2
20
- end
21
- end
22
- end
1
+ module GitWrapper
2
+ module Results
3
+ class LogInfo
4
+ def initialize(attributes)
5
+ attributes.each do |name, value|
6
+ define_singleton_method name, lambda { value }
7
+ end
8
+ end
9
+
10
+ def parents
11
+ parent_hashes.split
12
+ end
13
+
14
+ def abbreviated_parents
15
+ abbreviated_parent_hashes.split
16
+ end
17
+
18
+ def merge?
19
+ parents.length == 2
20
+ end
21
+ end
22
+ end
23
23
  end
@@ -1,40 +1,40 @@
1
- module GitWrapper
2
- module Results
3
- class StatusPorcelain
4
- attr_reader :file_name
5
- attr_reader :original_file_name
6
- attr_reader :status
7
- attr_reader :staged_for_commit
8
-
9
- def initialize(file_name, original_file_name, status, staged_for_commit)
10
- @file_name = file_name
11
- @original_file_name = original_file_name
12
- @status = status
13
- @staged_for_commit = staged_for_commit
14
- end
15
-
16
- def self.parse(text)
17
- StatusPorcelain.new parse_file_name(text), parse_original_file_name(text), parse_status(text), parse_staged_for_commit(text)
18
- end
19
-
20
- private
21
-
22
- def self.parse_file_name(text)
23
- text[3..text.length].gsub("\"", "").split(' -> ').last
24
- end
25
-
26
- def self.parse_original_file_name(text)
27
- text[3..text.length].gsub("\"", "").split(' -> ').first
28
- end
29
-
30
- def self.parse_status(text)
31
- FileStatus.value_of text[0..2].strip
32
- end
33
-
34
- def self.parse_staged_for_commit(text)
35
- text[1..2].strip.empty?
36
- end
37
-
38
- end
39
- end
1
+ module GitWrapper
2
+ module Results
3
+ class StatusPorcelain
4
+ attr_reader :file_name
5
+ attr_reader :original_file_name
6
+ attr_reader :status
7
+ attr_reader :staged_for_commit
8
+
9
+ def initialize(file_name, original_file_name, status, staged_for_commit)
10
+ @file_name = file_name
11
+ @original_file_name = original_file_name
12
+ @status = status
13
+ @staged_for_commit = staged_for_commit
14
+ end
15
+
16
+ def self.parse(text)
17
+ StatusPorcelain.new parse_file_name(text), parse_original_file_name(text), parse_status(text), parse_staged_for_commit(text)
18
+ end
19
+
20
+ private
21
+
22
+ def self.parse_file_name(text)
23
+ text[3..text.length].gsub("\"", "").split(' -> ').last
24
+ end
25
+
26
+ def self.parse_original_file_name(text)
27
+ text[3..text.length].gsub("\"", "").split(' -> ').first
28
+ end
29
+
30
+ def self.parse_status(text)
31
+ FileStatus.value_of text[0..2].strip
32
+ end
33
+
34
+ def self.parse_staged_for_commit(text)
35
+ text[1..2].strip.empty?
36
+ end
37
+
38
+ end
39
+ end
40
40
  end
@@ -1,3 +1,3 @@
1
- module GitWrapper
2
- VERSION = '1.0.2'
3
- end
1
+ module GitWrapper
2
+ VERSION = '1.0.3'
3
+ end