Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit ad8ce67

Browse files
committed
Merge pull request #37 from skv-headless/submodule-method
submodules in diff
2 parents a0e2e4e + 5969366 commit ad8ce67

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

lib/gitlab_git/blob.rb

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ def find(repository, sha, path)
1515

1616
return nil unless blob_entry
1717

18-
blob = repository.lookup(blob_entry[:oid])
19-
20-
if blob
21-
Blob.new(
22-
id: blob.oid,
23-
name: blob_entry[:name],
24-
size: blob.size,
25-
data: blob.content,
26-
mode: blob_entry[:mode],
27-
path: path,
28-
commit_id: sha,
29-
)
18+
if blob_entry[:type] == :commit
19+
submodule_blob(blob_entry, path, sha)
20+
else
21+
blob = repository.lookup(blob_entry[:oid])
22+
23+
if blob
24+
Blob.new(
25+
id: blob.oid,
26+
name: blob_entry[:name],
27+
size: blob.size,
28+
data: blob.content,
29+
mode: blob_entry[:mode],
30+
path: path,
31+
commit_id: sha,
32+
)
33+
end
3034
end
3135
end
3236

@@ -63,17 +67,22 @@ def find_entry_by_path(repository, root_id, path)
6367

6468
if path_arr.size > 1
6569
return nil unless entry[:type] == :tree
66-
else
67-
return nil unless entry[:type] == :blob
68-
end
69-
70-
if path_arr.size > 1
7170
path_arr.shift
7271
find_entry_by_path(repository, entry[:oid], path_arr.join('/'))
7372
else
74-
entry
73+
[:blob, :commit].include?(entry[:type]) ? entry : nil
7574
end
7675
end
76+
77+
def submodule_blob(blob_entry, path, sha)
78+
Blob.new(
79+
id: blob_entry[:oid],
80+
name: blob_entry[:name],
81+
data: '',
82+
path: path,
83+
commit_id: sha,
84+
)
85+
end
7786
end
7887

7988
def initialize(options)

lib/gitlab_git/diff.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def to_hash
5252
hash
5353
end
5454

55+
def submodule?
56+
a_mode == '160000' || b_mode == '160000'
57+
end
58+
5559
private
5660

5761
def init_from_rugged(rugged)

spec/blob_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333

3434
it { blob.should be_nil }
3535
end
36+
37+
context 'six submodule' do
38+
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, 'six') }
39+
40+
it { blob.id.should == '409f37c4f05865e4fb208c771485f211a22c4c2d' }
41+
it { blob.data.should == '' }
42+
end
3643
end
3744

3845
describe :raw do

spec/diff_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@
6262
its(:diff) { should include '+class Feature' }
6363
end
6464
end
65+
66+
describe :submodule? do
67+
before do
68+
commit = repository.lookup('5937ac0a7beb003549fc5fd26fc247adbce4a52e')
69+
@diffs = commit.parents[0].diff(commit).patches
70+
end
71+
72+
it { Gitlab::Git::Diff.new(@diffs[0]).submodule?.should == false }
73+
it { Gitlab::Git::Diff.new(@diffs[1]).submodule?.should == true }
74+
end
6575
end

0 commit comments

Comments
 (0)