git-trip 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data.tar.gz.sig +2 -1
  2. data/History.txt +4 -0
  3. data/Manifest.txt +3 -56
  4. data/bin/git-trip +3 -0
  5. data/git-trip.gemspec +36 -0
  6. data/lib/git-trip.rb +3 -5
  7. data/lib/git-trip/errors.rb +1 -0
  8. data/lib/git-trip/gitter.rb +1 -0
  9. data/lib/git-trip/gitter/github.rb +68 -0
  10. data/lib/git-trip/gitter/uri.rb +27 -0
  11. data/spec/git-trip/errors_spec.rb +4 -0
  12. data/spec/git-trip/gitter/github_spec.rb +30 -0
  13. data/spec/git-trip/gitter/uri_spec.rb +4 -1
  14. data/spec/git-trip/gitter_spec.rb +8 -0
  15. metadata +5 -61
  16. metadata.gz.sig +0 -0
  17. data/vendor/grit/History.txt +0 -6
  18. data/vendor/grit/Manifest.txt +0 -53
  19. data/vendor/grit/README.txt +0 -213
  20. data/vendor/grit/Rakefile +0 -29
  21. data/vendor/grit/grit.gemspec +0 -16
  22. data/vendor/grit/lib/grit.rb +0 -37
  23. data/vendor/grit/lib/grit/actor.rb +0 -36
  24. data/vendor/grit/lib/grit/blob.rb +0 -117
  25. data/vendor/grit/lib/grit/commit.rb +0 -208
  26. data/vendor/grit/lib/grit/config.rb +0 -44
  27. data/vendor/grit/lib/grit/diff.rb +0 -70
  28. data/vendor/grit/lib/grit/errors.rb +0 -7
  29. data/vendor/grit/lib/grit/git.rb +0 -116
  30. data/vendor/grit/lib/grit/index.rb +0 -77
  31. data/vendor/grit/lib/grit/lazy.rb +0 -31
  32. data/vendor/grit/lib/grit/ref.rb +0 -110
  33. data/vendor/grit/lib/grit/repo.rb +0 -318
  34. data/vendor/grit/lib/grit/tree.rb +0 -99
  35. data/vendor/grit/test/fixtures/blame +0 -131
  36. data/vendor/grit/test/fixtures/cat_file_blob +0 -1
  37. data/vendor/grit/test/fixtures/cat_file_blob_size +0 -1
  38. data/vendor/grit/test/fixtures/diff_2 +0 -54
  39. data/vendor/grit/test/fixtures/diff_2f +0 -19
  40. data/vendor/grit/test/fixtures/diff_f +0 -15
  41. data/vendor/grit/test/fixtures/diff_i +0 -201
  42. data/vendor/grit/test/fixtures/diff_mode_only +0 -1152
  43. data/vendor/grit/test/fixtures/diff_new_mode +0 -17
  44. data/vendor/grit/test/fixtures/diff_p +0 -610
  45. data/vendor/grit/test/fixtures/for_each_ref +0 -0
  46. data/vendor/grit/test/fixtures/for_each_ref_remotes +0 -0
  47. data/vendor/grit/test/fixtures/for_each_ref_tags +0 -0
  48. data/vendor/grit/test/fixtures/ls_tree_a +0 -7
  49. data/vendor/grit/test/fixtures/ls_tree_b +0 -2
  50. data/vendor/grit/test/fixtures/ls_tree_commit +0 -3
  51. data/vendor/grit/test/fixtures/rev_list +0 -26
  52. data/vendor/grit/test/fixtures/rev_list_count +0 -655
  53. data/vendor/grit/test/fixtures/rev_list_single +0 -7
  54. data/vendor/grit/test/fixtures/rev_parse +0 -1
  55. data/vendor/grit/test/fixtures/show_empty_commit +0 -6
  56. data/vendor/grit/test/fixtures/simple_config +0 -2
  57. data/vendor/grit/test/helper.rb +0 -17
  58. data/vendor/grit/test/profile.rb +0 -21
  59. data/vendor/grit/test/suite.rb +0 -6
  60. data/vendor/grit/test/test_actor.rb +0 -35
  61. data/vendor/grit/test/test_blob.rb +0 -74
  62. data/vendor/grit/test/test_commit.rb +0 -182
  63. data/vendor/grit/test/test_config.rb +0 -58
  64. data/vendor/grit/test/test_diff.rb +0 -18
  65. data/vendor/grit/test/test_git.rb +0 -52
  66. data/vendor/grit/test/test_head.rb +0 -22
  67. data/vendor/grit/test/test_real.rb +0 -19
  68. data/vendor/grit/test/test_reality.rb +0 -17
  69. data/vendor/grit/test/test_remote.rb +0 -15
  70. data/vendor/grit/test/test_repo.rb +0 -278
  71. data/vendor/grit/test/test_tag.rb +0 -29
  72. data/vendor/grit/test/test_tree.rb +0 -91
