git_diff 0.3.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e3b41b08c6a9dccc59f7a462cdcdb68e5b1cfaec
4
- data.tar.gz: 366a324e52d933f22147093c90d8844d4af34710
2
+ SHA256:
3
+ metadata.gz: 52a2071ba28b2a0703fabec01c2c4f50c3eae657255a096b5603fcc7cffa8381
4
+ data.tar.gz: c888271d5001095ab3dcae18cf209bc03eb0251d57e2d528deb9873cc3a66d02
5
5
  SHA512:
6
- metadata.gz: bb7a0f39886899976aeb0a98aedd8ffbb7588a61177072dd77c082ee14b72a11ebb30908af0d7d99ac5e50eb9db1e3a9d46cd9dfbfdae657020ba7a885f33309
7
- data.tar.gz: 7d0e155533df7ef127f9c1769b7f81e281cba163c22dc72af5b8a1f0fe845aa3d21e2368712c4c383d96ff8cd68762303b2d99ed7b91af680a07c12e7e5e4670
6
+ metadata.gz: a145f66c6c8345883093adef62a6bdbde48d5475ee41923bd523f5f7d8f471cc3c8637a89eb4b2003749488c32f2dfffc0a4d78f9f395e259770386fd6f00739
7
+ data.tar.gz: 323ad1908b9f757c36185ec943e31f1620185d0b0b8052d5e8cf6680dd4ac8dc9e4204f88d6f32615458c0282154d250909f10b83988933c7c34f5eca1c7590c
@@ -0,0 +1,46 @@
1
+ AllCops:
2
+ Include:
3
+ - "**/*.rb"
4
+ - "*.gemspec"
5
+ - "Gemfile"
6
+ - "Rakefile"
7
+ TargetRubyVersion: 2.5
8
+
9
+ Lint/AssignmentInCondition:
10
+ Enabled: false
11
+
12
+ Metrics/AbcSize:
13
+ Enabled: false
14
+
15
+ Metrics/ClassLength:
16
+ Enabled: false
17
+
18
+ Metrics/CyclomaticComplexity:
19
+ Enabled: false
20
+
21
+ Metrics/LineLength:
22
+ Max: 120
23
+
24
+ Metrics/MethodLength:
25
+ Enabled: false
26
+
27
+ Metrics/PerceivedComplexity:
28
+ Enabled: false
29
+
30
+ Style/ClassAndModuleChildren:
31
+ Enabled: false
32
+
33
+ Style/Documentation:
34
+ Enabled: false
35
+
36
+ Style/GuardClause:
37
+ MinBodyLength: 60
38
+
39
+ Style/StringLiterals:
40
+ EnforcedStyle: double_quotes
41
+
42
+
43
+
44
+
45
+
46
+
@@ -1,4 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
3
+ - 2.3.8
4
+ - 2.4.6
5
+ - 2.5.5
6
+ - 2.6.3
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler
10
+ script:
11
+ - bundle exec rake
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in git_diff.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -9,7 +9,7 @@ A Ruby library for parsing the unified diff format generated with `git diff`
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
- gem 'git_diff', git: 'https://github.com/anolson/git_diff.git'
12
+ gem 'git_diff'
13
13
 
14
14
  And then execute:
15
15
 
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  Rake::TestTask.new do |t|
5
8
  t.libs << "lib"
@@ -7,4 +10,6 @@ Rake::TestTask.new do |t|
7
10
  t.pattern = "test/**/*_test.rb"
8
11
  end
9
12
 
10
- task :default => :test
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[rubocop test]
@@ -1,21 +1,23 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'git_diff/version'
5
+ require "git_diff/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "git_diff"
8
9
  spec.version = GitDiff::VERSION
9
10
  spec.authors = ["Andrew Olson"]
10
- spec.email = ["aolson@geezeo.com"]
11
- spec.summary = %q{A Ruby library for parsing git diffs.}
11
+ spec.email = ["anolson@gmail.com"]
12
+ spec.summary = "A Ruby library for parsing git diffs."
12
13
  spec.license = "MIT"
13
14
 
