diff --git a/.gitignore b/.gitignore index 8394ee1d..92eef40b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ *.gem *.kpf *.sw? +.bundle +.ruby-version .DS_Store coverage pkg rdoc +vendor Gemfile.lock diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 830c4dfe..bd6eb21b 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -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 diff --git a/tests/files/working/dot_git/COMMIT_EDITMSG b/tests/files/working/dot_git/COMMIT_EDITMSG new file mode 100644 index 00000000..b07b10f3 --- /dev/null +++ b/tests/files/working/dot_git/COMMIT_EDITMSG @@ -0,0 +1 @@ +ls_tree skips submodules (commits) diff --git a/tests/files/working/dot_git/config b/tests/files/working/dot_git/config index 6c545b24..a4d6c8fc 100644 --- a/tests/files/working/dot_git/config +++ b/tests/files/working/dot_git/config @@ -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 diff --git a/tests/files/working/dot_git/index b/tests/files/working/dot_git/index index 6f6327cb..d4dae3cd 100644 Binary files a/tests/files/working/dot_git/index and b/tests/files/working/dot_git/index differ diff --git a/tests/files/working/dot_git/logs/HEAD b/tests/files/working/dot_git/logs/HEAD index 349dda2e..69f9eaf4 100644 --- a/tests/files/working/dot_git/logs/HEAD +++ b/tests/files/working/dot_git/logs/HEAD @@ -73,3 +73,4 @@ b98f4909807c8c84a1dc1b62b4a339ae1777f369 87c56502c73149f006631129f85dff697e00035 a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon 1194632975 -0800 commit: modified to not show up 34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon 1194633382 -0800 commit: more search help 935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon 1194720731 -0800 commit: diff test +5e53019b3238362144c2766f02a2c00d91fcc023 9641f3383a015620ffd40591a4d7ec9ef07697d6 Scott Chacon 1596068184 -0700 commit: ls_tree skips submodules (commits) diff --git a/tests/files/working/dot_git/logs/refs/heads/git_grep b/tests/files/working/dot_git/logs/refs/heads/git_grep index 0123a146..d593d6e0 100644 --- a/tests/files/working/dot_git/logs/refs/heads/git_grep +++ b/tests/files/working/dot_git/logs/refs/heads/git_grep @@ -3,3 +3,4 @@ a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon 1194632975 -0800 commit: modified to not show up 34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon 1194633382 -0800 commit: more search help 935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon 1194720731 -0800 commit: diff test +5e53019b3238362144c2766f02a2c00d91fcc023 9641f3383a015620ffd40591a4d7ec9ef07697d6 Scott Chacon 1596068184 -0700 commit: ls_tree skips submodules (commits) diff --git a/tests/files/working/dot_git/modules/submodule_dir/HEAD b/tests/files/working/dot_git/modules/submodule_dir/HEAD new file mode 100644 index 00000000..58ba86b5 --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/HEAD @@ -0,0 +1 @@ +4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 diff --git a/tests/files/working/dot_git/modules/submodule_dir/config b/tests/files/working/dot_git/modules/submodule_dir/config new file mode 100644 index 00000000..c5560d7f --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/config @@ -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 diff --git a/tests/files/working/dot_git/modules/submodule_dir/description b/tests/files/working/dot_git/modules/submodule_dir/description new file mode 100644 index 00000000..498b267a --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/files/working/dot_git/modules/submodule_dir/index b/tests/files/working/dot_git/modules/submodule_dir/index new file mode 100644 index 00000000..a125d879 Binary files /dev/null and b/tests/files/working/dot_git/modules/submodule_dir/index differ diff --git a/tests/files/working/dot_git/modules/submodule_dir/info/exclude b/tests/files/working/dot_git/modules/submodule_dir/info/exclude new file mode 100644 index 00000000..a5196d1b --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/info/exclude @@ -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] +# *~ diff --git a/tests/files/working/dot_git/modules/submodule_dir/logs/HEAD b/tests/files/working/dot_git/modules/submodule_dir/logs/HEAD new file mode 100644 index 00000000..943819ef --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/logs/HEAD @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git +4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary 1596073041 -0700 checkout: moving from master to 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 diff --git a/tests/files/working/dot_git/modules/submodule_dir/logs/refs/heads/master b/tests/files/working/dot_git/modules/submodule_dir/logs/refs/heads/master new file mode 100644 index 00000000..e75fd0c2 --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git diff --git a/tests/files/working/dot_git/modules/submodule_dir/logs/refs/remotes/origin/HEAD b/tests/files/working/dot_git/modules/submodule_dir/logs/refs/remotes/origin/HEAD new file mode 100644 index 00000000..e75fd0c2 --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/logs/refs/remotes/origin/HEAD @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 Matthew Cary 1596068129 -0700 clone: from https://github.com/ruby-git/ruby-git.git diff --git a/tests/files/working/dot_git/modules/submodule_dir/objects/pack/pack-cdf4a9df621e613af06a1e62de3465eaa5482587.idx b/tests/files/working/dot_git/modules/submodule_dir/objects/pack/pack-cdf4a9df621e613af06a1e62de3465eaa5482587.idx new file mode 100644 index 00000000..1d6002ce Binary files /dev/null and b/tests/files/working/dot_git/modules/submodule_dir/objects/pack/pack-cdf4a9df621e613af06a1e62de3465eaa5482587.idx differ diff --git a/tests/files/working/dot_git/modules/submodule_dir/objects/pack/pack-cdf4a9df621e613af06a1e62de3465eaa5482587.pack b/tests/files/working/dot_git/modules/submodule_dir/objects/pack/pack-cdf4a9df621e613af06a1e62de3465eaa5482587.pack new file mode 100644 index 00000000..1a014d47 Binary files /dev/null and b/tests/files/working/dot_git/modules/submodule_dir/objects/pack/pack-cdf4a9df621e613af06a1e62de3465eaa5482587.pack differ diff --git a/tests/files/working/dot_git/modules/submodule_dir/packed-refs b/tests/files/working/dot_git/modules/submodule_dir/packed-refs new file mode 100644 index 00000000..775bf9d6 --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/packed-refs @@ -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 diff --git a/tests/files/working/dot_git/modules/submodule_dir/refs/heads/master b/tests/files/working/dot_git/modules/submodule_dir/refs/heads/master new file mode 100644 index 00000000..58ba86b5 --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/refs/heads/master @@ -0,0 +1 @@ +4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 diff --git a/tests/files/working/dot_git/modules/submodule_dir/refs/remotes/origin/HEAD b/tests/files/working/dot_git/modules/submodule_dir/refs/remotes/origin/HEAD new file mode 100644 index 00000000..6efe28ff --- /dev/null +++ b/tests/files/working/dot_git/modules/submodule_dir/refs/remotes/origin/HEAD @@ -0,0 +1 @@ +ref: refs/remotes/origin/master diff --git a/tests/files/working/dot_git/objects/53/a7aca1ee68676e870675fef166cce923609d38 b/tests/files/working/dot_git/objects/53/a7aca1ee68676e870675fef166cce923609d38 new file mode 100644 index 00000000..1125b301 Binary files /dev/null and b/tests/files/working/dot_git/objects/53/a7aca1ee68676e870675fef166cce923609d38 differ diff --git a/tests/files/working/dot_git/objects/69/3af11b325dfb788712f8cd84f05b3f96f926d6 b/tests/files/working/dot_git/objects/69/3af11b325dfb788712f8cd84f05b3f96f926d6 new file mode 100644 index 00000000..b2c35727 Binary files /dev/null and b/tests/files/working/dot_git/objects/69/3af11b325dfb788712f8cd84f05b3f96f926d6 differ diff --git a/tests/files/working/dot_git/objects/96/41f3383a015620ffd40591a4d7ec9ef07697d6 b/tests/files/working/dot_git/objects/96/41f3383a015620ffd40591a4d7ec9ef07697d6 new file mode 100644 index 00000000..63a3c993 Binary files /dev/null and b/tests/files/working/dot_git/objects/96/41f3383a015620ffd40591a4d7ec9ef07697d6 differ diff --git a/tests/files/working/dot_git/refs/heads/git_grep b/tests/files/working/dot_git/refs/heads/git_grep index 475c8590..482a71d3 100644 --- a/tests/files/working/dot_git/refs/heads/git_grep +++ b/tests/files/working/dot_git/refs/heads/git_grep @@ -1 +1 @@ -5e53019b3238362144c2766f02a2c00d91fcc023 +9641f3383a015620ffd40591a4d7ec9ef07697d6 diff --git a/tests/files/working/dot_git/refs/tags/v2.9 b/tests/files/working/dot_git/refs/tags/v2.9 new file mode 100644 index 00000000..482a71d3 --- /dev/null +++ b/tests/files/working/dot_git/refs/tags/v2.9 @@ -0,0 +1 @@ +9641f3383a015620ffd40591a4d7ec9ef07697d6 diff --git a/tests/files/working/dot_gitmodules b/tests/files/working/dot_gitmodules new file mode 100644 index 00000000..693af11b --- /dev/null +++ b/tests/files/working/dot_gitmodules @@ -0,0 +1,3 @@ +[submodule "submodule_dir"] + path = submodule_dir + url = https://github.com/ruby-git/ruby-git.git diff --git a/tests/test_helper.rb b/tests/test_helper.rb index 617d8c83..c7ea84aa 100644 --- a/tests/test_helper.rb +++ b/tests/test_helper.rb @@ -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 diff --git a/tests/units/test_describe.rb b/tests/units/test_describe.rb index 580e328e..971adcc8 100644 --- a/tests/units/test_describe.rb +++ b/tests/units/test_describe.rb @@ -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 diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb index c007d168..0400341b 100644 --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -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 @@ -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 @@ -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 diff --git a/tests/units/test_log.rb b/tests/units/test_log.rb index 9b9cb803..b14acb12 100644 --- a/tests/units/test_log.rb +++ b/tests/units/test_log.rb @@ -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