Skip to content

Commit

Permalink
Checking an edge case for git strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
beatmadsen committed Oct 12, 2024
1 parent 84ffc6d commit 215cc46
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/churn_vs_complexity/git_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def valid_commit?(commit:)
end

def changes(commit:)
@repo.object(commit).diff(@repo.object(commit).parent).map do |change|
commit_object = @repo.object(commit)
base = commit_object.parent
commit_object.diff(base).map do |change|
{ path: change.path, type: change.type.to_sym }
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/churn_vs_complexity/delta/checker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CheckerTest < TLDR
# Idea for check algorithm:
# 1. Find commit in log
# 2. Find all files changed in this commit
#  3. Annotate changed files with type of change (create, delete, modify)
# 3. Annotate changed files with type of change (create, delete, modify)
# 4. Validate changed files with complexity validator
# 5. Serialize results

Expand All @@ -37,10 +37,10 @@ def test_that_it_fails_when_it_cannot_prepare_a_worktree_and_there_are_changes
end
end

def test_that_it_fails_when_it_cannot_check_out_a_worktree_for_commit_and_there_are_changes
f = factory(worktree: worktree(fail_to_checkout: true))
# TODO: move worktree up one level
assert_raises(Timetravel::Worktree::Error) do
def test_that_it_fails_when_it_cannot_calculate_complexity_for_a_file
f = factory()
# TODO: wire Engine for custom complexity calculator
assert_raises(StandardError) do
checker(factory: f).check(folder: 'space-place')
end
end
Expand Down
28 changes: 28 additions & 0 deletions test/churn_vs_complexity/git_strategy_integration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'test_helper'

module ChurnVsComplexity
class GitStrategyIntegrationTest < TLDR

def test_that_it_can_get_changes_for_the_first_commit
g = GitStrategy.new(folder: ROOT_PATH)
repo = Git.open(ROOT_PATH)

first_commit = repo.log(max_count = 100_000).last.sha

changes = g.changes(commit: first_commit)
assert changes.any?, "No changes found for first commit #{first_commit}"
end

def test_that_it_can_get_changes_for_the_last_commit
g = GitStrategy.new(folder: ROOT_PATH)
repo = Git.open(ROOT_PATH)

last_commit = repo.log.first.sha

changes = g.changes(commit: last_commit)
assert changes.any?, "No changes found for last commit #{last_commit}"
end
end
end

0 comments on commit 215cc46

Please sign in to comment.