Skip to content

Git::Lib#ls_tree ignore other types fix #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
*.gem
*.kpf
*.sw?
.bundle
.ruby-version
.DS_Store
coverage
pkg
rdoc
vendor
Gemfile.lock
2 changes: 2 additions & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def ls_tree(sha)
command_lines('ls-tree', sha).each do |line|
(info, filenm) = line.split("\t")
(mode, type, sha) = info.split
next unless data.include? type

data[type][filenm] = {:mode => mode, :sha => sha}
end

Expand Down
1 change: 1 addition & 0 deletions tests/files/working/dot_git/COMMIT_EDITMSG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls_tree skips submodules (commits)
3 changes: 3 additions & 0 deletions tests/files/working/dot_git/config
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[remote "working"]
url = ../working.git
fetch = +refs/heads/*:refs/remotes/working/*
[submodule "submodule_dir"]
url = https://github.com/ruby-git/ruby-git.git
active = true
Binary file modified tests/files/working/dot_git/index
Binary file not shown.
1 change: 1 addition & 0 deletions tests/files/working/dot_git/logs/HEAD
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ b98f4909807c8c84a1dc1b62b4a339ae1777f369 87c56502c73149f006631129f85dff697e00035
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
5e53019b3238362144c2766f02a2c00d91fcc023 9641f3383a015620ffd40591a4d7ec9ef07697d6 Scott Chacon <schacon@gmail.com> 1596068184 -0700 commit: ls_tree skips submodules (commits)
1 change: 1 addition & 0 deletions tests/files/working/dot_git/logs/refs/heads/git_grep
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
5e53019b3238362144c2766f02a2c00d91fcc023 9641f3383a015620ffd40591a4d7ec9ef07697d6 Scott Chacon <schacon@gmail.com> 1596068184 -0700 commit: ls_tree skips submodules (commits)
1 change: 1 addition & 0 deletions tests/files/working/dot_git/modules/submodule_dir/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
14 changes: 14 additions & 0 deletions tests/files/working/dot_git/modules/submodule_dir/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
worktree = ../../../submodule_dir
[remote "origin"]
url = https://github.com/ruby-git/ruby-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
2 changes: 2 additions & 0 deletions tests/files/working/dot_git/modules/submodule_dir/logs/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596073041 -0700 checkout: moving from master to 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary <cary.m.p@gmail.com> 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git
Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions tests/files/working/dot_git/modules/submodule_dir/packed-refs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# pack-refs with: peeled fully-peeled sorted
ee51cb0d00b54c0b31757af16ab57cac856ab7cc refs/remotes/origin/develop
72d7a3d66d47a0142ede2fc79acca7b32f02c05f refs/remotes/origin/diff_name_status
10b880b418879e662feb91ce7af98560adeaa8bb refs/remotes/origin/integrate
6a9db968e8563bc27b8f56f9d413159a2e14cf67 refs/remotes/origin/internals
7fa802e3a8ee39091f21d7909fa804fc2536e726 refs/remotes/origin/ls-files-default-location
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 refs/remotes/origin/master
2d749e3aa69d7bfedf814f59618f964fdbc300d5 refs/remotes/origin/test
e392283c06fcdc45bd661595f0903869695e629f refs/remotes/origin/thread_safety
be47ad8aea4f854fc2d6773456fb28f3e9f519e7 refs/tags/1.0.3
6c4af60f5fc5193b956a4698b604ad96ef3c51c6 refs/tags/1.0.5
3d26fb201e724814c6dd61cdb7ac8605c35a1dc0 refs/tags/1.0.5.1
^ae106e2a3569e5ea874852c613ed060d8e232109
2bc4103245a4e8d9f79ec59c2814c47b857d3a0b refs/tags/v1.0.7
^1adc5b8136c2cd6c694629947e1dbc49c8bffe6a
cfad76700b3d38eb3be97e2d5ef75cc0a398f818 refs/tags/v1.2.0
f85cef0b1916f09ceb38f778ada98b23c8610da7 refs/tags/v1.2.1
9110f3908ed5e76ad9366d1e5005db9e38b602e0 refs/tags/v1.2.10
^6f48447656c68317842aaa39a959dbe69681e38d
85fa6ec3a68b6ff8acfa69c59fbdede1385f63bb refs/tags/v1.2.2
2962356828cc0ce07674b1c1fa39fde893732344 refs/tags/v1.2.3
1987b5010ed1abff915bd87146753323754bfb13 refs/tags/v1.2.4
94f389bf5d9af4511597d035e69d1be9510b50c7 refs/tags/v1.2.5
f14a87280dd00215e892b8b20859c128a85f0759 refs/tags/v1.2.6
^6db4fdcad851eeaff6382a9eb6748455c3818c3e
a8debf3605b1ddf05ed6a2243bd1d6cbbc1275df refs/tags/v1.2.7
^219c729b24b1dc868986f821655912612919ac21
20fcdc6cec2e5a2a88be63e7f441f889ad17e158 refs/tags/v1.2.8
^8425a6b6169eaeda0afe2e16b0e4210ed433caf2
697d201b779991fb66e1d14d488e028518c9029e refs/tags/v1.2.9
^99b11561a64740285872f4c0a8b72e3e69308ed2
4bc7f14b62714853c1bd0c53930172356116e6a1 refs/tags/v1.2.9.1
^cc6d6efc1b7eaf63609c4c06969b0f839dc80095
03524b251812019da4fed3fc7d6c835f03f47c3d refs/tags/v1.3.0
^a223fcf873bd99658cd1d0bdee1818adc7e3e92c
f2633470c2cfa3a8a78f608f622629a6c772041d refs/tags/v1.4.0
^c8d10125d0cf172684e2da776b79edf90baebc52
024942729a623adea934d6dbd8ed503240e6cd7e refs/tags/v1.5.0
^fd2642a626d20594a25010526f10ff99431c2cca
49db88b6371211b1c9ebafad63d38c9ece8ca381 refs/tags/v1.6.0
69621e19a1a607d01e7e296d9bd8aaf593018e9b refs/tags/v1.6.0.pre1
^b9c7c5c51f935e547ab15a134e66c65ea0d9ab76
fa9e2a5a1869731541b9703b17276ae5ecaced8c refs/tags/v1.7.0
^4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/remotes/origin/master
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/files/working/dot_git/refs/heads/git_grep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5e53019b3238362144c2766f02a2c00d91fcc023
9641f3383a015620ffd40591a4d7ec9ef07697d6
1 change: 1 addition & 0 deletions tests/files/working/dot_git/refs/tags/v2.9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9641f3383a015620ffd40591a4d7ec9ef07697d6
3 changes: 3 additions & 0 deletions tests/files/working/dot_gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodule_dir"]
path = submodule_dir
url = https://github.com/ruby-git/ruby-git.git
1 change: 1 addition & 0 deletions tests/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def create_temp_repo(clone_path)
FileUtils.cp_r(clone_path, @tmp_path)
tmp_path = File.join(@tmp_path, 'working')
Dir.chdir(tmp_path) do
FileUtils.mv('dot_gitmodules', '.gitmodules')
FileUtils.mv('dot_git', '.git')
end
tmp_path
Expand Down
2 changes: 1 addition & 1 deletion tests/units/test_describe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def setup
end

def test_describe
assert_equal(@git.describe(nil, {:tags => true}), 'v2.8')
assert_equal(@git.describe(nil, {:tags => true}), 'v2.9')
end

end
22 changes: 17 additions & 5 deletions tests/units/test_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_fetch_unshallow
git = Git.clone("file://#{@wdir}", "shallow", path: dir, depth: 1).lib
assert_equal(1, git.log_commits.length)
git.fetch("file://#{@wdir}", unshallow: true)
assert_equal(71, git.log_commits.length)
assert_equal(72, git.log_commits.length)
end
end

Expand Down Expand Up @@ -227,10 +227,22 @@ def test_config_remote
end


def test_ls_tree
tree = @lib.ls_tree('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7')
assert_equal("3aac4b445017a8fc07502670ec2dbf744213dd48", tree['blob']['example.txt'][:sha])
def test_ls_tree_sha
tree = @lib.ls_tree('5e53019b3238362144c2766f02a2c00d91fcc023')
assert_equal("8dc79ae7616abf1e2d4d5d97d566f2b2f6cee043", tree['blob']['example.txt'][:sha])
assert_equal("100644", tree['blob']['example.txt'][:mode])
assert_not_include(tree['blob'], ".gitmodules")
assert(tree['tree'])
end

def test_ls_tree_head
tree = @lib.ls_tree('HEAD')
assert_equal("8dc79ae7616abf1e2d4d5d97d566f2b2f6cee043", tree['blob']['example.txt'][:sha])
assert_equal("100644", tree['blob']['example.txt'][:mode])
assert_equal("693af11b325dfb788712f8cd84f05b3f96f926d6", tree['blob']['.gitmodules'][:sha])
assert_equal("100644", tree['blob']['.gitmodules'][:mode])
assert_not_include(tree['blob'], "submodule_dir")
assert_not_include(tree['blob'], "submodule_dir")
assert(tree['tree'])
end

Expand Down Expand Up @@ -280,7 +292,7 @@ def test_grep
end

def test_show
assert(/^commit 5e53019b3238362144c2766f02a2c00d91fcc023.+\+replace with new text - diff test$/m.match(@lib.show))
assert(/^commit 9641f3383a015620ffd40591a4d7ec9ef07697d6.+\+Subproject commit 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4$/m.match(@lib.show))
assert(/^commit 935badc874edd62a8629aaf103418092c73f0a56.+\+nothing!$/m.match(@lib.show('gitsearch1')))
assert(/^hello.+nothing!$/m.match(@lib.show('gitsearch1', 'scott/text.txt')))
end
Expand Down
6 changes: 3 additions & 3 deletions tests/units/test_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def setup
@git = Git.open(@wdir)
end

def test_get_fisrt_and_last_entries
def test_get_first_and_last_entries
log = @git.log
assert(log.first.is_a?(Git::Object::Commit))
assert_equal('5e53019b3238362144c2766f02a2c00d91fcc023', log.first.objectish)
assert_equal('9641f3383a015620ffd40591a4d7ec9ef07697d6', log.first.objectish)

assert(log.last.is_a?(Git::Object::Commit))
assert_equal('f1410f8735f6f73d3599eb9b5cdd2fb70373335c', log.last.objectish)
assert_equal('b03003311ad3fa368b475df58390353868e13c91', log.last.objectish)
end

def test_get_log_entries
Expand Down