Skip to content

Commit

Permalink
Fix issue when the mode isn't present
Browse files Browse the repository at this point in the history
- Can happen with this kind of diff

  ```diff
  diff --git a/blabla.rb b/app/my_file.rb
  similarity index 100%
  rename from blabla.rb
  rename to app/my_file.rb
  ```
  • Loading branch information
Edouard-chin committed Feb 21, 2024
1 parent 97b2732 commit 1a38b29
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.1.1] - 2024-2-21
### Fixed
- `GithubDiffParser::Diff#new_mode?` and ``GithubDiffParser::Diff#deleted_mode?` would raise
an error with this kind of diff:

```diff
diff --git a/blabla.rb b/app/my_file.rb
similarity index 100%
rename from blabla.rb
rename to app/my_file.rb
```

## [1.1.0] - 2024-2-21
### Added
- Github Diff Parser parses the permissions bits and you now have have access to various method
Expand Down
10 changes: 5 additions & 5 deletions lib/github_diff_parser/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def add_line(line_content, type:)
#
# @return [Boolean]
def deleted_mode?
@mode.operation == "deleted"
@mode&.operation == "deleted"
end

# Check if this Diff is set to new mode.
Expand All @@ -94,7 +94,7 @@ def deleted_mode?
#
# @return [Boolean]
def new_mode?
@mode.operation == "new"
@mode&.operation == "new"
end

# Check if this Diff is set to rename mode.
Expand All @@ -112,17 +112,17 @@ def rename_mode?

# @return [Boolean] True if this diff applies to a regular file.
def normal_file?
@mode.bits == "100644"
@mode&.bits == "100644"
end

# @return [Boolean] True if this diff applies to an executable.
def executable?
@mode.bits == "100755"
@mode&.bits == "100755"
end

# @return [Boolean] True if this diff applies to a symlink.
def symlink?
@mode.bits == "120000"
@mode&.bits == "120000"
end

# @return [String] The source of the symlink
Expand Down
5 changes: 5 additions & 0 deletions test/github_diff_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ def test_file_moved
assert_equal("app/my_file.rb", parsed_diff.new_filename)
assert_equal(0, parsed_diff.hunks.count)
assert_predicate(parsed_diff, :rename_mode?)
refute_predicate(parsed_diff, :new_mode?)
refute_predicate(parsed_diff, :deleted_mode?)
refute_predicate(parsed_diff, :normal_file?)
refute_predicate(parsed_diff, :symlink?)
refute_predicate(parsed_diff, :executable?)
end

def test_rails_diff
Expand Down

0 comments on commit 1a38b29

Please sign in to comment.