File tree Expand file tree Collapse file tree 4 files changed +88
-2
lines changed Expand file tree Collapse file tree 4 files changed +88
-2
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is a command line client that can do a number of read operations
4
+ # on a git repository in pure ruby. This may be helpful if you have access
5
+ # to a computer that has no C compiler but you want to do some git stuff
6
+ # on it. It's also helpful for me to test Git stuff with.
7
+ #
8
+ # author : Scott Chacon (schacon@gmail.com)
9
+ #
10
+ # todo:
11
+ # add --git-dir
12
+ # add --log-file
13
+ # add --help
14
+
15
+ #require 'lib/git'
16
+ require 'rubygems'
17
+ require 'git'
18
+ require 'logger'
19
+
20
+ command = ARGV [ 0 ]
21
+
22
+ if !command
23
+ puts 'You have to provide a command'
24
+ puts 'usage: gitr (command) [args]'
25
+ puts
26
+ puts 'commands: log'
27
+ puts ' log-shas'
28
+ puts ' cat-file'
29
+ puts ' rev-parse'
30
+ puts ' branches'
31
+ puts ' config'
32
+ exit
33
+ end
34
+
35
+ git_dir = ENV [ 'GIT_DIR' ] || '.git'
36
+ @git = Git . bare ( git_dir , :log => Logger . new ( STDOUT ) )
37
+
38
+ case command
39
+ when 'log'
40
+ # gitr log
41
+ @git . log . each do |l |
42
+ puts 'commit ' + l . sha
43
+ puts l . contents
44
+ puts
45
+ end
46
+ when 'log-shas'
47
+ # gitr log-shas
48
+ puts @git . log
49
+ when 'cat-file'
50
+ # gitr cat-file
51
+ puts @git . cat_file ( ARGV [ 1 ] )
52
+ when 'rev-parse'
53
+ # gitr rev-parse
54
+ puts @git . revparse ( ARGV [ 1 ] )
55
+ when 'branches'
56
+ # gitr branches
57
+ puts @git . branches
58
+ when 'config'
59
+ # gitr config
60
+ @git . config . sort . each do |k , v |
61
+ puts "#{ k } : #{ v } "
62
+ end
63
+ end
64
+
65
+ # gitr ls-tree
66
+ # gitr pack-browse
67
+
68
+ # gitr diff / stats ?
69
+ # output in yaml?
Original file line number Diff line number Diff line change @@ -429,6 +429,10 @@ def revparse(objectish)
429
429
self . lib . revparse ( objectish )
430
430
end
431
431
432
+ def cat_file ( objectish )
433
+ self . lib . object_contents ( objectish )
434
+ end
435
+
432
436
# returns the name of the branch the working directory is currently on
433
437
def current_branch
434
438
self . lib . branch_current
Original file line number Diff line number Diff line change @@ -41,5 +41,17 @@ def [](symbol)
41
41
@branches [ symbol . to_s ]
42
42
end
43
43
44
+ def to_s
45
+ out = ''
46
+ @branches . each do |k , b |
47
+ if b . current
48
+ out += "* " + b . to_s + "\n "
49
+ else
50
+ out += " " + b . to_s + "\n "
51
+ end
52
+ end
53
+ out
54
+ end
55
+
44
56
end
45
57
end
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ def full_log_commits(opts = {})
81
81
sha = revparse ( opts [ :object ] || branch_current || 'master' )
82
82
count = opts [ :count ] || 30
83
83
84
- repo = Git :: Raw :: Repository . new ( @git_dir )
84
+ repo = get_raw_repo
85
85
return process_commit_data ( repo . log ( sha , count ) )
86
86
end
87
87
@@ -182,7 +182,8 @@ def process_commit_data(data, sha = nil)
182
182
end
183
183
184
184
def object_contents ( sha )
185
- command ( 'cat-file' , [ '-p' , sha ] )
185
+ #command('cat-file', ['-p', sha])
186
+ get_raw_repo . cat_file ( revparse ( sha ) )
186
187
end
187
188
188
189
def ls_tree ( sha )
You can’t perform that action at this time.
0 commit comments