Skip to content

Commit a367bff

Browse files
Preserving original commit sha after parsing the commit data.
closes #2
1 parent 98e36bf commit a367bff

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/git/object.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@ def diff_parent
217217
end
218218

219219
def set_commit(data)
220-
if data['sha']
221-
@sha = data['sha']
222-
end
220+
@sha ||= data['sha']
223221
@committer = Git::Author.new(data['committer'])
224222
@author = Git::Author.new(data['author'])
225223
@tree = Git::Object::Tree.new(@base, data['tree'])

tests/units/test_object.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ def setup
1111
@tree = @git.gtree('1cc8667014381^{tree}')
1212
@blob = @git.gblob('v2.5:example.txt')
1313
end
14+
15+
def test_sha_state
16+
o = @git.object('HEAD')
17+
original_sha = o.sha
18+
o.date
19+
assert_equal(original_sha, o.sha)
20+
end
1421

1522
def test_commit
1623
o = @git.gcommit('1cc8667014381')

0 commit comments

Comments
 (0)