started the ruby-only command line git client
[rubygit.git] / bin / gitr
blob53c8055b92917125a386b4ba5ccc1a9c20677958
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'
29 puts ' rev-parse'
30 puts ' branches'
31 puts ' config'
32 exit
33 end
35 git_dir = ENV['GIT_DIR'] || '.git'
36 @git = Git.bare(git_dir, :log => Logger.new(STDOUT))
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
65 # gitr ls-tree
66 # gitr pack-browse
68 # gitr diff / stats ?
69 # output in yaml?