@@ -1,208 +0,0 @@
1
- module Grit
2
-
3
- class Commit
4
- attr_reader :id
5
- lazy_reader :parents
6
- lazy_reader :tree
7
- lazy_reader :author
8
- lazy_reader :authored_date
9
- lazy_reader :committer
10
- lazy_reader :committed_date
11
- lazy_reader :message
12
- lazy_reader :short_message
13
-
14
- # Instantiate a new Commit
15
- # +id+ is the id of the commit
16
- # +parents+ is an array of commit ids (will be converted into Commit instances)
17
- # +tree+ is the correspdonding tree id (will be converted into a Tree object)
18
- # +author+ is the author string
19
- # +authored_date+ is the authored Time
20
- # +committer+ is the committer string
21
- # +committed_date+ is the committed Time
22
- # +message+ is an array of commit message lines
23
- #
24
- # Returns Grit::Commit (baked)
25
- def initialize(repo, id, parents, tree, author, authored_date, committer, committed_date, message)
26
- @repo = repo
27
- @id = id
28
- @parents = parents.map { |p| Commit.create(repo, :id => p) }
29
- @tree = Tree.create(repo, :id => tree)
30
- @author = author
31
- @authored_date = authored_date
32
- @committer = committer
33
- @committed_date = committed_date
34
- @message = message.join("\n")
35
- @short_message = message[0] || ''
36
- end
37
-
38
- def id_abbrev
39
- @id_abbrev ||= @repo.git.rev_parse({:short => true}, self.id).chomp
40
- end
41
-
42
- # Create an unbaked Commit containing just the specified attributes
43
- # +repo+ is the Repo
44
- # +atts+ is a Hash of instance variable data
45
- #
46
- # Returns Grit::Commit (unbaked)
47
- def self.create(repo, atts)
48
- self.allocate.create_initialize(repo, atts)
49
- end
50
-
51
- # Initializer for Commit.create
52
- # +repo+ is the Repo
53
- # +atts+ is a Hash of instance variable data
54
- #
55
- # Returns Grit::Commit (unbaked)
56
- def create_initialize(repo, atts)
57
- @repo = repo
58
- atts.each do |k, v|
59
- instance_variable_set("@#{k}", v)
60
- end
61
- self
62
- end
63
-
64
- def lazy_source
65
- self.class.find_all(@repo, @id, {:max_count => 1}).first
66
- end
67
-
68
- # Count the number of commits reachable from this ref
69
- # +repo+ is the Repo
70
- # +ref+ is the ref from which to begin (SHA1 or name)
71
- #
72
- # Returns Integer
73
- def self.count(repo, ref)
74
- repo.git.rev_list({}, ref).strip.split("\n").size
75
- end
76
-
77
- # Find all commits matching the given criteria.
78
- # +repo+ is the Repo
79
- # +ref+ is the ref from which to begin (SHA1 or name) or nil for --all
80
- # +options+ is a Hash of optional arguments to git
81
- # :max_count is the maximum number of commits to fetch
82
- # :skip is the number of commits to skip
83
- #
84
- # Returns Grit::Commit[] (baked)
85
- def self.find_all(repo, ref, options = {})
86
- allowed_options = [:max_count, :skip, :since]
87
-
88
- default_options = {:pretty => "raw"}
89
- actual_options = default_options.merge(options)
90
-
91
- if ref
92
- output = repo.git.rev_list(actual_options, ref)
93
- else
94
- output = repo.git.rev_list(actual_options.merge(:all => true))
95
- end
96
-
97
- self.list_from_string(repo, output)
98
- end
99
-
100
- # Parse out commit information into an array of baked Commit objects
101
- # +repo+ is the Repo
102
- # +text+ is the text output from the git command (raw format)
103
- #
104
- # Returns Grit::Commit[] (baked)
105
- def self.list_from_string(repo, text)
106
- lines = text.split("\n")
107
-
108
- commits = []
109
-
110
- while !lines.empty?
111
- id = lines.shift.split.last
112
- tree = lines.shift.split.last
113
-
114
- parents = []
115
- parents << lines.shift.split.last while lines.first =~ /^parent/
116
-
117
- author, authored_date = self.actor(lines.shift)
118
- committer, committed_date = self.actor(lines.shift)
119
-
120
- lines.shift
121
-
122
- message_lines = []
123
- message_lines << lines.shift[4..-1] while lines.first =~ /^ {4}/
124
-
125
- lines.shift while lines.first && lines.first.empty?
126
-
127
- commits << Commit.new(repo, id, parents, tree, author, authored_date, committer, committed_date, message_lines)
128
- end
129
-
130
- commits
131
- end
132
-
133
- # Show diffs between two trees:
134
- # +repo+ is the Repo
135
- # +a+ is a named commit
136
- # +b+ is an optional named commit. Passing an array assumes you
137
- # wish to omit the second named commit and limit the diff to the
138
- # given paths.
139
- # +paths* is an array of paths to limit the diff.
140
- #
141
- # Returns Grit::Diff[] (baked)
142
- def self.diff(repo, a, b = nil, paths = [])
143
- if b.is_a?(Array)
144
- paths = b
145
- b = nil
146
- end
147
- paths.unshift("--") unless paths.empty?
148
- paths.unshift(b) unless b.nil?
149
- paths.unshift(a)
150
- text = repo.git.diff({:full_index => true}, *paths)
151
- Diff.list_from_string(repo, text)
152
- end
153
-
154
- def diffs
155
- if parents.empty?
156
- diff = @repo.git.show({:full_index => true, :pretty => 'raw'}, @id)
157
- if diff =~ /diff --git a/
158
- diff = diff.sub(/.+?(diff --git a)/m, '\1')
159
- else
160
- diff = ''
161
- end
162
- Diff.list_from_string(@repo, diff)
163
- else
164
- self.class.diff(@repo, parents.first.id, @id)
165
- end
166
- end
167
-
168
- # Convert this Commit to a String which is just the SHA1 id
169
- def to_s
170
- @id
171
- end
172
-
173
- # Pretty object inspection
174
- def inspect
175
- %Q{#<Grit::Commit "#{@id}">}
176
- end
177
-
178
- # private
179
-
180
- # Parse out the actor (author or committer) info
181
- #
182
- # Returns [String (actor name and email), Time (acted at time)]
183
- def self.actor(line)
184
- m, actor, epoch = *line.match(/^.+? (.*) (\d+) .*$/)
185
- [Actor.from_string(actor), Time.at(epoch.to_i)]
186
- end
187
-
188
- def to_hash
189
- {
190
- 'id' => id,
191
- 'parents' => parents.map { |p| { 'id' => p.id } },
192
- 'tree' => tree.id,
193
- 'message' => message,
194
- 'author' => {
195
- 'name' => author.name,
196
- 'email' => author.email
197
- },
198
- 'committer' => {
199
- 'name' => committer.name,
200
- 'email' => committer.email
201
- },
202
- 'authored_date' => authored_date.xmlschema,
203
- 'committed_date' => committed_date.xmlschema,
204
- }
205
- end
206
- end # Commit
207
-
208
- end # Grit
@@ -1,44 +0,0 @@
1
- module Grit
2
-
3
- class Config
4
- def initialize(repo)
5
- @repo = repo
6
- end
7
-
8
- def []=(key, value)
9
- @repo.git.config({}, key, value)
10
- @data = nil
11
- end
12
-
13
- def [](key)
14
- data[key]
15
- end
16
-
17
- def fetch(key, default = nil)
18
- data[key] || default || raise(IndexError.new("key not found"))
19
- end
20
-
21
- def keys
22
- data.keys
23
- end
24
-
25
- protected
26
- def data
27
- @data ||= load_config
28
- end
29
-
30
- def load_config
31
- hash = {}
32
- config_lines.map do |line|
33
- key, value = line.split(/=/, 2)
34
- hash[key] = value
35
- end
36
- hash
37
- end
38
-
39
- def config_lines
40
- @repo.git.config(:list => true).split(/\n/)
41
- end
42
- end # Config
43
-
44
- end # Grit
@@ -1,70 +0,0 @@
1
- module Grit
2
-
3
- class Diff
4
- attr_reader :a_path, :b_path
5
- attr_reader :a_commit, :b_commit
6
- attr_reader :a_mode, :b_mode
7
- attr_reader :new_file, :deleted_file
8
- attr_reader :diff
9
-
10
- def initialize(repo, a_path, b_path, a_commit, b_commit, a_mode, b_mode, new_file, deleted_file, diff)
11
- @repo = repo
12
- @a_path = a_path
13
- @b_path = b_path
14
- @a_commit = a_commit =~ /^0{40}$/ ? nil : Commit.create(repo, :id => a_commit)
15
- @b_commit = b_commit =~ /^0{40}$/ ? nil : Commit.create(repo, :id => b_commit)
16
- @a_mode = a_mode
17
- @b_mode = b_mode
18
- @new_file = new_file
19
- @deleted_file = deleted_file
20
- @diff = diff
21
- end
22
-
23
- def self.list_from_string(repo, text)
24
- lines = text.split("\n")
25
-
26
- diffs = []
27
-
28
- while !lines.empty?
29
- m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
30
-
31
- if lines.first =~ /^old mode/
32
- m, a_mode = *lines.shift.match(/^old mode (\d+)/)
33
- m, b_mode = *lines.shift.match(/^new mode (\d+)/)
34
- end
35
-
36
- if lines.empty? || lines.first =~ /^diff --git/
37
- diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
38
- next
39
- end
40
-
41
- new_file = false
42
- deleted_file = false
43
-
44
- if lines.first =~ /^new file/
45
- m, b_mode = lines.shift.match(/^new file mode (.+)$/)
46
- a_mode = nil
47
- new_file = true
48
- elsif lines.first =~ /^deleted file/
49
- m, a_mode = lines.shift.match(/^deleted file mode (.+)$/)
50
- b_mode = nil
51
- deleted_file = true
52
- end
53
-
54
- m, a_commit, b_commit, b_mode = *lines.shift.match(%r{^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$})
55
- b_mode.strip! if b_mode
56
-
57
- diff_lines = []
58
- while lines.first && lines.first !~ /^diff/
59
- diff_lines << lines.shift
60
- end
61
- diff = diff_lines.join("\n")
62
-
63
- diffs << Diff.new(repo, a_path, b_path, a_commit, b_commit, a_mode, b_mode, new_file, deleted_file, diff)
64
- end
65
-
66
- diffs
67
- end
68
- end # Diff
69
-
70
- end # Grit
@@ -1,7 +0,0 @@
1
- module Grit
2
- class InvalidGitRepositoryError < StandardError
3
- end
4
-
5
- class NoSuchPathError < StandardError
6
- end
7
- end
@@ -1,116 +0,0 @@
1
- trap("CHLD") do
2
- begin
3
- Process.wait(-1, Process::WNOHANG)
4
- rescue Object
5
- end
6
- end
7
-
8
- module Grit
9
-
10
- class Git
11
- class GitTimeout < RuntimeError
12
- attr_reader :command, :bytes_read
13
-
14
- def initialize(command = nil, bytes_read = nil)
15
- @command = command
16
- @bytes_read = bytes_read
17
- end
18
- end
19
-
20
- undef_method :clone
21
-
22
- class << self
23
- attr_accessor :git_binary, :git_timeout
24
- end
25
-
26
- self.git_binary = "/usr/bin/env git"
27
- self.git_timeout = 5
28
-
29
- attr_accessor :git_dir, :bytes_read
30
-
31
- def initialize(git_dir)
32
- self.git_dir = git_dir
33
- self.bytes_read = 0
34
- end
35
-
36
- # Run the given git command with the specified arguments and return
37
- # the result as a String
38
- # +cmd+ is the command
39
- # +options+ is a hash of Ruby style options
40
- # +args+ is the list of arguments (to be joined by spaces)
41
- #
42
- # Examples
43
- # git.rev_list({:max_count => 10, :header => true}, "master")
44
- #
45
- # Returns String
46
- def method_missing(cmd, options = {}, *args)
47
- run('', cmd, '', options, args)
48
- end
49
-
50
- def run(prefix, cmd, postfix, options, args)
51
- timeout = options.delete(:timeout)
52
- timeout = true if timeout.nil?
53
-
54
- opt_args = transform_options(options)
55
- ext_args = args.map { |a| a == '--' ? a : "'#{a}'" }
56
-
57
- call = "#{prefix}#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{postfix}"
58
- puts call if Grit.debug
59
- response = timeout ? sh(call) : wild_sh(call)
60
- puts response if Grit.debug
61
- response
62
- end
63
-
64
- def sh(command)
65
- pid, _, io, _ = Open4.popen4(command)
66
- ret = Timeout.timeout(self.class.git_timeout) { io.read }
67
- @bytes_read += ret.size
68
-
69
- if @bytes_read > 5242880 # 5.megabytes
70
- bytes = @bytes_read
71
- @bytes_read = 0
72
- raise GitTimeout.new(command, bytes)
73
- end
74
-
75
- ret
76
- rescue Object => e
77
- Process.kill('KILL', pid) rescue nil
78
- bytes = @bytes_read
79
- @bytes_read = 0
80
- raise GitTimeout.new(command, bytes)
81
- end
82
-
83
- def wild_sh(command)
84
- pid, _, io, _ = Open4.popen4(command)
85
- io.read
86
- end
87
-
88
- # Transform Ruby style options into git command line options
89
- # +options+ is a hash of Ruby style options
90
- #
91
- # Returns String[]
92
- # e.g. ["--max-count=10", "--header"]
93
- def transform_options(options)
94
- args = []
95
- options.keys.each do |opt|
96
- if opt.to_s.size == 1
97
- if options[opt] == true
98
- args << "-#{opt}"
99
- else
100
- val = options.delete(opt)
101
- args << "-#{opt.to_s} '#{val}'"
102
- end
103
- else
104
- if options[opt] == true
105
- args << "--#{opt.to_s.gsub(/_/, '-')}"
106
- else
107
- val = options.delete(opt)
108
- args << "--#{opt.to_s.gsub(/_/, '-')}='#{val}'"
109
- end
110
- end
111
- end
112
- args
113
- end
114
- end # Git
115
-
116
- end # Grit