14
- spec.files = `git ls-files`.split($/)
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.files = `git ls-files`.split($RS)
16
16
  spec.test_files = spec.files.grep(%r{^(test)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "bundler", "~> 2.0"
20
+ spec.add_development_dependency "minitest"
20
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rubocop", "~> 0.74.0"
21
23
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "forwardable"
2
4
 
3
5
  require "git_diff/stats_collector"
@@ -20,4 +22,4 @@ module GitDiff
20
22
  parser.parse
21
23
  parser.diff
22
24
  end
23
- end
25
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class Diff
3
- attr_reader :files, :stats
5
+ attr_reader :files
4
6
 
5
7
  def initialize
6
8
  @files = []
@@ -35,4 +37,4 @@ module GitDiff
35
37
  current_file << line
36
38
  end
37
39
  end
38
- end
40
+ end
@@ -1,22 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class File
3
-
4
- attr_reader :a_path, :a_blob, :b_path, :b_blob, :b_mode, :hunks
5
+ attr_reader :a_path, :a_blob, :b_path, :b_blob, :b_mode, :hunks, :binary
5
6
 
6
7
  def self.from_string(string)
7
- if /^diff --git/.match(string)
8
- File.new
8
+ if path_info = %r{^diff --git(?: a/(\S+))?(?: b/(\S+))?}.match(string)
9
+ File.new(
10
+ a_path: path_info.captures[0] || "/dev/null",
11
+ b_path: path_info.captures[1] || "/dev/null"
12
+ )
9
13
  end
10
14
  end
11
15
 
12
- def initialize
16
+ def initialize(a_path: "/dev/null", b_path: "/dev/null")
13
17
  @hunks = []
18
+ @a_path = a_path
19
+ @b_path = b_path
14
20
  end
15
21
 
16
22
  def <<(string)
17
23
  return if extract_diff_meta_data(string)
18
24
 
19
- if(range_info = RangeInfo.from_string(string))
25
+ if (range_info = RangeInfo.from_string(string))
20
26
  add_hunk Hunk.new(range_info)
21
27
  else
22
28
  append_to_current_hunk string
@@ -38,6 +44,7 @@ module GitDiff
38
44
  def add_hunk(hunk)
39
45
  self.current_hunk = hunk
40
46
  hunks << current_hunk
47
+ @binary = false
41
48
  end
42
49
 
43
50
  def append_to_current_hunk(string)
@@ -45,21 +52,39 @@ module GitDiff
45
52
  end
46
53
 
47
54
  def extract_diff_meta_data(string)
48
- case
49
- when a_path_info = /^[-]{3} \/dev\/null(.*)$/.match(string)
55
+ if a_path_info = %r{^[-]{3} /dev/null(.*)$}.match(string)
50
56
  @a_path = "/dev/null"
51
- when a_path_info = /^[-]{3} a\/(.*)$/.match(string)
57
+ elsif a_path_info = %r{^[-]{3} "?a/(.*)$}.match(string)
52
58
  @a_path = a_path_info[1]
53
- when b_path_info = /^[+]{3} \/dev\/null(.*)$/.match(string)
59
+ elsif b_path_info = %r{^[+]{3} /dev/null(.*)$}.match(string)
54
60
  @b_path = "/dev/null"
55
- when b_path_info = /^[+]{3} b\/(.*)$/.match(string)
61
+ elsif b_path_info = %r{^[+]{3} "?b/(.*)$}.match(string)
56
62
  @b_path = b_path_info[1]
57
- when blob_info = /^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$/.match(string)
63
+ elsif blob_info = /^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$/.match(string)
58
64
  @a_blob, @b_blob, @b_mode = *blob_info.captures
59
- when /^new file mode [0-9]{6}$/.match(string)
65
+ elsif /^new file mode [0-9]{6}$/.match(string)
60
66
  @a_path = "/dev/null"
61
- when /^deleted file mode [0-9]{6}$/.match(string)
67
+ elsif /^deleted file mode [0-9]{6}$/.match(string)
62
68
  @b_path = "/dev/null"
69
+ elsif mode_info = /^(old|new) mode ([0-9]{6})$/.match(string)
70
+ if mode_info.captures[0] == "old"
71
+ @a_mode = mode_info.captures[1]
72
+ else
73
+ @b_mode = mode_info.captures[1]
74
+ end
75
+ elsif copy_rename_info = /^(copy|rename) (from|to) (.*)$/.match(string)
76
+ if copy_rename_info.captures[1] == "from"
77
+ @a_path = copy_rename_info.captures[2]
78
+ else
79
+ @b_path = copy_rename_info.captures[2]
80
+ end
81
+ elsif binary_info = %r{^Binary files (?:/dev/null|"?a/(.*)) and (?:/dev/null|"?b/(.*)) differ$}.match(string)
82
+ @binary = true
83
+ @a_path ||= binary_info[1] || "/dev/null"
84
+ @b_path ||= binary_info[2] || "/dev/null"
85
+ elsif /^similarity/.match(string)
86
+ # trash
87
+ true
63
88
  end
64
89
  end
65
90
  end
@@ -1,12 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "forwardable"
2
4
 
3
5
  module GitDiff
4
6
  class Hunk
5
- include Enumerable
6
- extend Forwardable
7
-
8
- def_delegators :lines, :each
9
-
10
7
  attr_reader :lines, :range_info
11
8
 
12
9
  def initialize(range_info)
@@ -39,4 +36,4 @@ module GitDiff
39
36
  @line_number_calculation ||= LineNumberCalculation.new(initial_line_number)
40
37
  end
41
38
  end
42
- end
39
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "git_diff/line/context"
2
4
  require "git_diff/line/addition"
3
5
  require "git_diff/line/deletion"
@@ -19,4 +21,4 @@ module GitDiff
19
21
  end
20
22
  extend ClassMethods
21
23
  end
22
- end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  module Line
3
5
  class Addition < Context
@@ -10,4 +12,4 @@ module GitDiff
10
12
  end
11
13
  end
12
14
  end
13
- end
15
+ end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  module Line
3
5
  class Context
4
6
  attr_reader :content, :line_number
5
7
 
6
- def initialize(content, line_number=nil)
8
+ def initialize(content, line_number = nil)
7
9
  @content = content
8
10
  @line_number = line_number
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  module Line
3
5
  class Deletion < Context
@@ -10,4 +12,4 @@ module GitDiff
10
12
  end
11
13
  end
12
14
  end
13
- end
15
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class LineNumber
3
5
  attr_reader :left, :right
@@ -39,4 +41,4 @@ module GitDiff
39
41
  [left, right]
40
42
  end
41
43
  end
42
- end
44
+ end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class LineNumberCalculation
3
-
4
5
  attr_reader :current
5
6
 
6
7
  def initialize(line_number)
@@ -19,4 +20,4 @@ module GitDiff
19
20
  end
20
21
  end
21
22
  end
22
- end
23
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class LineNumberRange
3
5
  attr_reader :start, :number_of_lines
@@ -6,7 +8,7 @@ module GitDiff
6
8
  new(*string.split(","))
7
9
  end
8
10
 
9
- def initialize(start = 0, number_of_lines = 0)
11
+ def initialize(start = 0, number_of_lines = 1)
10
12
  @start = start.to_i
11
13
  @number_of_lines = number_of_lines.to_i
12
14
  end
@@ -15,4 +17,4 @@ module GitDiff
15
17
  "#{type}#{start},#{number_of_lines}"
16
18
  end
17
19
  end
18
- end
20
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class Parser
3
5
  attr_reader :string, :diff
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class RangeInfo
3
5
  attr_reader :original_range, :new_range, :header
4
6
 
5
7
  module ClassMethods
6
8
  def from_string(string)
7
- if(range_data = extract_hunk_range_data(string))
9
+ if (range_data = extract_hunk_range_data(string))
8
10
  new(*range_data.captures)
9
11
  end
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class Stats
3
5
  attr_reader :number_of_additions, :number_of_lines, :number_of_deletions
@@ -15,4 +17,4 @@ module GitDiff
15
17
  end
16
18
  end
17
19
  end
18
- end
20
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  class StatsCalculator
3
5
  attr_reader :collector
@@ -28,4 +30,4 @@ module GitDiff
28
30
  Array(collector.collect)
29
31
  end
30
32
  end
31
- end
33
+ end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "git_diff/stats_collector/hunk"
2
- require "git_diff/stats_collector/rollup"
4
+ require "git_diff/stats_collector/rollup"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  module StatsCollector
3
5
  class Hunk
@@ -33,9 +35,5 @@ module GitDiff
33
35
  hunk.lines
34
36
  end
35
37
  end
36
-
37
38
  end
38
39
  end
39
-
40
-
41
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
4
  module StatsCollector
3
5
  class StatsCollector::Rollup
@@ -8,7 +10,7 @@ module GitDiff
8
10
  end
9
11
 
10
12
  def collect
11
- collection.map { |item| item.stats }
13
+ collection.map(&:stats)
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitDiff
2
- VERSION = "0.3.0"
4
+ VERSION = "0.4.3"
3
5
  end
@@ -1,7 +1,8 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class DiffFileTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class DiffFileTest < Minitest::Test
5
6
  def setup
6
7
  @file = GitDiff::File.new
7
8
  end
@@ -45,8 +46,8 @@ class DiffFileTest < MiniTest::Unit::TestCase
45
46
  @file << " io = StringIO.new(text)"
46
47
  @file << " objects = []"
47
48
  @file << " while line = io.gets"
48
- @file << "- sha, type, size = line.split(" ", 3)"
49
- @file << "+ sha, type, size = line.split(" ", 3) #wut"
49
+ @file << "- sha, type, size = line.split(' ', 3)"
50
+ @file << "+ sha, type, size = line.split(' ', 3) #wut"
50
51
  @file << " parser = BATCH_PARSERS[type]"
51
52
  @file << " if type == 'missing' || !parser"
52
53
  @file << " io.seek(size.to_i + 1, IO::SEEK_CUR)"
@@ -56,5 +57,4 @@ class DiffFileTest < MiniTest::Unit::TestCase
56
57
  assert_equal 1, @file.stats.number_of_additions
57
58
  assert_equal 1, @file.stats.number_of_deletions
58
59
  end
59
-
60
- end
60
+ end
@@ -1,51 +1,52 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class GitDiffTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class GitDiffTest < Minitest::Test
5
6
  def setup
6
- string = <<-'DIFF'
7
- diff --git a/lib/grit/commit.rb b/lib/grit/commit.rb
8
- index 403ea33..dd4b590 100644
9
- --- a/lib/grit/commit.rb
10
- +++ b/lib/grit/commit.rb
11
- @@ -27,6 +27,7 @@
12
-
13
- lines = info.split("\n")
14
- tree = lines.shift.split(' ', 2).last
15
- +
16
- parents = []
17
- parents << lines.shift[7..-1] while lines.first[0, 6] == 'parent'
18
- author, authored_date = Grit::Commit.actor(lines.shift)
19
- diff --git a/lib/grit/new_file.rb b/lib/grit/new_file.rb
20
- new file mode 100644
21
- index 0000000..24f83d1
22
- --- /dev/null
23
- +++ b/lib/grit/new_file.rb
24
- @@ -0,0 +1 @@
25
- +#
26
- diff --git a/grit/old_file.rb b/grit/old_file.rb
27
- deleted file mode 100644
28
- index ba6b733..0000000
29
- --- a/lib/grit/old_file.rb
30
- +++ /dev/null
31
- @@ -1 +0,0 @@
32
- -#
33
- diff --git a/lib/grit/repo.rb b/lib/grit/repo.rb
34
- index 033b446..0e2d140 100644
35
- --- a/lib/grit/repo.rb
36
- +++ b/lib/grit/repo.rb
37
- @@ -180,7 +180,7 @@ module Grit
38
- io = StringIO.new(text)
39
- objects = []
40
- while line = io.gets
41
- - sha, type, size = line.split(" ", 3)
42
- + sha, type, size = line.split(" ", 3) #wut
43
- parser = BATCH_PARSERS[type]
44
- if type == 'missing' || !parser
45
- io.seek(size.to_i + 1, IO::SEEK_CUR)
7
+ string = <<~'DIFF'
8
+ diff --git a/lib/grit/commit.rb b/lib/grit/commit.rb
9
+ index 403ea33..dd4b590 100644
10
+ --- a/lib/grit/commit.rb
11
+ +++ b/lib/grit/commit.rb
12
+ @@ -27,6 +27,7 @@
13
+
14
+ lines = info.split("\n")
15
+ tree = lines.shift.split(' ', 2).last
16
+ +
17
+ parents = []
18
+ parents << lines.shift[7..-1] while lines.first[0, 6] == 'parent'
19
+ author, authored_date = Grit::Commit.actor(lines.shift)
20
+ diff --git a/lib/grit/new_file.rb b/lib/grit/new_file.rb
21
+ new file mode 100644
22
+ index 0000000..24f83d1
23
+ --- /dev/null
24
+ +++ b/lib/grit/new_file.rb
25
+ @@ -0,0 +1 @@
26
+ +#
27
+ diff --git a/grit/old_file.rb b/grit/old_file.rb
28
+ deleted file mode 100644
29
+ index ba6b733..0000000
30
+ --- a/lib/grit/old_file.rb
31
+ +++ /dev/null
32
+ @@ -1 +0,0 @@
33
+ -#
34
+ diff --git a/lib/grit/repo.rb b/lib/grit/repo.rb
35
+ index 033b446..0e2d140 100644
36
+ --- a/lib/grit/repo.rb
37
+ +++ b/lib/grit/repo.rb
38
+ @@ -180,7 +180,7 @@ module Grit
39
+ io = StringIO.new(text)
40
+ objects = []
41
+ while line = io.gets
42
+ - sha, type, size = line.split(" ", 3)
43
+ + sha, type, size = line.split(" ", 3) #wut
44
+ parser = BATCH_PARSERS[type]
45
+ if type == 'missing' || !parser
46
+ io.seek(size.to_i + 1, IO::SEEK_CUR)
46
47
  DIFF
47
48
 
48
- @diff = GitDiff::from_string(string)
49
+ @diff = GitDiff.from_string(string)
49
50
  end
50
51
 
51
52
  def first_diff_file
@@ -108,24 +109,94 @@ index 033b446..0e2d140 100644
108
109
  second_hunk = last_diff_file.hunks.first
109
110
 
110
111
  assert_equal [
111
- [27,27],
112
- [28,28],
113
- [29,29],
114
- [nil,30],
115
- [30,31],
116
- [31,32],
117
- [32,33]
118
- ], first_hunk.lines.map { |line| line.line_number.pair }
112
+ [27, 27],
113
+ [28, 28],
114
+ [29, 29],
115
+ [nil, 30],
116
+ [30, 31],
117
+ [31, 32],
118
+ [32, 33]
119
+ ], (first_hunk.lines.map { |line| line.line_number.pair })
119
120
 
120
121
  assert_equal [
121
- [180,180],
122
- [181,181],
123
- [182,182],
124
- [183,nil],
125
- [nil,183],
126
- [184,184],
127
- [185,185],
128
- [186,186]
129
- ], second_hunk.lines.map { |line| line.line_number.pair }
122
+ [180, 180],
123
+ [181, 181],
124
+ [182, 182],
125
+ [183, nil],
126
+ [nil, 183],
127
+ [184, 184],
128
+ [185, 185],
129
+ [186, 186]
130
+ ], (second_hunk.lines.map { |line| line.line_number.pair })
131
+ end
132
+
133
+ def test_binary_file_diff
134
+ diff = GitDiff.from_string 'diff --git a/app/assets/bin.eot b/app/assets/bin.eot
135
+ new file mode 100644
136
+ index 0000000..2cbab9c
137
+ Binary files /dev/null and b/app/assets/bin.eot differ'
138
+
139
+ refute_nil diff
140
+ assert_instance_of GitDiff::Diff, diff
141
+
142
+ assert_equal 1, diff.files.count
143
+ file = diff.files[0]
144
+
145
+ assert file.binary
146
+ assert_equal "/dev/null", file.a_path
147
+ assert_equal "app/assets/bin.eot", file.b_path
148
+ end
149
+
150
+ def test_perm_change_diff
151
+ diff = GitDiff.from_string 'diff --git a/bin/setup b/bin/setup
152
+ old mode 100644
153
+ new mode 100755'
154
+
155
+ refute_nil diff
156
+ assert_instance_of GitDiff::Diff, diff
157
+
158
+ assert_equal 1, diff.files.count
159
+ file = diff.files[0]
160
+
161
+ assert_equal 0, file.hunks.count
162
+
163
+ assert_equal "bin/setup", file.a_path
164
+ assert_equal "bin/setup", file.b_path
165
+ end
166
+
167
+ def test_rename_diff
168
+ diff = GitDiff.from_string 'diff --git a/lib/path1/my_file.rb b/lib/path2/my_file2.rb
169
+ similarity index 100%
170
+ rename from lib/path1/my_file.rb
171
+ rename to lib/path2/my_file2.rb'
172
+
173
+ refute_nil diff
174
+ assert_instance_of GitDiff::Diff, diff
175
+
176
+ assert_equal 1, diff.files.count
177
+ file = diff.files[0]
178
+
179
+ assert_equal 0, file.hunks.count
180
+
181
+ assert_equal "lib/path1/my_file.rb", file.a_path
182
+ assert_equal "lib/path2/my_file2.rb", file.b_path
183
+ end
184
+
185
+ def test_copy_diff
186
+ diff = GitDiff.from_string 'diff --git a/lib/path1/my_file.rb b/lib/path2/my_file2.rb
187
+ similarity index 100%
188
+ copy from lib/path1/my_file.rb
189
+ copy to lib/path2/my_file2.rb'
190
+
191
+ refute_nil diff
192
+ assert_instance_of GitDiff::Diff, diff
193
+
194
+ assert_equal 1, diff.files.count
195
+ file = diff.files[0]
196
+
197
+ assert_equal 0, file.hunks.count
198
+
199
+ assert_equal "lib/path1/my_file.rb", file.a_path
200
+ assert_equal "lib/path2/my_file2.rb", file.b_path
130
201
  end
131
202
  end
@@ -1,7 +1,8 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class HunkTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class HunkTest < Minitest::Test
5
6
  def setup
6
7
  @range_info = GitDiff::RangeInfo.new("180,7", "180,7", "module Grit")
7
8
  @hunk = GitDiff::Hunk.new(@range_info)
@@ -24,4 +25,4 @@ class HunkTest < MiniTest::Unit::TestCase
24
25
 
25
26
  assert_equal 1, @hunk.stats.number_of_deletions
26
27
  end
27
- end
28
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
- class AdditionTest < MiniTest::Unit::TestCase
5
+ class AdditionTest < Minitest::Test
4
6
  def setup
5
7
  @addition = GitDiff::Line::Addition.new("+ addition")
6
8
  end
@@ -12,4 +14,4 @@ class AdditionTest < MiniTest::Unit::TestCase
12
14
  def test_deletion_is_false
13
15
  refute @addition.deletion?
14
16
  end
15
- end
17
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
- class ContextTest < MiniTest::Unit::TestCase
5
+ class ContextTest < Minitest::Test
4
6
  def setup
5
- @line_number = GitDiff::LineNumber.new(0,0)
7
+ @line_number = GitDiff::LineNumber.new(0, 0)
6
8
  @content = "some content"
7
9
  @context = GitDiff::Line::Context.new(@content, @line_number)
8
10
  end
@@ -18,4 +20,4 @@ class ContextTest < MiniTest::Unit::TestCase
18
20
  def test_to_s_returns_the_content
19
21
  assert_equal @content, @context.to_s
20
22
  end
21
- end
23
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
- class DeletionTest < MiniTest::Unit::TestCase
5
+ class DeletionTest < Minitest::Test
4
6
  def setup
5
7
  @deletion = GitDiff::Line::Deletion.new("- deletion")
6
8
  end
@@ -12,4 +14,4 @@ class DeletionTest < MiniTest::Unit::TestCase
12
14
  def test_deletion_is_true
13
15
  assert @deletion.deletion?
14
16
  end
15
- end
17
+ end
@@ -1,7 +1,8 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class LineNumberCalculationTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class LineNumberCalculationTest < Minitest::Test
5
6
  def setup
6
7
  @line_number = GitDiff::LineNumber.new(0, 0)
7
8
  @line_number_calculation = GitDiff::LineNumberCalculation.new(@line_number)
@@ -31,4 +32,4 @@ class LineNumberCalculationTest < MiniTest::Unit::TestCase
31
32
  assert_equal 1, @line_number_calculation.current.left
32
33
  assert_equal 1, @line_number_calculation.current.right
33
34
  end
34
- end
35
+ end
@@ -1,24 +1,32 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class LineNumberRangeTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class LineNumberRangeTest < Minitest::Test
5
6
  def test_from_string_with_empty_string
6
7
  range = GitDiff::LineNumberRange.from_string("")
7
8
 
8
9
  assert_equal 0, range.start
9
- assert_equal 0, range.number_of_lines
10
+ assert_equal 1, range.number_of_lines
10
11
  end
11
12
 
12
- def test_from_string_with_empty_string
13
+ def test_from_string_with_not_empty_string
13
14
  range = GitDiff::LineNumberRange.from_string("180,7")
14
15
 
15
16
  assert_equal 180, range.start
16
17
  assert_equal 7, range.number_of_lines
17
18
  end
18
19
 
20
+ def test_from_string_with_start_no_count
21
+ range = GitDiff::LineNumberRange.from_string("180")
22
+
23
+ assert_equal 180, range.start
24
+ assert_equal 1, range.number_of_lines
25
+ end
26
+
19
27
  def test_to_s
20
28
  range = GitDiff::LineNumberRange.from_string("180,7")
21
29
 
22
30
  assert_equal "+180,7", range.to_s(:+)
23
31
  end
24
- end
32
+ end
@@ -1,9 +1,10 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class LineNumberTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class LineNumberTest < Minitest::Test
5
6
  def setup
6
- @line_number = GitDiff::LineNumber.new(0,0)
7
+ @line_number = GitDiff::LineNumber.new(0, 0)
7
8
  end
8
9
 
9
10
  def test_increment_left
@@ -25,6 +26,6 @@ class LineNumberTest < MiniTest::Unit::TestCase
25
26
  end
26
27
 
27
28
  def test_pair
28
- assert_equal [0,0], @line_number.pair
29
+ assert_equal [0, 0], @line_number.pair
29
30
  end
30
- end
31
+ end
@@ -1,12 +1,12 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- class LineTest < MiniTest::Unit::TestCase
3
+ require "test_helper"
4
4
 
5
+ class LineTest < Minitest::Test
5
6
  def setup
6
7
  @line_number = GitDiff::LineNumber.new(0, 0)
7
8
  end
8
9
 
9
-
10
10
  def test_from_string_with_addition
11
11
  addition = GitDiff::Line.from_string("+ addition")
12
12
 
@@ -27,4 +27,4 @@ class LineTest < MiniTest::Unit::TestCase
27
27
  refute_nil context
28
28
  assert_instance_of GitDiff::Line::Context, context
29
29
  end
30
- end
30
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
- class RangeInfoTest < MiniTest::Unit::TestCase
5
+ class RangeInfoTest < Minitest::Test
4
6
  def setup
5
7
  @range_info = GitDiff::RangeInfo.new("180,7", "180,7", "module Grit")
6
8
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class Collector
4
-
5
6
  def collect
6
7
  GitDiff::Stats.new(
7
8
  number_of_lines: number_of_lines,
@@ -25,7 +26,7 @@ class Collector
25
26
  end
26
27
  end
27
28
 
28
- class StatsCalculatorTest < MiniTest::Unit::TestCase
29
+ class StatsCalculatorTest < Minitest::Test
29
30
  def setup
30
31
  collector = Collector.new
31
32
 
@@ -44,4 +45,4 @@ class StatsCalculatorTest < MiniTest::Unit::TestCase
44
45
  def test_total_number_additions_is_the_sum_of_all_the_lines
45
46
  assert_equal 24, @stats.number_of_lines
46
47
  end
47
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "minitest/autorun"
2
4
  require "minitest/pride"
3
- require "git_diff"
5
+ require "git_diff"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Olson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,17 +52,31 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.74.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.74.0
41
69
  description:
42
70
  email:
43
- - aolson@geezeo.com
71
+ - anolson@gmail.com
44
72
  executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
76
  - ".gitignore"
77
+ - ".rubocop.yml"
49
78
  - ".travis.yml"
50
79
  - Gemfile
51
- - Gemfile.lock
52
80
  - LICENSE.txt
53
81
  - README.md
54
82
  - Rakefile
@@ -73,7 +101,7 @@ files:
73
101
  - lib/git_diff/stats_collector/rollup.rb
74
102
  - lib/git_diff/stats_rollup.rb
75
103
  - lib/git_diff/version.rb
76
- - test/diff_file_test.rb
104
+ - test/file_test.rb
77
105
  - test/git_diff_test.rb
78
106
  - test/hunk_test.rb
79
107
  - test/line/addition_test.rb
@@ -105,13 +133,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
133
  - !ruby/object:Gem::Version
106
134
  version: '0'
107
135
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.2.2
136
+ rubygems_version: 3.0.3
110
137
  signing_key:
111
138
  specification_version: 4
112
139
  summary: A Ruby library for parsing git diffs.
113
140
  test_files:
114
- - test/diff_file_test.rb
141
+ - test/file_test.rb
115
142
  - test/git_diff_test.rb
116
143
  - test/hunk_test.rb
117
144
  - test/line/addition_test.rb
@@ -124,4 +151,3 @@ test_files:
124
151
  - test/range_info_test.rb
125
152
  - test/stats_calculator_test.rb
126
153
  - test/test_helper.rb
127
- has_rdoc: