Skip to content

Commit d6c06bd

Browse files
Adding Git::show support
closes ruby-git#164
1 parent 8a48065 commit d6c06bd

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ Here are the operations that need read permission only.
149149
g.config # returns whole config hash
150150

151151
g.tags # returns array of Git::Tag objects
152+
153+
g.show()
154+
g.show('HEAD')
155+
g.show('v2.8', 'README.md')
152156
```
153157

154158
And here are the operations that will need to write to your git repository.

lib/git/base.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ def apply(file)
421421
def apply_mail(file)
422422
self.lib.apply_mail(file) if File.exist?(file)
423423
end
424+
425+
# Shows objects
426+
#
427+
# @param [String|NilClass] objectish the target object reference (nil == HEAD)
428+
# @param [String|NilClass] path the path of the file to be shown
429+
# @return [String] the object information
430+
def show(objectish=nil, path=nil)
431+
self.lib.show(objectish, path)
432+
end
424433

425434
## LOWER LEVEL INDEX OPERATIONS ##
426435

lib/git/lib.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ def clone(repository, name, opts = {})
6161
clone_dir = opts[:path] ? File.join(@path, name) : name
6262

6363
arr_opts = []
64-
arr_opts << "--bare" if opts[:bare]
65-
arr_opts << "--branch" << opts[:branch] if opts[:branch]
66-
arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0
67-
arr_opts << "--config" << opts[:config] if opts[:config]
68-
arr_opts << "--origin" << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin]
69-
arr_opts << "--recursive" if opts[:recursive]
64+
arr_opts << '--bare' if opts[:bare]
65+
arr_opts << '--branch' << opts[:branch] if opts[:branch]
66+
arr_opts << '--depth' << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0
67+
arr_opts << '--config' << opts[:config] if opts[:config]
68+
arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin]
69+
arr_opts << '--recursive' if opts[:recursive]
7070

7171
arr_opts << '--'
7272

@@ -439,6 +439,19 @@ def parse_config_list(lines)
439439
def parse_config(file)
440440
parse_config_list command_lines('config', ['--list', '--file', file], false)
441441
end
442+
443+
# Shows objects
444+
#
445+
# @param [String|NilClass] objectish the target object reference (nil == HEAD)
446+
# @param [String|NilClass] path the path of the file to be shown
447+
# @return [String] the object information
448+
def show(objectish=nil, path=nil)
449+
arr_opts = []
450+
451+
arr_opts << (path ? "#{objectish}:#{path}" : objectish)
452+
453+
command('show', arr_opts.compact)
454+
end
442455

443456
## WRITE COMMANDS ##
444457

tests/units/test_lib.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,10 @@ def test_grep
199199
assert_equal(2, match.size)
200200
end
201201

202+
def test_show
203+
assert(/^commit 5e53019b3238362144c2766f02a2c00d91fcc023.+\+replace with new text - diff test$/m.match(@lib.show))
204+
assert(/^commit 935badc874edd62a8629aaf103418092c73f0a56.+\+nothing!$/m.match(@lib.show('gitsearch1')))
205+
assert(/^hello.+nothing!$/m.match(@lib.show('gitsearch1', 'scott/text.txt')))
206+
end
207+
202208
end

0 commit comments

Comments
 (0)