blob: bf1e192cf35736ee2e1a95041903d808784039d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/usr/bin/env ruby
# This is a command line client that can do a number of read operations
# on a git repository in pure ruby. This may be helpful if you have access
# to a computer that has no C compiler but you want to do some git stuff
# on it. It's also helpful for me to test Git stuff with.
#
# author : Scott Chacon (schacon@gmail.com)
#
# todo:
# add --git-dir
# add --log-file
# add --help
require 'lib/git'
#require 'rubygems'
#require 'git'
require 'logger'
command = ARGV[0]
if !command
puts 'You have to provide a command'
puts 'usage: gitr (command) [args]'
puts
puts 'commands: log'
puts ' log-shas'
puts ' cat-file (treeish)'
puts ' rev-parse (treeish)'
puts ' branches'
puts ' config'
puts ' ls-tree (tree)'
exit
end
git_dir = ENV['GIT_DIR'] || '.git'
#@git = Git.bare(git_dir, :log => Logger.new(STDOUT))
@git = Git.bare(git_dir)
case command
when 'log'
# gitr log
@git.log.each do |l|
puts 'commit ' + l.sha
puts l.contents
puts
end
when 'log-shas'
# gitr log-shas
puts @git.log
when 'cat-file'
# gitr cat-file
puts @git.cat_file(ARGV[1])
when 'rev-parse'
# gitr rev-parse
puts @git.revparse(ARGV[1])
when 'branches'
# gitr branches
puts @git.branches
when 'config'
# gitr config
@git.config.sort.each do |k,v|
puts "#{k} : #{v}"
end
when 'ls-tree'
# gitr ls-tree
tree = @git.gtree(ARGV[1])
tree.blobs.sort.each do |name, c|
puts [[c.mode, c.type, c.sha].join(" "), name].join("\t")
end
tree.trees.sort.each do |name, c|
puts [[c.mode, c.type, c.sha].join(" "), name].join("\t")
end
end
# todo:
# gitr pack-browse
# gitr diff / stats ?
|