Skip to content

Commit 391ce68

Browse files
committed
Git::Lib#ls_tree ignore other types fix
If `git ls-tree` includes items other than blobs and trees, Git::Lib.ls_tree fails to either interpret or ignore the items. Until first-class support is available, ignore types other than these two. No mechanism for logging or otherwise recording this action is available, so, the unknown types are ignored silently. (Debug logging elsewhere does include the entire `git ls-tree` output.) Signed-off-by: Matthew Cary <98661+stujapa@users.noreply.github.com>
1 parent 4bef5ab commit 391ce68

30 files changed

+110
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
*.gem
22
*.kpf
33
*.sw?
4+
.bundle
5+
.ruby-version
46
.DS_Store
57
coverage
68
pkg
79
rdoc
10+
vendor
811
Gemfile.lock

lib/git/lib.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ def ls_tree(sha)
277277
command_lines('ls-tree', sha).each do |line|
278278
(info, filenm) = line.split("\t")
279279
(mode, type, sha) = info.split
280+
next unless data.include? type
281+
280282
data[type][filenm] = {:mode => mode, :sha => sha}
281283
end
282284

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ls_tree skips submodules (commits)

tests/files/working/dot_git/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[remote "working"]
1414
url = ../working.git
1515
fetch = +refs/heads/*:refs/remotes/working/*
16+
[submodule "submodule_dir"]
17+
url = https://github.com/ruby-git/ruby-git.git
18+
active = true

tests/files/working/dot_git/index

160 Bytes
Binary file not shown.

tests/files/working/dot_git/logs/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ b98f4909807c8c84a1dc1b62b4a339ae1777f369 87c56502c73149f006631129f85dff697e00035
7373
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
7474
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
7575
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
76+
5e53019b3238362144c2766f02a2c00d91fcc023 9641f3383a015620ffd40591a4d7ec9ef07697d6 Scott Chacon <schacon@gmail.com> 1596068184 -0700 commit: ls_tree skips submodules (commits)

tests/files/working/dot_git/logs/refs/heads/git_grep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
44
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
55
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
6+
5e53019b3238362144c2766f02a2c00d91fcc023 9641f3383a015620ffd40591a4d7ec9ef07697d6 Scott Chacon <schacon@gmail.com> 1596068184 -0700 commit: ls_tree skips submodules (commits)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
precomposeunicode = true
8+
worktree = ../../../submodule_dir
9+
[remote "origin"]
10+
url = https://github.com/ruby-git/ruby-git.git
11+
fetch = +refs/heads/*:refs/remotes/origin/*
12+
[branch "master"]
13+
remote = origin
14+
merge = refs/heads/master
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git
2+
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596073041 -0700 checkout: moving from master to 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# pack-refs with: peeled fully-peeled sorted
2+
ee51cb0d00b54c0b31757af16ab57cac856ab7cc refs/remotes/origin/develop
3+
72d7a3d66d47a0142ede2fc79acca7b32f02c05f refs/remotes/origin/diff_name_status
4+
10b880b418879e662feb91ce7af98560adeaa8bb refs/remotes/origin/integrate
5+
6a9db968e8563bc27b8f56f9d413159a2e14cf67 refs/remotes/origin/internals
6+
7fa802e3a8ee39091f21d7909fa804fc2536e726 refs/remotes/origin/ls-files-default-location
7+
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 refs/remotes/origin/master
8+
2d749e3aa69d7bfedf814f59618f964fdbc300d5 refs/remotes/origin/test
9+
e392283c06fcdc45bd661595f0903869695e629f refs/remotes/origin/thread_safety
10+
be47ad8aea4f854fc2d6773456fb28f3e9f519e7 refs/tags/1.0.3
11+
6c4af60f5fc5193b956a4698b604ad96ef3c51c6 refs/tags/1.0.5
12+
3d26fb201e724814c6dd61cdb7ac8605c35a1dc0 refs/tags/1.0.5.1
13+
^ae106e2a3569e5ea874852c613ed060d8e232109
14+
2bc4103245a4e8d9f79ec59c2814c47b857d3a0b refs/tags/v1.0.7
15+
^1adc5b8136c2cd6c694629947e1dbc49c8bffe6a
16+
cfad76700b3d38eb3be97e2d5ef75cc0a398f818 refs/tags/v1.2.0
17+
f85cef0b1916f09ceb38f778ada98b23c8610da7 refs/tags/v1.2.1
18+
9110f3908ed5e76ad9366d1e5005db9e38b602e0 refs/tags/v1.2.10
19+
^6f48447656c68317842aaa39a959dbe69681e38d
20+
85fa6ec3a68b6ff8acfa69c59fbdede1385f63bb refs/tags/v1.2.2
21+
2962356828cc0ce07674b1c1fa39fde893732344 refs/tags/v1.2.3
22+
1987b5010ed1abff915bd87146753323754bfb13 refs/tags/v1.2.4
23+
94f389bf5d9af4511597d035e69d1be9510b50c7 refs/tags/v1.2.5
24+
f14a87280dd00215e892b8b20859c128a85f0759 refs/tags/v1.2.6
25+
^6db4fdcad851eeaff6382a9eb6748455c3818c3e
26+
a8debf3605b1ddf05ed6a2243bd1d6cbbc1275df refs/tags/v1.2.7
27+
^219c729b24b1dc868986f821655912612919ac21
28+
20fcdc6cec2e5a2a88be63e7f441f889ad17e158 refs/tags/v1.2.8
29+
^8425a6b6169eaeda0afe2e16b0e4210ed433caf2
30+
697d201b779991fb66e1d14d488e028518c9029e refs/tags/v1.2.9
31+
^99b11561a64740285872f4c0a8b72e3e69308ed2
32+
4bc7f14b62714853c1bd0c53930172356116e6a1 refs/tags/v1.2.9.1
33+
^cc6d6efc1b7eaf63609c4c06969b0f839dc80095
34+
03524b251812019da4fed3fc7d6c835f03f47c3d refs/tags/v1.3.0
35+
^a223fcf873bd99658cd1d0bdee1818adc7e3e92c
36+
f2633470c2cfa3a8a78f608f622629a6c772041d refs/tags/v1.4.0
37+
^c8d10125d0cf172684e2da776b79edf90baebc52
38+
024942729a623adea934d6dbd8ed503240e6cd7e refs/tags/v1.5.0
39+
^fd2642a626d20594a25010526f10ff99431c2cca
40+
49db88b6371211b1c9ebafad63d38c9ece8ca381 refs/tags/v1.6.0
41+
69621e19a1a607d01e7e296d9bd8aaf593018e9b refs/tags/v1.6.0.pre1
42+
^b9c7c5c51f935e547ab15a134e66c65ea0d9ab76
43+
fa9e2a5a1869731541b9703b17276ae5ecaced8c refs/tags/v1.7.0
44+
^4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/remotes/origin/master
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5e53019b3238362144c2766f02a2c00d91fcc023
1+
9641f3383a015620ffd40591a4d7ec9ef07697d6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9641f3383a015620ffd40591a4d7ec9ef07697d6

tests/files/working/dot_gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "submodule_dir"]
2+
path = submodule_dir
3+
url = https://github.com/ruby-git/ruby-git.git

tests/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def create_temp_repo(clone_path)
3838
FileUtils.cp_r(clone_path, @tmp_path)
3939
tmp_path = File.join(@tmp_path, 'working')
4040
Dir.chdir(tmp_path) do
41+
FileUtils.mv('dot_gitmodules', '.gitmodules')
4142
FileUtils.mv('dot_git', '.git')
4243
end
4344
tmp_path

tests/units/test_describe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup
1010
end
1111

1212
def test_describe
13-
assert_equal(@git.describe(nil, {:tags => true}), 'v2.8')
13+
assert_equal(@git.describe(nil, {:tags => true}), 'v2.9')
1414
end
1515

1616
end

tests/units/test_lib.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_fetch_unshallow
1919
git = Git.clone("file://#{@wdir}", "shallow", path: dir, depth: 1).lib
2020
assert_equal(1, git.log_commits.length)
2121
git.fetch("file://#{@wdir}", unshallow: true)
22-
assert_equal(71, git.log_commits.length)
22+
assert_equal(72, git.log_commits.length)
2323
end
2424
end
2525

@@ -227,10 +227,22 @@ def test_config_remote
227227
end
228228

229229

230-
def test_ls_tree
231-
tree = @lib.ls_tree('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7')
232-
assert_equal("3aac4b445017a8fc07502670ec2dbf744213dd48", tree['blob']['example.txt'][:sha])
230+
def test_ls_tree_sha
231+
tree = @lib.ls_tree('5e53019b3238362144c2766f02a2c00d91fcc023')
232+
assert_equal("8dc79ae7616abf1e2d4d5d97d566f2b2f6cee043", tree['blob']['example.txt'][:sha])
233233
assert_equal("100644", tree['blob']['example.txt'][:mode])
234+
assert_not_include(tree['blob'], ".gitmodules")
235+
assert(tree['tree'])
236+
end
237+
238+
def test_ls_tree_head
239+
tree = @lib.ls_tree('HEAD')
240+
assert_equal("8dc79ae7616abf1e2d4d5d97d566f2b2f6cee043", tree['blob']['example.txt'][:sha])
241+
assert_equal("100644", tree['blob']['example.txt'][:mode])
242+
assert_equal("693af11b325dfb788712f8cd84f05b3f96f926d6", tree['blob']['.gitmodules'][:sha])
243+
assert_equal("100644", tree['blob']['.gitmodules'][:mode])
244+
assert_not_include(tree['blob'], "submodule_dir")
245+
assert_not_include(tree['blob'], "submodule_dir")
234246
assert(tree['tree'])
235247
end
236248

@@ -280,7 +292,7 @@ def test_grep
280292
end
281293

282294
def test_show
283-
assert(/^commit 5e53019b3238362144c2766f02a2c00d91fcc023.+\+replace with new text - diff test$/m.match(@lib.show))
295+
assert(/^commit 9641f3383a015620ffd40591a4d7ec9ef07697d6.+\+Subproject commit 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4$/m.match(@lib.show))
284296
assert(/^commit 935badc874edd62a8629aaf103418092c73f0a56.+\+nothing!$/m.match(@lib.show('gitsearch1')))
285297
assert(/^hello.+nothing!$/m.match(@lib.show('gitsearch1', 'scott/text.txt')))
286298
end

tests/units/test_log.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ def setup
99
@git = Git.open(@wdir)
1010
end
1111

12-
def test_get_fisrt_and_last_entries
12+
def test_get_first_and_last_entries
1313
log = @git.log
1414
assert(log.first.is_a?(Git::Object::Commit))
15-
assert_equal('5e53019b3238362144c2766f02a2c00d91fcc023', log.first.objectish)
15+
assert_equal('9641f3383a015620ffd40591a4d7ec9ef07697d6', log.first.objectish)
1616

1717
assert(log.last.is_a?(Git::Object::Commit))
18-
assert_equal('f1410f8735f6f73d3599eb9b5cdd2fb70373335c', log.last.objectish)
18+
assert_equal('b03003311ad3fa368b475df58390353868e13c91', log.last.objectish)
1919
end
2020

2121
def test_get_log_entries

0 commit comments

Comments
 (0)