added ls-tree to gitr
[rubygit.git] / bin / gitr
blobbf1e192cf35736ee2e1a95041903d808784039d7
1 #!/usr/bin/env ruby
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)
10 # todo:
11 # add --git-dir
12 # add --log-file
13 # add --help
15 require 'lib/git'
16 #require 'rubygems'
17 #require 'git'
18 require 'logger'
20 command = ARGV[0]
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 (treeish)'
29 puts ' rev-parse (treeish)'
30 puts ' branches'
31 puts ' config'
32 puts ' ls-tree (tree)'
33 exit
34 end
36 git_dir = ENV['GIT_DIR'] || '.git'
37 #@git = Git.bare(git_dir, :log => Logger.new(STDOUT))
38 @git = Git.bare(git_dir)
40 case command
41 when 'log'
42 # gitr log
43 @git.log.each do |l|
44 puts 'commit ' + l.sha
45 puts l.contents
46 puts
47 end
48 when 'log-shas'
49 # gitr log-shas
50 puts @git.log
51 when 'cat-file'
52 # gitr cat-file
53 puts @git.cat_file(ARGV[1])
54 when 'rev-parse'
55 # gitr rev-parse
56 puts @git.revparse(ARGV[1])
57 when 'branches'
58 # gitr branches
59 puts @git.branches
60 when 'config'
61 # gitr config
62 @git.config.sort.each do |k,v|
63 puts "#{k} : #{v}"
64 end
65 when 'ls-tree'
66 # gitr ls-tree
67 tree = @git.gtree(ARGV[1])
68 tree.blobs.sort.each do |name, c|
69 puts [[c.mode, c.type, c.sha].join(" "), name].join("\t")
70 end
71 tree.trees.sort.each do |name, c|
72 puts [[c.mode, c.type, c.sha].join(" "), name].join("\t")
73 end
74 end
76 # todo:
77 # gitr pack-browse
78 # gitr diff / stats ?