diff options
author | Sean McGivern <sean@gitlab.com> | 2016-08-19 15:05:47 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-08-19 16:35:44 +0100 |
commit | 4a4c1765be20f0f0c6eca5c66513cb51a8b08fcf (patch) | |
tree | d16ecde63ed11e4c1e6904886ee3661babd1132e /lib/gitlab/diff | |
parent | 12e9df327042f3b368878d14f6e18e51b9f668b9 (diff) | |
download | gitlab-ce-4a4c1765be20f0f0c6eca5c66513cb51a8b08fcf.tar.gz |
Fix line commenting for the initial commit
The initial commit doesn't have a parent, so explicitly pass the blank
SHA and handle that when calculating the position.
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r-- | lib/gitlab/diff/position.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb index 2fdcf8d7838..ecf62dead35 100644 --- a/lib/gitlab/diff/position.rb +++ b/lib/gitlab/diff/position.rb @@ -139,13 +139,19 @@ module Gitlab private def find_diff_file(repository) - diffs = Gitlab::Git::Compare.new( - repository.raw_repository, - start_sha, - head_sha - ).diffs(paths: paths) + # We're at the initial commit, so just get that as we can't compare to anything. + if Gitlab::Git.blank_ref?(start_sha) + compare = Gitlab::Git::Commit.find(repository.raw_repository, head_sha) + else + compare = Gitlab::Git::Compare.new( + repository.raw_repository, + start_sha, + head_sha + ) + end + + diff = compare.diffs(paths: paths).first - diff = diffs.first return unless diff Gitlab::Diff::File.new(diff, repository: repository, diff_refs: diff_refs) |