rugged 0.19.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +151 -25
- data/ext/rugged/extconf.rb +48 -27
- data/ext/rugged/rugged.c +107 -35
- data/ext/rugged/rugged.h +44 -8
- data/ext/rugged/rugged_blame.c +292 -0
- data/ext/rugged/rugged_blob.c +84 -31
- data/ext/rugged/rugged_branch.c +90 -223
- data/ext/rugged/rugged_branch_collection.c +445 -0
- data/ext/rugged/rugged_commit.c +190 -9
- data/ext/rugged/rugged_config.c +1 -1
- data/ext/rugged/rugged_cred.c +125 -0
- data/ext/rugged/rugged_diff.c +267 -94
- data/ext/rugged/rugged_diff_delta.c +14 -3
- data/ext/rugged/rugged_diff_hunk.c +31 -28
- data/ext/rugged/rugged_diff_line.c +21 -17
- data/ext/rugged/rugged_index.c +326 -6
- data/ext/rugged/rugged_note.c +39 -34
- data/ext/rugged/rugged_object.c +9 -9
- data/ext/rugged/rugged_patch.c +245 -0
- data/ext/rugged/rugged_reference.c +67 -332
- data/ext/rugged/rugged_reference_collection.c +490 -0
- data/ext/rugged/rugged_remote.c +447 -351
- data/ext/rugged/rugged_remote_collection.c +285 -0
- data/ext/rugged/rugged_repo.c +752 -203
- data/ext/rugged/rugged_revwalk.c +119 -27
- data/ext/rugged/rugged_settings.c +48 -1
- data/ext/rugged/rugged_signature.c +30 -16
- data/ext/rugged/rugged_tag.c +86 -191
- data/ext/rugged/rugged_tag_collection.c +279 -0
- data/ext/rugged/rugged_tree.c +159 -22
- data/lib/rugged/branch.rb +8 -17
- data/lib/rugged/credentials.rb +43 -0
- data/lib/rugged/diff/delta.rb +1 -2
- data/lib/rugged/diff/hunk.rb +4 -9
- data/lib/rugged/diff/line.rb +23 -3
- data/lib/rugged/diff.rb +3 -1
- data/lib/rugged/patch.rb +26 -0
- data/lib/rugged/reference.rb +1 -3
- data/lib/rugged/remote.rb +0 -9
- data/lib/rugged/repository.rb +70 -13
- data/lib/rugged/tag.rb +23 -18
- data/lib/rugged/tree.rb +7 -0
- data/lib/rugged/version.rb +1 -1
- data/lib/rugged.rb +8 -1
- data/vendor/libgit2/AUTHORS +75 -0
- data/vendor/libgit2/CMakeLists.txt +490 -0
- data/vendor/libgit2/COPYING +920 -0
- data/vendor/libgit2/Makefile.embed +25 -7
- data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +16 -0
- data/vendor/libgit2/cmake/Modules/FindHTTP_Parser.cmake +39 -0
- data/vendor/libgit2/cmake/Modules/FindIconv.cmake +43 -0
- data/vendor/libgit2/cmake/Modules/FindLIBSSH2.cmake +44 -0
- data/vendor/libgit2/deps/http-parser/LICENSE-MIT +23 -0
- data/vendor/libgit2/deps/regex/regex.c +10 -3
- data/vendor/libgit2/include/git2/attr.h +2 -1
- data/vendor/libgit2/include/git2/blame.h +213 -0
- data/vendor/libgit2/include/git2/blob.h +57 -29
- data/vendor/libgit2/include/git2/branch.h +56 -44
- data/vendor/libgit2/include/git2/buffer.h +112 -0
- data/vendor/libgit2/include/git2/checkout.h +72 -37
- data/vendor/libgit2/include/git2/cherrypick.h +87 -0
- data/vendor/libgit2/include/git2/clone.h +153 -56
- data/vendor/libgit2/include/git2/commit.h +82 -12
- data/vendor/libgit2/include/git2/common.h +31 -19
- data/vendor/libgit2/include/git2/config.h +124 -19
- data/vendor/libgit2/include/git2/cred_helpers.h +1 -1
- data/vendor/libgit2/include/git2/diff.h +636 -494
- data/vendor/libgit2/include/git2/errors.h +48 -15
- data/vendor/libgit2/include/git2/filter.h +149 -0
- data/vendor/libgit2/include/git2/graph.h +14 -0
- data/vendor/libgit2/include/git2/index.h +95 -54
- data/vendor/libgit2/include/git2/indexer.h +15 -9
- data/vendor/libgit2/include/git2/merge.h +402 -39
- data/vendor/libgit2/include/git2/message.h +9 -14
- data/vendor/libgit2/include/git2/net.h +5 -0
- data/vendor/libgit2/include/git2/notes.h +6 -6
- data/vendor/libgit2/include/git2/object.h +34 -2
- data/vendor/libgit2/include/git2/odb.h +77 -14
- data/vendor/libgit2/include/git2/odb_backend.h +50 -6
- data/vendor/libgit2/include/git2/oid.h +4 -8
- data/vendor/libgit2/include/git2/pack.h +58 -4
- data/vendor/libgit2/include/git2/patch.h +277 -0
- data/vendor/libgit2/include/git2/pathspec.h +263 -0
- data/vendor/libgit2/include/git2/push.h +55 -5
- data/vendor/libgit2/include/git2/reflog.h +11 -8
- data/vendor/libgit2/include/git2/refs.h +219 -33
- data/vendor/libgit2/include/git2/refspec.h +3 -4
- data/vendor/libgit2/include/git2/remote.h +216 -76
- data/vendor/libgit2/include/git2/repository.h +85 -40
- data/vendor/libgit2/include/git2/reset.h +15 -4
- data/vendor/libgit2/include/git2/revert.h +86 -0
- data/vendor/libgit2/include/git2/revparse.h +27 -16
- data/vendor/libgit2/include/git2/revwalk.h +44 -6
- data/vendor/libgit2/include/git2/signature.h +17 -3
- data/vendor/libgit2/include/git2/stash.h +8 -12
- data/vendor/libgit2/include/git2/status.h +67 -18
- data/vendor/libgit2/include/git2/submodule.h +100 -85
- data/vendor/libgit2/include/git2/sys/commit.h +38 -4
- data/vendor/libgit2/include/git2/sys/config.h +44 -3
- data/vendor/libgit2/include/git2/sys/diff.h +91 -0
- data/vendor/libgit2/include/git2/sys/filter.h +301 -0
- data/vendor/libgit2/include/git2/sys/index.h +0 -2
- data/vendor/libgit2/include/git2/sys/mempack.h +85 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +33 -11
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +51 -5
- data/vendor/libgit2/include/git2/sys/reflog.h +21 -0
- data/vendor/libgit2/include/git2/sys/refs.h +2 -2
- data/vendor/libgit2/include/git2/sys/repository.h +19 -1
- data/vendor/libgit2/include/git2/transport.h +216 -75
- data/vendor/libgit2/include/git2/tree.h +32 -11
- data/vendor/libgit2/include/git2/types.h +124 -10
- data/vendor/libgit2/include/git2/version.h +4 -2
- data/vendor/libgit2/include/git2.h +41 -40
- data/vendor/libgit2/libgit2.pc.in +10 -0
- data/vendor/libgit2/src/array.h +16 -8
- data/vendor/libgit2/src/attr.c +140 -402
- data/vendor/libgit2/src/attr.h +1 -33
- data/vendor/libgit2/src/attr_file.c +298 -135
- data/vendor/libgit2/src/attr_file.h +61 -22
- data/vendor/libgit2/src/attrcache.c +449 -0
- data/vendor/libgit2/src/attrcache.h +38 -6
- data/vendor/libgit2/src/bitvec.h +75 -0
- data/vendor/libgit2/src/blame.c +488 -0
- data/vendor/libgit2/src/blame.h +93 -0
- data/vendor/libgit2/src/blame_git.c +624 -0
- data/vendor/libgit2/src/blame_git.h +20 -0
- data/vendor/libgit2/src/blob.c +137 -92
- data/vendor/libgit2/src/blob.h +9 -0
- data/vendor/libgit2/src/branch.c +175 -156
- data/vendor/libgit2/src/buf_text.c +29 -14
- data/vendor/libgit2/src/buf_text.h +5 -4
- data/vendor/libgit2/src/buffer.c +158 -15
- data/vendor/libgit2/src/buffer.h +33 -20
- data/vendor/libgit2/src/cc-compat.h +8 -2
- data/vendor/libgit2/src/checkout.c +1081 -287
- data/vendor/libgit2/src/checkout.h +1 -1
- data/vendor/libgit2/src/cherrypick.c +226 -0
- data/vendor/libgit2/src/clone.c +297 -245
- data/vendor/libgit2/src/{compress.h → clone.h} +4 -8
- data/vendor/libgit2/src/commit.c +313 -101
- data/vendor/libgit2/src/commit.h +6 -3
- data/vendor/libgit2/src/commit_list.c +3 -3
- data/vendor/libgit2/src/commit_list.h +1 -1
- data/vendor/libgit2/src/common.h +74 -1
- data/vendor/libgit2/src/config.c +570 -145
- data/vendor/libgit2/src/config.h +39 -6
- data/vendor/libgit2/src/config_cache.c +32 -18
- data/vendor/libgit2/src/config_file.c +711 -424
- data/vendor/libgit2/src/config_file.h +4 -3
- data/vendor/libgit2/src/crlf.c +149 -109
- data/vendor/libgit2/src/date.c +35 -7
- data/vendor/libgit2/src/delta.c +1 -1
- data/vendor/libgit2/src/diff.c +719 -414
- data/vendor/libgit2/src/diff.h +52 -7
- data/vendor/libgit2/src/diff_driver.c +183 -85
- data/vendor/libgit2/src/diff_driver.h +1 -1
- data/vendor/libgit2/src/diff_file.c +65 -84
- data/vendor/libgit2/src/diff_file.h +12 -10
- data/vendor/libgit2/src/diff_patch.c +274 -333
- data/vendor/libgit2/src/diff_patch.h +10 -9
- data/vendor/libgit2/src/diff_print.c +381 -179
- data/vendor/libgit2/src/diff_stats.c +336 -0
- data/vendor/libgit2/src/diff_tform.c +393 -215
- data/vendor/libgit2/src/diff_xdiff.c +117 -42
- data/vendor/libgit2/src/errors.c +59 -4
- data/vendor/libgit2/src/fetch.c +40 -34
- data/vendor/libgit2/src/fetch.h +2 -5
- data/vendor/libgit2/src/fetchhead.c +14 -7
- data/vendor/libgit2/src/filebuf.c +13 -24
- data/vendor/libgit2/src/filebuf.h +3 -3
- data/vendor/libgit2/src/fileops.c +104 -296
- data/vendor/libgit2/src/fileops.h +23 -94
- data/vendor/libgit2/src/filter.c +642 -43
- data/vendor/libgit2/src/filter.h +7 -66
- data/vendor/libgit2/src/fnmatch.c +46 -3
- data/vendor/libgit2/src/fnmatch.h +24 -3
- data/vendor/libgit2/src/global.c +158 -42
- data/vendor/libgit2/src/global.h +9 -0
- data/vendor/libgit2/src/graph.c +34 -20
- data/vendor/libgit2/src/hash/hash_generic.h +0 -1
- data/vendor/libgit2/src/hash/hash_openssl.h +0 -1
- data/vendor/libgit2/src/hash/hash_win32.c +14 -29
- data/vendor/libgit2/src/hash.h +0 -2
- data/vendor/libgit2/src/hashsig.c +97 -117
- data/vendor/libgit2/src/ident.c +125 -0
- data/vendor/libgit2/src/ignore.c +159 -110
- data/vendor/libgit2/src/ignore.h +13 -3
- data/vendor/libgit2/src/index.c +803 -445
- data/vendor/libgit2/src/index.h +43 -6
- data/vendor/libgit2/src/indexer.c +475 -157
- data/vendor/libgit2/src/iterator.c +198 -55
- data/vendor/libgit2/src/iterator.h +28 -4
- data/vendor/libgit2/src/map.h +1 -0
- data/vendor/libgit2/src/merge.c +849 -142
- data/vendor/libgit2/src/merge.h +11 -4
- data/vendor/libgit2/src/merge_file.c +183 -78
- data/vendor/libgit2/src/merge_file.h +0 -57
- data/vendor/libgit2/src/message.c +4 -28
- data/vendor/libgit2/src/mwindow.c +117 -8
- data/vendor/libgit2/src/mwindow.h +9 -1
- data/vendor/libgit2/src/netops.c +164 -59
- data/vendor/libgit2/src/netops.h +37 -1
- data/vendor/libgit2/src/notes.c +9 -18
- data/vendor/libgit2/src/notes.h +1 -1
- data/vendor/libgit2/src/object.c +78 -2
- data/vendor/libgit2/src/odb.c +191 -59
- data/vendor/libgit2/src/odb.h +2 -1
- data/vendor/libgit2/src/odb_loose.c +66 -51
- data/vendor/libgit2/src/odb_mempack.c +182 -0
- data/vendor/libgit2/src/odb_pack.c +151 -61
- data/vendor/libgit2/src/oid.c +30 -19
- data/vendor/libgit2/src/oid.h +13 -10
- data/vendor/libgit2/src/pack-objects.c +198 -147
- data/vendor/libgit2/src/pack-objects.h +7 -0
- data/vendor/libgit2/src/pack.c +272 -101
- data/vendor/libgit2/src/pack.h +15 -1
- data/vendor/libgit2/src/path.c +359 -117
- data/vendor/libgit2/src/path.h +110 -20
- data/vendor/libgit2/src/pathspec.c +583 -57
- data/vendor/libgit2/src/pathspec.h +36 -15
- data/vendor/libgit2/src/pool.c +4 -5
- data/vendor/libgit2/src/posix.c +45 -2
- data/vendor/libgit2/src/posix.h +13 -5
- data/vendor/libgit2/src/pqueue.c +73 -119
- data/vendor/libgit2/src/pqueue.h +35 -82
- data/vendor/libgit2/src/push.c +116 -48
- data/vendor/libgit2/src/push.h +5 -0
- data/vendor/libgit2/src/refdb.c +45 -6
- data/vendor/libgit2/src/refdb.h +13 -3
- data/vendor/libgit2/src/refdb_fs.c +1130 -551
- data/vendor/libgit2/src/reflog.c +36 -327
- data/vendor/libgit2/src/reflog.h +6 -1
- data/vendor/libgit2/src/refs.c +345 -142
- data/vendor/libgit2/src/refs.h +9 -2
- data/vendor/libgit2/src/refspec.c +90 -62
- data/vendor/libgit2/src/refspec.h +7 -24
- data/vendor/libgit2/src/remote.c +815 -415
- data/vendor/libgit2/src/remote.h +3 -4
- data/vendor/libgit2/src/repository.c +360 -207
- data/vendor/libgit2/src/repository.h +16 -10
- data/vendor/libgit2/src/reset.c +28 -13
- data/vendor/libgit2/src/revert.c +228 -0
- data/vendor/libgit2/src/revparse.c +29 -30
- data/vendor/libgit2/src/revwalk.c +141 -96
- data/vendor/libgit2/src/revwalk.h +6 -1
- data/vendor/libgit2/src/settings.c +140 -0
- data/vendor/libgit2/src/sha1_lookup.c +71 -0
- data/vendor/libgit2/src/sha1_lookup.h +5 -0
- data/vendor/libgit2/src/signature.c +38 -10
- data/vendor/libgit2/src/sortedcache.c +378 -0
- data/vendor/libgit2/src/sortedcache.h +178 -0
- data/vendor/libgit2/src/stash.c +98 -116
- data/vendor/libgit2/src/status.c +88 -60
- data/vendor/libgit2/src/status.h +2 -2
- data/vendor/libgit2/src/strmap.c +32 -0
- data/vendor/libgit2/src/strmap.h +14 -1
- data/vendor/libgit2/src/strnlen.h +23 -0
- data/vendor/libgit2/src/submodule.c +1073 -615
- data/vendor/libgit2/src/submodule.h +89 -21
- data/vendor/libgit2/src/sysdir.c +252 -0
- data/vendor/libgit2/src/sysdir.h +101 -0
- data/vendor/libgit2/src/tag.c +31 -20
- data/vendor/libgit2/src/thread-utils.h +98 -17
- data/vendor/libgit2/src/trace.h +0 -2
- data/vendor/libgit2/src/transport.c +76 -6
- data/vendor/libgit2/src/transports/cred.c +164 -61
- data/vendor/libgit2/src/transports/git.c +41 -48
- data/vendor/libgit2/src/transports/http.c +65 -109
- data/vendor/libgit2/src/transports/local.c +88 -65
- data/vendor/libgit2/src/transports/smart.c +91 -19
- data/vendor/libgit2/src/transports/smart.h +13 -5
- data/vendor/libgit2/src/transports/smart_pkt.c +24 -14
- data/vendor/libgit2/src/transports/smart_protocol.c +268 -113
- data/vendor/libgit2/src/transports/ssh.c +284 -186
- data/vendor/libgit2/src/transports/winhttp.c +279 -198
- data/vendor/libgit2/src/tree-cache.c +21 -23
- data/vendor/libgit2/src/tree-cache.h +1 -0
- data/vendor/libgit2/src/tree.c +109 -92
- data/vendor/libgit2/src/tree.h +2 -3
- data/vendor/libgit2/src/unix/map.c +7 -1
- data/vendor/libgit2/src/unix/posix.h +0 -1
- data/vendor/libgit2/src/userdiff.h +208 -0
- data/vendor/libgit2/src/util.c +16 -112
- data/vendor/libgit2/src/util.h +107 -3
- data/vendor/libgit2/src/vector.c +72 -17
- data/vendor/libgit2/src/vector.h +32 -5
- data/vendor/libgit2/src/win32/dir.c +15 -40
- data/vendor/libgit2/src/win32/dir.h +3 -2
- data/vendor/libgit2/src/win32/error.c +5 -31
- data/vendor/libgit2/src/win32/findfile.c +47 -66
- data/vendor/libgit2/src/win32/findfile.h +1 -12
- data/vendor/libgit2/src/win32/git2.rc +40 -0
- data/vendor/libgit2/src/win32/map.c +7 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +3 -0
- data/vendor/libgit2/src/win32/posix.h +17 -11
- data/vendor/libgit2/src/win32/posix_w32.c +424 -292
- data/vendor/libgit2/src/win32/precompiled.h +6 -2
- data/vendor/libgit2/src/win32/pthread.c +141 -18
- data/vendor/libgit2/src/win32/pthread.h +50 -8
- data/vendor/libgit2/src/win32/reparse.h +57 -0
- data/vendor/libgit2/src/win32/utf-conv.c +117 -60
- data/vendor/libgit2/src/win32/utf-conv.h +81 -6
- data/vendor/libgit2/src/win32/version.h +21 -4
- data/vendor/libgit2/src/win32/w32_util.c +139 -0
- data/vendor/libgit2/src/win32/w32_util.h +54 -0
- data/vendor/libgit2/src/zstream.c +156 -0
- data/vendor/libgit2/src/zstream.h +39 -0
- metadata +84 -167
- data/Rakefile +0 -61
- data/ext/rugged/rugged_diff_patch.c +0 -169
- data/lib/rugged/diff/patch.rb +0 -28
- data/test/blob_test.rb +0 -341
- data/test/branch_test.rb +0 -199
- data/test/commit_test.rb +0 -104
- data/test/config_test.rb +0 -45
- data/test/coverage/cover.rb +0 -133
- data/test/diff_test.rb +0 -777
- data/test/errors_test.rb +0 -34
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +0 -1
- data/test/fixtures/attr/attr1 +0 -29
- data/test/fixtures/attr/attr2 +0 -21
- data/test/fixtures/attr/attr3 +0 -4
- data/test/fixtures/attr/binfile +0 -1
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +0 -1
- data/test/fixtures/attr/gitattributes +0 -29
- data/test/fixtures/attr/gitignore +0 -2
- data/test/fixtures/attr/ign +0 -1
- data/test/fixtures/attr/macro_bad +0 -1
- data/test/fixtures/attr/macro_test +0 -1
- data/test/fixtures/attr/root_test1 +0 -1
- data/test/fixtures/attr/root_test2 +0 -6
- data/test/fixtures/attr/root_test3 +0 -19
- data/test/fixtures/attr/root_test4.txt +0 -14
- data/test/fixtures/attr/sub/abc +0 -37
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +0 -1
- data/test/fixtures/attr/sub/ign/file +0 -1
- data/test/fixtures/attr/sub/ign/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/subsub.txt +0 -1
- data/test/fixtures/attr/sub/subdir_test1 +0 -2
- data/test/fixtures/attr/sub/subdir_test2.txt +0 -1
- data/test/fixtures/diff/another.txt +0 -38
- data/test/fixtures/diff/readme.txt +0 -36
- data/test/fixtures/mergedrepo/conflicts-one.txt +0 -5
- data/test/fixtures/mergedrepo/conflicts-two.txt +0 -5
- data/test/fixtures/mergedrepo/one.txt +0 -10
- data/test/fixtures/mergedrepo/two.txt +0 -12
- data/test/fixtures/status/current_file +0 -1
- data/test/fixtures/status/ignored_file +0 -1
- data/test/fixtures/status/modified_file +0 -2
- data/test/fixtures/status/new_file +0 -1
- data/test/fixtures/status/staged_changes +0 -2
- data/test/fixtures/status/staged_changes_modified_file +0 -3
- data/test/fixtures/status/staged_delete_modified_file +0 -1
- data/test/fixtures/status/staged_new_file +0 -1
- data/test/fixtures/status/staged_new_file_modified_file +0 -2
- data/test/fixtures/status/subdir/current_file +0 -1
- data/test/fixtures/status/subdir/modified_file +0 -2
- data/test/fixtures/status/subdir/new_file +0 -1
- data/test/fixtures/status/subdir.txt +0 -2
- data/test/fixtures/status//350/277/231 +0 -1
- data/test/fixtures/testrepo.git/HEAD +0 -1
- data/test/fixtures/testrepo.git/config +0 -13
- data/test/fixtures/testrepo.git/description +0 -1
- data/test/fixtures/testrepo.git/index +0 -0
- data/test/fixtures/testrepo.git/info/exclude +0 -6
- data/test/fixtures/testrepo.git/logs/HEAD +0 -3
- data/test/fixtures/testrepo.git/logs/refs/heads/master +0 -3
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d +0 -0
- data/test/fixtures/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 +0 -0
- data/test/fixtures/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 +0 -0
- data/test/fixtures/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd +0 -0
- data/test/fixtures/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2 +0 -0
- data/test/fixtures/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a +0 -2
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +0 -1
- data/test/fixtures/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 +0 -0
- data/test/fixtures/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 +0 -2
- data/test/fixtures/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 +0 -2
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +0 -1
- data/test/fixtures/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a +0 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d +0 -0
- data/test/fixtures/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 +0 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a +0 -3
- data/test/fixtures/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f +0 -2
- data/test/fixtures/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd +0 -0
- data/test/fixtures/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +0 -3
- data/test/fixtures/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 +0 -3
- data/test/fixtures/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd +0 -3
- data/test/fixtures/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b +0 -0
- data/test/fixtures/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 +0 -0
- data/test/fixtures/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 +0 -0
- data/test/fixtures/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack +0 -0
- data/test/fixtures/testrepo.git/packed-refs +0 -2
- data/test/fixtures/testrepo.git/refs/heads/master +0 -1
- data/test/fixtures/testrepo.git/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v0.9 +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v1.0 +0 -1
- data/test/fixtures/text_file.md +0 -464
- data/test/fixtures/unsymlinked.git/HEAD +0 -1
- data/test/fixtures/unsymlinked.git/config +0 -6
- data/test/fixtures/unsymlinked.git/description +0 -1
- data/test/fixtures/unsymlinked.git/info/exclude +0 -2
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +0 -2
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/master +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +0 -1
- data/test/index_test.rb +0 -333
- data/test/lib_test.rb +0 -127
- data/test/note_test.rb +0 -158
- data/test/object_test.rb +0 -43
- data/test/reference_test.rb +0 -207
- data/test/remote_test.rb +0 -324
- data/test/repo_pack_test.rb +0 -24
- data/test/repo_reset_test.rb +0 -82
- data/test/repo_test.rb +0 -402
- data/test/tag_test.rb +0 -68
- data/test/test_helper.rb +0 -92
- data/test/tree_test.rb +0 -91
- data/test/walker_test.rb +0 -88
- data/vendor/libgit2/src/amiga/map.c +0 -48
- data/vendor/libgit2/src/compress.c +0 -53
@@ -4,7 +4,6 @@
|
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
6
6
|
*/
|
7
|
-
#include <stdarg.h>
|
8
7
|
#include <ctype.h>
|
9
8
|
|
10
9
|
#include "git2/object.h"
|
@@ -17,6 +16,7 @@
|
|
17
16
|
#include "tag.h"
|
18
17
|
#include "blob.h"
|
19
18
|
#include "fileops.h"
|
19
|
+
#include "sysdir.h"
|
20
20
|
#include "filebuf.h"
|
21
21
|
#include "index.h"
|
22
22
|
#include "config.h"
|
@@ -27,14 +27,16 @@
|
|
27
27
|
#include "merge.h"
|
28
28
|
#include "diff_driver.h"
|
29
29
|
|
30
|
+
#ifdef GIT_WIN32
|
31
|
+
# include "win32/w32_util.h"
|
32
|
+
#endif
|
33
|
+
|
30
34
|
#define GIT_FILE_CONTENT_PREFIX "gitdir:"
|
31
35
|
|
32
36
|
#define GIT_BRANCH_MASTER "master"
|
33
37
|
|
34
38
|
#define GIT_REPO_VERSION 0
|
35
39
|
|
36
|
-
#define GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
|
37
|
-
|
38
40
|
static void set_odb(git_repository *repo, git_odb *odb)
|
39
41
|
{
|
40
42
|
if (odb) {
|
@@ -95,6 +97,7 @@ void git_repository__cleanup(git_repository *repo)
|
|
95
97
|
|
96
98
|
git_cache_clear(&repo->objects);
|
97
99
|
git_attr_cache_flush(repo);
|
100
|
+
git_submodule_cache_free(repo);
|
98
101
|
|
99
102
|
set_config(repo, NULL);
|
100
103
|
set_index(repo, NULL);
|
@@ -110,7 +113,6 @@ void git_repository_free(git_repository *repo)
|
|
110
113
|
git_repository__cleanup(repo);
|
111
114
|
|
112
115
|
git_cache_free(&repo->objects);
|
113
|
-
git_submodule_config_free(repo);
|
114
116
|
|
115
117
|
git_diff_driver_registry_free(repo->diff_drivers);
|
116
118
|
repo->diff_drivers = NULL;
|
@@ -167,13 +169,9 @@ int git_repository_new(git_repository **out)
|
|
167
169
|
return 0;
|
168
170
|
}
|
169
171
|
|
170
|
-
static int load_config_data(git_repository *repo)
|
172
|
+
static int load_config_data(git_repository *repo, const git_config *config)
|
171
173
|
{
|
172
174
|
int is_bare;
|
173
|
-
git_config *config;
|
174
|
-
|
175
|
-
if (git_repository_config__weakptr(&config, repo) < 0)
|
176
|
-
return -1;
|
177
175
|
|
178
176
|
/* Try to figure out if it's bare, default to non-bare if it's not set */
|
179
177
|
if (git_config_get_bool(&is_bare, config, "core.bare") < 0)
|
@@ -184,43 +182,37 @@ static int load_config_data(git_repository *repo)
|
|
184
182
|
return 0;
|
185
183
|
}
|
186
184
|
|
187
|
-
static int load_workdir(git_repository *repo, git_buf *parent_path)
|
185
|
+
static int load_workdir(git_repository *repo, git_config *config, git_buf *parent_path)
|
188
186
|
{
|
189
187
|
int error;
|
190
|
-
|
191
|
-
|
192
|
-
git_buf worktree_buf = GIT_BUF_INIT;
|
188
|
+
const git_config_entry *ce;
|
189
|
+
git_buf worktree = GIT_BUF_INIT;
|
193
190
|
|
194
191
|
if (repo->is_bare)
|
195
192
|
return 0;
|
196
193
|
|
197
|
-
if (
|
198
|
-
|
194
|
+
if ((error = git_config__lookup_entry(
|
195
|
+
&ce, config, "core.worktree", false)) < 0)
|
196
|
+
return error;
|
199
197
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
&worktree_buf, worktree, repo->path_repository);
|
204
|
-
if (error < 0)
|
198
|
+
if (ce && ce->value) {
|
199
|
+
if ((error = git_path_prettify_dir(
|
200
|
+
&worktree, ce->value, repo->path_repository)) < 0)
|
205
201
|
return error;
|
206
|
-
|
202
|
+
|
203
|
+
repo->workdir = git_buf_detach(&worktree);
|
207
204
|
}
|
208
|
-
else if (
|
209
|
-
|
205
|
+
else if (parent_path && git_path_isdir(parent_path->ptr))
|
206
|
+
repo->workdir = git_buf_detach(parent_path);
|
210
207
|
else {
|
211
|
-
|
208
|
+
if (git_path_dirname_r(&worktree, repo->path_repository) < 0 ||
|
209
|
+
git_path_to_dir(&worktree) < 0)
|
210
|
+
return -1;
|
212
211
|
|
213
|
-
|
214
|
-
repo->workdir = git_buf_detach(parent_path);
|
215
|
-
else {
|
216
|
-
git_path_dirname_r(&worktree_buf, repo->path_repository);
|
217
|
-
git_path_to_dir(&worktree_buf);
|
218
|
-
repo->workdir = git_buf_detach(&worktree_buf);
|
219
|
-
}
|
212
|
+
repo->workdir = git_buf_detach(&worktree);
|
220
213
|
}
|
221
214
|
|
222
215
|
GITERR_CHECK_ALLOC(repo->workdir);
|
223
|
-
|
224
216
|
return 0;
|
225
217
|
}
|
226
218
|
|
@@ -266,7 +258,7 @@ static int find_ceiling_dir_offset(
|
|
266
258
|
buf[--len] = '\0';
|
267
259
|
|
268
260
|
if (!strncmp(path, buf2, len) &&
|
269
|
-
path[len] == '/' &&
|
261
|
+
(path[len] == '/' || !path[len]) &&
|
270
262
|
len > max_len)
|
271
263
|
{
|
272
264
|
max_len = len;
|
@@ -293,16 +285,20 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
|
|
293
285
|
return -1;
|
294
286
|
|
295
287
|
git_buf_rtrim(&file);
|
288
|
+
/* apparently on Windows, some people use backslashes in paths */
|
289
|
+
git_path_mkposix(file.ptr);
|
296
290
|
|
297
291
|
if (git_buf_len(&file) <= prefix_len ||
|
298
292
|
memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
|
299
293
|
{
|
300
|
-
giterr_set(GITERR_REPOSITORY,
|
294
|
+
giterr_set(GITERR_REPOSITORY,
|
295
|
+
"The `.git` file at '%s' is malformed", file_path);
|
301
296
|
error = -1;
|
302
297
|
}
|
303
298
|
else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
|
304
299
|
const char *gitlink = git_buf_cstr(&file) + prefix_len;
|
305
300
|
while (*gitlink && git__isspace(*gitlink)) gitlink++;
|
301
|
+
|
306
302
|
error = git_path_prettify_dir(
|
307
303
|
path_out, gitlink, git_buf_cstr(path_out));
|
308
304
|
}
|
@@ -322,17 +318,18 @@ static int find_repo(
|
|
322
318
|
git_buf path = GIT_BUF_INIT;
|
323
319
|
struct stat st;
|
324
320
|
dev_t initial_device = 0;
|
325
|
-
bool try_with_dot_git =
|
321
|
+
bool try_with_dot_git = ((flags & GIT_REPOSITORY_OPEN_BARE) != 0);
|
326
322
|
int ceiling_offset;
|
327
323
|
|
328
324
|
git_buf_free(repo_path);
|
329
325
|
|
330
|
-
if ((error =
|
326
|
+
if ((error = git_path_prettify(&path, start_path, NULL)) < 0)
|
331
327
|
return error;
|
332
328
|
|
333
329
|
ceiling_offset = find_ceiling_dir_offset(path.ptr, ceiling_dirs);
|
334
330
|
|
335
|
-
if (
|
331
|
+
if (!try_with_dot_git &&
|
332
|
+
(error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
|
336
333
|
return error;
|
337
334
|
|
338
335
|
while (!error && !git_buf_len(repo_path)) {
|
@@ -384,7 +381,7 @@ static int find_repo(
|
|
384
381
|
try_with_dot_git = !try_with_dot_git;
|
385
382
|
}
|
386
383
|
|
387
|
-
if (!error && parent_path
|
384
|
+
if (!error && parent_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
|
388
385
|
if (!git_buf_len(repo_path))
|
389
386
|
git_buf_clear(parent_path);
|
390
387
|
else {
|
@@ -460,16 +457,24 @@ int git_repository_open_ext(
|
|
460
457
|
repo->path_repository = git_buf_detach(&path);
|
461
458
|
GITERR_CHECK_ALLOC(repo->path_repository);
|
462
459
|
|
463
|
-
if ((
|
464
|
-
|
465
|
-
{
|
466
|
-
|
467
|
-
|
460
|
+
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
|
461
|
+
repo->is_bare = 1;
|
462
|
+
else {
|
463
|
+
git_config *config = NULL;
|
464
|
+
|
465
|
+
if ((error = git_repository_config_snapshot(&config, repo)) < 0 ||
|
466
|
+
(error = load_config_data(repo, config)) < 0 ||
|
467
|
+
(error = load_workdir(repo, config, &parent)) < 0)
|
468
|
+
git_repository_free(repo);
|
469
|
+
|
470
|
+
git_config_free(config);
|
468
471
|
}
|
469
472
|
|
473
|
+
if (!error)
|
474
|
+
*repo_ptr = repo;
|
470
475
|
git_buf_free(&parent);
|
471
|
-
|
472
|
-
return
|
476
|
+
|
477
|
+
return error;
|
473
478
|
}
|
474
479
|
|
475
480
|
int git_repository_open(git_repository **repo_out, const char *path)
|
@@ -492,34 +497,18 @@ int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb)
|
|
492
497
|
}
|
493
498
|
|
494
499
|
int git_repository_discover(
|
495
|
-
|
496
|
-
size_t size,
|
500
|
+
git_buf *out,
|
497
501
|
const char *start_path,
|
498
502
|
int across_fs,
|
499
503
|
const char *ceiling_dirs)
|
500
504
|
{
|
501
|
-
git_buf path = GIT_BUF_INIT;
|
502
505
|
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
|
503
|
-
int error;
|
504
|
-
|
505
|
-
assert(start_path && repository_path && size > 0);
|
506
|
-
|
507
|
-
*repository_path = '\0';
|
508
506
|
|
509
|
-
|
510
|
-
return error != GIT_ENOTFOUND ? -1 : error;
|
507
|
+
assert(start_path);
|
511
508
|
|
512
|
-
|
513
|
-
giterr_set(GITERR_REPOSITORY,
|
514
|
-
"The given buffer is too small to store the discovered path");
|
515
|
-
git_buf_free(&path);
|
516
|
-
return -1;
|
517
|
-
}
|
509
|
+
git_buf_sanitize(out);
|
518
510
|
|
519
|
-
|
520
|
-
git_buf_copy_cstr(repository_path, size, &path);
|
521
|
-
git_buf_free(&path);
|
522
|
-
return 0;
|
511
|
+
return find_repo(out, NULL, start_path, flags, ceiling_dirs);
|
523
512
|
}
|
524
513
|
|
525
514
|
static int load_config(
|
@@ -595,9 +584,9 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
595
584
|
git_buf system_buf = GIT_BUF_INIT;
|
596
585
|
git_config *config;
|
597
586
|
|
598
|
-
|
599
|
-
|
600
|
-
|
587
|
+
git_config_find_global(&global_buf);
|
588
|
+
git_config_find_xdg(&xdg_buf);
|
589
|
+
git_config_find_system(&system_buf);
|
601
590
|
|
602
591
|
/* If there is no global file, open a backend for it anyway */
|
603
592
|
if (git_buf_len(&global_buf) == 0)
|
@@ -636,6 +625,17 @@ int git_repository_config(git_config **out, git_repository *repo)
|
|
636
625
|
return 0;
|
637
626
|
}
|
638
627
|
|
628
|
+
int git_repository_config_snapshot(git_config **out, git_repository *repo)
|
629
|
+
{
|
630
|
+
int error;
|
631
|
+
git_config *weak;
|
632
|
+
|
633
|
+
if ((error = git_repository_config__weakptr(&weak, repo)) < 0)
|
634
|
+
return error;
|
635
|
+
|
636
|
+
return git_config_snapshot(out, weak);
|
637
|
+
}
|
638
|
+
|
639
639
|
void git_repository_set_config(git_repository *repo, git_config *config)
|
640
640
|
{
|
641
641
|
assert(repo && config);
|
@@ -815,7 +815,7 @@ static int repo_init_create_head(const char *git_dir, const char *ref_name)
|
|
815
815
|
const char *fmt;
|
816
816
|
|
817
817
|
if (git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE) < 0 ||
|
818
|
-
git_filebuf_open(&ref, ref_path.ptr, 0) < 0)
|
818
|
+
git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE) < 0)
|
819
819
|
goto fail;
|
820
820
|
|
821
821
|
if (!ref_name)
|
@@ -827,7 +827,7 @@ static int repo_init_create_head(const char *git_dir, const char *ref_name)
|
|
827
827
|
fmt = "ref: " GIT_REFS_HEADS_DIR "%s\n";
|
828
828
|
|
829
829
|
if (git_filebuf_printf(&ref, fmt, ref_name) < 0 ||
|
830
|
-
git_filebuf_commit(&ref
|
830
|
+
git_filebuf_commit(&ref) < 0)
|
831
831
|
goto fail;
|
832
832
|
|
833
833
|
git_buf_free(&ref_path);
|
@@ -842,10 +842,6 @@ fail:
|
|
842
842
|
static bool is_chmod_supported(const char *file_path)
|
843
843
|
{
|
844
844
|
struct stat st1, st2;
|
845
|
-
static int _is_supported = -1;
|
846
|
-
|
847
|
-
if (_is_supported > -1)
|
848
|
-
return _is_supported;
|
849
845
|
|
850
846
|
if (p_stat(file_path, &st1) < 0)
|
851
847
|
return false;
|
@@ -856,27 +852,19 @@ static bool is_chmod_supported(const char *file_path)
|
|
856
852
|
if (p_stat(file_path, &st2) < 0)
|
857
853
|
return false;
|
858
854
|
|
859
|
-
|
860
|
-
|
861
|
-
return _is_supported;
|
855
|
+
return (st1.st_mode != st2.st_mode);
|
862
856
|
}
|
863
857
|
|
864
858
|
static bool is_filesystem_case_insensitive(const char *gitdir_path)
|
865
859
|
{
|
866
860
|
git_buf path = GIT_BUF_INIT;
|
867
|
-
|
861
|
+
int is_insensitive = -1;
|
868
862
|
|
869
|
-
if (
|
870
|
-
|
863
|
+
if (!git_buf_joinpath(&path, gitdir_path, "CoNfIg"))
|
864
|
+
is_insensitive = git_path_exists(git_buf_cstr(&path));
|
871
865
|
|
872
|
-
if (git_buf_joinpath(&path, gitdir_path, "CoNfIg") < 0)
|
873
|
-
goto cleanup;
|
874
|
-
|
875
|
-
_is_insensitive = git_path_exists(git_buf_cstr(&path));
|
876
|
-
|
877
|
-
cleanup:
|
878
866
|
git_buf_free(&path);
|
879
|
-
return
|
867
|
+
return is_insensitive;
|
880
868
|
}
|
881
869
|
|
882
870
|
static bool are_symlinks_supported(const char *wd_path)
|
@@ -884,24 +872,21 @@ static bool are_symlinks_supported(const char *wd_path)
|
|
884
872
|
git_buf path = GIT_BUF_INIT;
|
885
873
|
int fd;
|
886
874
|
struct stat st;
|
887
|
-
|
875
|
+
int symlinks_supported = -1;
|
888
876
|
|
889
|
-
if (
|
890
|
-
return _symlinks_supported;
|
891
|
-
|
892
|
-
if ((fd = git_futils_mktmp(&path, wd_path)) < 0 ||
|
877
|
+
if ((fd = git_futils_mktmp(&path, wd_path, 0666)) < 0 ||
|
893
878
|
p_close(fd) < 0 ||
|
894
879
|
p_unlink(path.ptr) < 0 ||
|
895
880
|
p_symlink("testing", path.ptr) < 0 ||
|
896
881
|
p_lstat(path.ptr, &st) < 0)
|
897
|
-
|
882
|
+
symlinks_supported = false;
|
898
883
|
else
|
899
|
-
|
884
|
+
symlinks_supported = (S_ISLNK(st.st_mode) != 0);
|
900
885
|
|
901
886
|
(void)p_unlink(path.ptr);
|
902
887
|
git_buf_free(&path);
|
903
888
|
|
904
|
-
return
|
889
|
+
return symlinks_supported;
|
905
890
|
}
|
906
891
|
|
907
892
|
static int create_empty_file(const char *path, mode_t mode)
|
@@ -921,71 +906,132 @@ static int create_empty_file(const char *path, mode_t mode)
|
|
921
906
|
return 0;
|
922
907
|
}
|
923
908
|
|
909
|
+
static int repo_local_config(
|
910
|
+
git_config **out,
|
911
|
+
git_buf *config_dir,
|
912
|
+
git_repository *repo,
|
913
|
+
const char *repo_dir)
|
914
|
+
{
|
915
|
+
int error = 0;
|
916
|
+
git_config *parent;
|
917
|
+
const char *cfg_path;
|
918
|
+
|
919
|
+
if (git_buf_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
|
920
|
+
return -1;
|
921
|
+
cfg_path = git_buf_cstr(config_dir);
|
922
|
+
|
923
|
+
/* make LOCAL config if missing */
|
924
|
+
if (!git_path_isfile(cfg_path) &&
|
925
|
+
(error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
|
926
|
+
return error;
|
927
|
+
|
928
|
+
/* if no repo, just open that file directly */
|
929
|
+
if (!repo)
|
930
|
+
return git_config_open_ondisk(out, cfg_path);
|
931
|
+
|
932
|
+
/* otherwise, open parent config and get that level */
|
933
|
+
if ((error = git_repository_config__weakptr(&parent, repo)) < 0)
|
934
|
+
return error;
|
935
|
+
|
936
|
+
if (git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL) < 0) {
|
937
|
+
giterr_clear();
|
938
|
+
|
939
|
+
if (!(error = git_config_add_file_ondisk(
|
940
|
+
parent, cfg_path, GIT_CONFIG_LEVEL_LOCAL, false)))
|
941
|
+
error = git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL);
|
942
|
+
}
|
943
|
+
|
944
|
+
git_config_free(parent);
|
945
|
+
|
946
|
+
return error;
|
947
|
+
}
|
948
|
+
|
949
|
+
static int repo_init_fs_configs(
|
950
|
+
git_config *cfg,
|
951
|
+
const char *cfg_path,
|
952
|
+
const char *repo_dir,
|
953
|
+
const char *work_dir,
|
954
|
+
bool update_ignorecase)
|
955
|
+
{
|
956
|
+
int error = 0;
|
957
|
+
|
958
|
+
if (!work_dir)
|
959
|
+
work_dir = repo_dir;
|
960
|
+
|
961
|
+
if ((error = git_config_set_bool(
|
962
|
+
cfg, "core.filemode", is_chmod_supported(cfg_path))) < 0)
|
963
|
+
return error;
|
964
|
+
|
965
|
+
if (!are_symlinks_supported(work_dir)) {
|
966
|
+
if ((error = git_config_set_bool(cfg, "core.symlinks", false)) < 0)
|
967
|
+
return error;
|
968
|
+
} else if (git_config_delete_entry(cfg, "core.symlinks") < 0)
|
969
|
+
giterr_clear();
|
970
|
+
|
971
|
+
if (update_ignorecase) {
|
972
|
+
if (is_filesystem_case_insensitive(repo_dir)) {
|
973
|
+
if ((error = git_config_set_bool(cfg, "core.ignorecase", true)) < 0)
|
974
|
+
return error;
|
975
|
+
} else if (git_config_delete_entry(cfg, "core.ignorecase") < 0)
|
976
|
+
giterr_clear();
|
977
|
+
}
|
978
|
+
|
979
|
+
#ifdef GIT_USE_ICONV
|
980
|
+
if ((error = git_config_set_bool(
|
981
|
+
cfg, "core.precomposeunicode",
|
982
|
+
git_path_does_fs_decompose_unicode(work_dir))) < 0)
|
983
|
+
return error;
|
984
|
+
/* on non-iconv platforms, don't even set core.precomposeunicode */
|
985
|
+
#endif
|
986
|
+
|
987
|
+
return 0;
|
988
|
+
}
|
989
|
+
|
924
990
|
static int repo_init_config(
|
925
991
|
const char *repo_dir,
|
926
992
|
const char *work_dir,
|
927
|
-
|
993
|
+
uint32_t flags,
|
994
|
+
uint32_t mode)
|
928
995
|
{
|
929
996
|
int error = 0;
|
930
997
|
git_buf cfg_path = GIT_BUF_INIT;
|
931
998
|
git_config *config = NULL;
|
999
|
+
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
|
1000
|
+
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
|
932
1001
|
|
933
|
-
|
934
|
-
|
935
|
-
goto cleanup; } while (0)
|
1002
|
+
if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
|
1003
|
+
goto cleanup;
|
936
1004
|
|
937
|
-
if (
|
938
|
-
|
1005
|
+
if (is_reinit && (error = check_repositoryformatversion(config)) < 0)
|
1006
|
+
goto cleanup;
|
939
1007
|
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
return -1;
|
944
|
-
}
|
1008
|
+
#define SET_REPO_CONFIG(TYPE, NAME, VAL) do { \
|
1009
|
+
if ((error = git_config_set_##TYPE(config, NAME, VAL)) < 0) \
|
1010
|
+
goto cleanup; } while (0)
|
945
1011
|
|
946
|
-
|
947
|
-
|
948
|
-
return -1;
|
949
|
-
}
|
1012
|
+
SET_REPO_CONFIG(bool, "core.bare", is_bare);
|
1013
|
+
SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
|
950
1014
|
|
951
|
-
if ((
|
952
|
-
|
1015
|
+
if ((error = repo_init_fs_configs(
|
1016
|
+
config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0)
|
953
1017
|
goto cleanup;
|
954
1018
|
|
955
|
-
|
956
|
-
bool, "core.bare", (opts->flags & GIT_REPOSITORY_INIT_BARE) != 0);
|
957
|
-
SET_REPO_CONFIG(
|
958
|
-
int32, "core.repositoryformatversion", GIT_REPO_VERSION);
|
959
|
-
SET_REPO_CONFIG(
|
960
|
-
bool, "core.filemode", is_chmod_supported(git_buf_cstr(&cfg_path)));
|
961
|
-
|
962
|
-
if (!(opts->flags & GIT_REPOSITORY_INIT_BARE)) {
|
1019
|
+
if (!is_bare) {
|
963
1020
|
SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
|
964
1021
|
|
965
|
-
if (!
|
966
|
-
SET_REPO_CONFIG(bool, "core.symlinks", false);
|
967
|
-
|
968
|
-
if (!(opts->flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
|
1022
|
+
if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD))
|
969
1023
|
SET_REPO_CONFIG(string, "core.worktree", work_dir);
|
970
|
-
|
971
|
-
else if ((opts->flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0) {
|
1024
|
+
else if (is_reinit) {
|
972
1025
|
if (git_config_delete_entry(config, "core.worktree") < 0)
|
973
1026
|
giterr_clear();
|
974
1027
|
}
|
975
|
-
} else {
|
976
|
-
if (!are_symlinks_supported(repo_dir))
|
977
|
-
SET_REPO_CONFIG(bool, "core.symlinks", false);
|
978
1028
|
}
|
979
1029
|
|
980
|
-
if (
|
981
|
-
is_filesystem_case_insensitive(repo_dir))
|
982
|
-
SET_REPO_CONFIG(bool, "core.ignorecase", true);
|
983
|
-
|
984
|
-
if (opts->mode == GIT_REPOSITORY_INIT_SHARED_GROUP) {
|
1030
|
+
if (mode == GIT_REPOSITORY_INIT_SHARED_GROUP) {
|
985
1031
|
SET_REPO_CONFIG(int32, "core.sharedrepository", 1);
|
986
1032
|
SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true);
|
987
1033
|
}
|
988
|
-
else if (
|
1034
|
+
else if (mode == GIT_REPOSITORY_INIT_SHARED_ALL) {
|
989
1035
|
SET_REPO_CONFIG(int32, "core.sharedrepository", 2);
|
990
1036
|
SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true);
|
991
1037
|
}
|
@@ -997,6 +1043,41 @@ cleanup:
|
|
997
1043
|
return error;
|
998
1044
|
}
|
999
1045
|
|
1046
|
+
static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
|
1047
|
+
{
|
1048
|
+
git_repository *smrepo = NULL;
|
1049
|
+
GIT_UNUSED(n); GIT_UNUSED(p);
|
1050
|
+
|
1051
|
+
if (git_submodule_open(&smrepo, sm) < 0 ||
|
1052
|
+
git_repository_reinit_filesystem(smrepo, true) < 0)
|
1053
|
+
giterr_clear();
|
1054
|
+
git_repository_free(smrepo);
|
1055
|
+
|
1056
|
+
return 0;
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
1060
|
+
{
|
1061
|
+
int error = 0;
|
1062
|
+
git_buf path = GIT_BUF_INIT;
|
1063
|
+
git_config *config = NULL;
|
1064
|
+
const char *repo_dir = git_repository_path(repo);
|
1065
|
+
|
1066
|
+
if (!(error = repo_local_config(&config, &path, repo, repo_dir)))
|
1067
|
+
error = repo_init_fs_configs(
|
1068
|
+
config, path.ptr, repo_dir, git_repository_workdir(repo), true);
|
1069
|
+
|
1070
|
+
git_config_free(config);
|
1071
|
+
git_buf_free(&path);
|
1072
|
+
|
1073
|
+
git_repository__cvar_cache_clear(repo);
|
1074
|
+
|
1075
|
+
if (!repo->is_bare && recurse)
|
1076
|
+
(void)git_submodule_foreach(repo, repo_reinit_submodule_fs, NULL);
|
1077
|
+
|
1078
|
+
return error;
|
1079
|
+
}
|
1080
|
+
|
1000
1081
|
static int repo_write_template(
|
1001
1082
|
const char *git_dir,
|
1002
1083
|
bool allow_overwrite,
|
@@ -1028,7 +1109,7 @@ static int repo_write_template(
|
|
1028
1109
|
|
1029
1110
|
#ifdef GIT_WIN32
|
1030
1111
|
if (!error && hidden) {
|
1031
|
-
if (
|
1112
|
+
if (git_win32__sethidden(path.ptr) < 0)
|
1032
1113
|
error = -1;
|
1033
1114
|
}
|
1034
1115
|
#else
|
@@ -1109,12 +1190,13 @@ static int repo_init_structure(
|
|
1109
1190
|
bool external_tpl =
|
1110
1191
|
((opts->flags & GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE) != 0);
|
1111
1192
|
mode_t dmode = pick_dir_mode(opts);
|
1193
|
+
bool chmod = opts->mode != GIT_REPOSITORY_INIT_SHARED_UMASK;
|
1112
1194
|
|
1113
1195
|
/* Hide the ".git" directory */
|
1114
1196
|
#ifdef GIT_WIN32
|
1115
1197
|
if ((opts->flags & GIT_REPOSITORY_INIT__HAS_DOTGIT) != 0) {
|
1116
|
-
if (
|
1117
|
-
giterr_set(
|
1198
|
+
if (git_win32__sethidden(repo_dir) < 0) {
|
1199
|
+
giterr_set(GITERR_OS,
|
1118
1200
|
"Failed to mark Git repository folder as hidden");
|
1119
1201
|
return -1;
|
1120
1202
|
}
|
@@ -1131,31 +1213,36 @@ static int repo_init_structure(
|
|
1131
1213
|
|
1132
1214
|
/* Copy external template if requested */
|
1133
1215
|
if (external_tpl) {
|
1134
|
-
git_config *cfg;
|
1135
|
-
const char *tdir;
|
1216
|
+
git_config *cfg = NULL;
|
1217
|
+
const char *tdir = NULL;
|
1218
|
+
bool default_template = false;
|
1219
|
+
git_buf template_buf = GIT_BUF_INIT;
|
1136
1220
|
|
1137
1221
|
if (opts->template_path)
|
1138
1222
|
tdir = opts->template_path;
|
1139
|
-
else if ((error = git_config_open_default(&cfg))
|
1140
|
-
return error;
|
1141
|
-
else {
|
1223
|
+
else if ((error = git_config_open_default(&cfg)) >= 0) {
|
1142
1224
|
error = git_config_get_string(&tdir, cfg, "init.templatedir");
|
1225
|
+
giterr_clear();
|
1226
|
+
}
|
1143
1227
|
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1228
|
+
if (!tdir) {
|
1229
|
+
if (!(error = git_sysdir_find_template_dir(&template_buf)))
|
1230
|
+
tdir = template_buf.ptr;
|
1231
|
+
default_template = true;
|
1232
|
+
}
|
1148
1233
|
|
1149
|
-
|
1150
|
-
|
1234
|
+
if (tdir) {
|
1235
|
+
uint32_t cpflags = GIT_CPDIR_COPY_SYMLINKS | GIT_CPDIR_SIMPLE_TO_MODE;
|
1236
|
+
if (opts->mode != GIT_REPOSITORY_INIT_SHARED_UMASK)
|
1237
|
+
cpflags |= GIT_CPDIR_CHMOD_DIRS;
|
1238
|
+
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
|
1151
1239
|
}
|
1152
1240
|
|
1153
|
-
|
1154
|
-
|
1155
|
-
GIT_CPDIR_SIMPLE_TO_MODE, dmode);
|
1241
|
+
git_buf_free(&template_buf);
|
1242
|
+
git_config_free(cfg);
|
1156
1243
|
|
1157
1244
|
if (error < 0) {
|
1158
|
-
if (
|
1245
|
+
if (!default_template)
|
1159
1246
|
return error;
|
1160
1247
|
|
1161
1248
|
/* if template was default, ignore error and use internal */
|
@@ -1170,9 +1257,14 @@ static int repo_init_structure(
|
|
1170
1257
|
* - only create files if no external template was specified
|
1171
1258
|
*/
|
1172
1259
|
for (tpl = repo_template; !error && tpl->path; ++tpl) {
|
1173
|
-
if (!tpl->content)
|
1260
|
+
if (!tpl->content) {
|
1261
|
+
uint32_t mkdir_flags = GIT_MKDIR_PATH;
|
1262
|
+
if (chmod)
|
1263
|
+
mkdir_flags |= GIT_MKDIR_CHMOD;
|
1264
|
+
|
1174
1265
|
error = git_futils_mkdir(
|
1175
|
-
tpl->path, repo_dir, dmode,
|
1266
|
+
tpl->path, repo_dir, dmode, mkdir_flags);
|
1267
|
+
}
|
1176
1268
|
else if (!external_tpl) {
|
1177
1269
|
const char *content = tpl->content;
|
1178
1270
|
|
@@ -1382,22 +1474,22 @@ int git_repository_init_ext(
|
|
1382
1474
|
opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
|
1383
1475
|
|
1384
1476
|
error = repo_init_config(
|
1385
|
-
|
1477
|
+
repo_path.ptr, wd_path.ptr, opts->flags, opts->mode);
|
1386
1478
|
|
1387
1479
|
/* TODO: reinitialize the templates */
|
1388
1480
|
}
|
1389
1481
|
else {
|
1390
1482
|
if (!(error = repo_init_structure(
|
1391
|
-
|
1483
|
+
repo_path.ptr, wd_path.ptr, opts)) &&
|
1392
1484
|
!(error = repo_init_config(
|
1393
|
-
|
1485
|
+
repo_path.ptr, wd_path.ptr, opts->flags, opts->mode)))
|
1394
1486
|
error = repo_init_create_head(
|
1395
|
-
|
1487
|
+
repo_path.ptr, opts->initial_head);
|
1396
1488
|
}
|
1397
1489
|
if (error < 0)
|
1398
1490
|
goto cleanup;
|
1399
1491
|
|
1400
|
-
error = git_repository_open(out,
|
1492
|
+
error = git_repository_open(out, repo_path.ptr);
|
1401
1493
|
|
1402
1494
|
if (!error && opts->origin_url)
|
1403
1495
|
error = repo_init_create_origin(*out, opts->origin_url);
|
@@ -1448,10 +1540,10 @@ int git_repository_head(git_reference **head_out, git_repository *repo)
|
|
1448
1540
|
error = git_reference_lookup_resolved(head_out, repo, git_reference_symbolic_target(head), -1);
|
1449
1541
|
git_reference_free(head);
|
1450
1542
|
|
1451
|
-
return error == GIT_ENOTFOUND ?
|
1543
|
+
return error == GIT_ENOTFOUND ? GIT_EUNBORNBRANCH : error;
|
1452
1544
|
}
|
1453
1545
|
|
1454
|
-
int
|
1546
|
+
int git_repository_head_unborn(git_repository *repo)
|
1455
1547
|
{
|
1456
1548
|
git_reference *ref = NULL;
|
1457
1549
|
int error;
|
@@ -1459,7 +1551,7 @@ int git_repository_head_orphan(git_repository *repo)
|
|
1459
1551
|
error = git_repository_head(&ref, repo);
|
1460
1552
|
git_reference_free(ref);
|
1461
1553
|
|
1462
|
-
if (error ==
|
1554
|
+
if (error == GIT_EUNBORNBRANCH)
|
1463
1555
|
return 1;
|
1464
1556
|
|
1465
1557
|
if (error < 0)
|
@@ -1472,15 +1564,14 @@ static int at_least_one_cb(const char *refname, void *payload)
|
|
1472
1564
|
{
|
1473
1565
|
GIT_UNUSED(refname);
|
1474
1566
|
GIT_UNUSED(payload);
|
1475
|
-
|
1476
|
-
return GIT_EUSER;
|
1567
|
+
return GIT_PASSTHROUGH;
|
1477
1568
|
}
|
1478
1569
|
|
1479
1570
|
static int repo_contains_no_reference(git_repository *repo)
|
1480
1571
|
{
|
1481
1572
|
int error = git_reference_foreach_name(repo, &at_least_one_cb, NULL);
|
1482
1573
|
|
1483
|
-
if (error ==
|
1574
|
+
if (error == GIT_PASSTHROUGH)
|
1484
1575
|
return 0;
|
1485
1576
|
|
1486
1577
|
if (!error)
|
@@ -1492,24 +1583,20 @@ static int repo_contains_no_reference(git_repository *repo)
|
|
1492
1583
|
int git_repository_is_empty(git_repository *repo)
|
1493
1584
|
{
|
1494
1585
|
git_reference *head = NULL;
|
1495
|
-
int
|
1586
|
+
int is_empty = 0;
|
1496
1587
|
|
1497
1588
|
if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0)
|
1498
1589
|
return -1;
|
1499
1590
|
|
1500
|
-
if (
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
GIT_REFS_HEADS_DIR "master") == 0))
|
1506
|
-
goto cleanup;
|
1507
|
-
|
1508
|
-
error = repo_contains_no_reference(repo);
|
1591
|
+
if (git_reference_type(head) == GIT_REF_SYMBOLIC)
|
1592
|
+
is_empty =
|
1593
|
+
(strcmp(git_reference_symbolic_target(head),
|
1594
|
+
GIT_REFS_HEADS_DIR "master") == 0) &&
|
1595
|
+
repo_contains_no_reference(repo);
|
1509
1596
|
|
1510
|
-
cleanup:
|
1511
1597
|
git_reference_free(head);
|
1512
|
-
|
1598
|
+
|
1599
|
+
return is_empty;
|
1513
1600
|
}
|
1514
1601
|
|
1515
1602
|
const char *git_repository_path(git_repository *repo)
|
@@ -1597,14 +1684,13 @@ cleanup:
|
|
1597
1684
|
return error;
|
1598
1685
|
}
|
1599
1686
|
|
1600
|
-
int git_repository_message(
|
1687
|
+
int git_repository_message(git_buf *out, git_repository *repo)
|
1601
1688
|
{
|
1602
|
-
git_buf
|
1689
|
+
git_buf path = GIT_BUF_INIT;
|
1603
1690
|
struct stat st;
|
1604
1691
|
int error;
|
1605
1692
|
|
1606
|
-
|
1607
|
-
*buffer = '\0';
|
1693
|
+
git_buf_sanitize(out);
|
1608
1694
|
|
1609
1695
|
if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
|
1610
1696
|
return -1;
|
@@ -1613,17 +1699,11 @@ int git_repository_message(char *buffer, size_t len, git_repository *repo)
|
|
1613
1699
|
if (errno == ENOENT)
|
1614
1700
|
error = GIT_ENOTFOUND;
|
1615
1701
|
giterr_set(GITERR_OS, "Could not access message file");
|
1616
|
-
}
|
1617
|
-
|
1618
|
-
error = git_futils_readbuffer(&buf, git_buf_cstr(&path));
|
1619
|
-
git_buf_copy_cstr(buffer, len, &buf);
|
1702
|
+
} else {
|
1703
|
+
error = git_futils_readbuffer(out, git_buf_cstr(&path));
|
1620
1704
|
}
|
1621
1705
|
|
1622
1706
|
git_buf_free(&path);
|
1623
|
-
git_buf_free(&buf);
|
1624
|
-
|
1625
|
-
if (!error)
|
1626
|
-
error = (int)st.st_size + 1; /* add 1 for NUL byte */
|
1627
1707
|
|
1628
1708
|
return error;
|
1629
1709
|
}
|
@@ -1650,7 +1730,7 @@ int git_repository_hashfile(
|
|
1650
1730
|
const char *as_path)
|
1651
1731
|
{
|
1652
1732
|
int error;
|
1653
|
-
|
1733
|
+
git_filter_list *fl = NULL;
|
1654
1734
|
git_file fd = -1;
|
1655
1735
|
git_off_t len;
|
1656
1736
|
git_buf full_path = GIT_BUF_INIT;
|
@@ -1672,7 +1752,9 @@ int git_repository_hashfile(
|
|
1672
1752
|
|
1673
1753
|
/* passing empty string for "as_path" indicated --no-filters */
|
1674
1754
|
if (strlen(as_path) > 0) {
|
1675
|
-
error =
|
1755
|
+
error = git_filter_list_load(
|
1756
|
+
&fl, repo, NULL, as_path,
|
1757
|
+
GIT_FILTER_TO_ODB, GIT_FILTER_OPT_DEFAULT);
|
1676
1758
|
if (error < 0)
|
1677
1759
|
return error;
|
1678
1760
|
} else {
|
@@ -1699,12 +1781,12 @@ int git_repository_hashfile(
|
|
1699
1781
|
goto cleanup;
|
1700
1782
|
}
|
1701
1783
|
|
1702
|
-
error = git_odb__hashfd_filtered(out, fd, (size_t)len, type,
|
1784
|
+
error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, fl);
|
1703
1785
|
|
1704
1786
|
cleanup:
|
1705
1787
|
if (fd >= 0)
|
1706
1788
|
p_close(fd);
|
1707
|
-
|
1789
|
+
git_filter_list_free(fl);
|
1708
1790
|
git_buf_free(&full_path);
|
1709
1791
|
|
1710
1792
|
return error;
|
@@ -1717,7 +1799,9 @@ static bool looks_like_a_branch(const char *refname)
|
|
1717
1799
|
|
1718
1800
|
int git_repository_set_head(
|
1719
1801
|
git_repository* repo,
|
1720
|
-
const char* refname
|
1802
|
+
const char* refname,
|
1803
|
+
const git_signature *signature,
|
1804
|
+
const char *log_message)
|
1721
1805
|
{
|
1722
1806
|
git_reference *ref,
|
1723
1807
|
*new_head = NULL;
|
@@ -1730,12 +1814,17 @@ int git_repository_set_head(
|
|
1730
1814
|
return error;
|
1731
1815
|
|
1732
1816
|
if (!error) {
|
1733
|
-
if (git_reference_is_branch(ref))
|
1734
|
-
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1817
|
+
if (git_reference_is_branch(ref)) {
|
1818
|
+
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
1819
|
+
git_reference_name(ref), true, signature, log_message);
|
1820
|
+
} else {
|
1821
|
+
error = git_repository_set_head_detached(repo, git_reference_target(ref),
|
1822
|
+
signature, log_message);
|
1823
|
+
}
|
1824
|
+
} else if (looks_like_a_branch(refname)) {
|
1825
|
+
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
|
1826
|
+
true, signature, log_message);
|
1827
|
+
}
|
1739
1828
|
|
1740
1829
|
git_reference_free(ref);
|
1741
1830
|
git_reference_free(new_head);
|
@@ -1744,7 +1833,9 @@ int git_repository_set_head(
|
|
1744
1833
|
|
1745
1834
|
int git_repository_set_head_detached(
|
1746
1835
|
git_repository* repo,
|
1747
|
-
const git_oid* commitish
|
1836
|
+
const git_oid* commitish,
|
1837
|
+
const git_signature *signature,
|
1838
|
+
const char *log_message)
|
1748
1839
|
{
|
1749
1840
|
int error;
|
1750
1841
|
git_object *object,
|
@@ -1759,7 +1850,7 @@ int git_repository_set_head_detached(
|
|
1759
1850
|
if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0)
|
1760
1851
|
goto cleanup;
|
1761
1852
|
|
1762
|
-
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled),
|
1853
|
+
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, signature, log_message);
|
1763
1854
|
|
1764
1855
|
cleanup:
|
1765
1856
|
git_object_free(object);
|
@@ -1769,7 +1860,9 @@ cleanup:
|
|
1769
1860
|
}
|
1770
1861
|
|
1771
1862
|
int git_repository_detach_head(
|
1772
|
-
git_repository* repo
|
1863
|
+
git_repository* repo,
|
1864
|
+
const git_signature *signature,
|
1865
|
+
const char *reflog_message)
|
1773
1866
|
{
|
1774
1867
|
git_reference *old_head = NULL,
|
1775
1868
|
*new_head = NULL;
|
@@ -1784,7 +1877,8 @@ int git_repository_detach_head(
|
|
1784
1877
|
if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJ_COMMIT)) < 0)
|
1785
1878
|
goto cleanup;
|
1786
1879
|
|
1787
|
-
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
|
1880
|
+
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
|
1881
|
+
1, signature, reflog_message);
|
1788
1882
|
|
1789
1883
|
cleanup:
|
1790
1884
|
git_object_free(object);
|
@@ -1830,6 +1924,53 @@ int git_repository_state(git_repository *repo)
|
|
1830
1924
|
return state;
|
1831
1925
|
}
|
1832
1926
|
|
1927
|
+
int git_repository__cleanup_files(
|
1928
|
+
git_repository *repo, const char *files[], size_t files_len)
|
1929
|
+
{
|
1930
|
+
git_buf buf = GIT_BUF_INIT;
|
1931
|
+
size_t i;
|
1932
|
+
int error;
|
1933
|
+
|
1934
|
+
for (error = 0, i = 0; !error && i < files_len; ++i) {
|
1935
|
+
const char *path;
|
1936
|
+
|
1937
|
+
if (git_buf_joinpath(&buf, repo->path_repository, files[i]) < 0)
|
1938
|
+
return -1;
|
1939
|
+
|
1940
|
+
path = git_buf_cstr(&buf);
|
1941
|
+
|
1942
|
+
if (git_path_isfile(path)) {
|
1943
|
+
error = p_unlink(path);
|
1944
|
+
} else if (git_path_isdir(path)) {
|
1945
|
+
error = git_futils_rmdir_r(path, NULL,
|
1946
|
+
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
|
1947
|
+
}
|
1948
|
+
|
1949
|
+
git_buf_clear(&buf);
|
1950
|
+
}
|
1951
|
+
|
1952
|
+
git_buf_free(&buf);
|
1953
|
+
return error;
|
1954
|
+
}
|
1955
|
+
|
1956
|
+
static const char *state_files[] = {
|
1957
|
+
GIT_MERGE_HEAD_FILE,
|
1958
|
+
GIT_MERGE_MODE_FILE,
|
1959
|
+
GIT_MERGE_MSG_FILE,
|
1960
|
+
GIT_REVERT_HEAD_FILE,
|
1961
|
+
GIT_CHERRY_PICK_HEAD_FILE,
|
1962
|
+
GIT_BISECT_LOG_FILE,
|
1963
|
+
GIT_REBASE_MERGE_DIR,
|
1964
|
+
GIT_REBASE_APPLY_DIR,
|
1965
|
+
};
|
1966
|
+
|
1967
|
+
int git_repository_state_cleanup(git_repository *repo)
|
1968
|
+
{
|
1969
|
+
assert(repo);
|
1970
|
+
|
1971
|
+
return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
|
1972
|
+
}
|
1973
|
+
|
1833
1974
|
int git_repository_is_shallow(git_repository *repo)
|
1834
1975
|
{
|
1835
1976
|
git_buf path = GIT_BUF_INIT;
|
@@ -1840,9 +1981,21 @@ int git_repository_is_shallow(git_repository *repo)
|
|
1840
1981
|
error = git_path_lstat(path.ptr, &st);
|
1841
1982
|
git_buf_free(&path);
|
1842
1983
|
|
1843
|
-
if (error == GIT_ENOTFOUND)
|
1984
|
+
if (error == GIT_ENOTFOUND) {
|
1985
|
+
giterr_clear();
|
1844
1986
|
return 0;
|
1987
|
+
}
|
1988
|
+
|
1845
1989
|
if (error < 0)
|
1846
|
-
return
|
1990
|
+
return error;
|
1847
1991
|
return st.st_size == 0 ? 0 : 1;
|
1848
1992
|
}
|
1993
|
+
|
1994
|
+
int git_repository_init_init_options(
|
1995
|
+
git_repository_init_options *opts, unsigned int version)
|
1996
|
+
{
|
1997
|
+
GIT_INIT_STRUCTURE_FROM_TEMPLATE(
|
1998
|
+
opts, version, git_repository_init_options,
|
1999
|
+
GIT_REPOSITORY_INIT_OPTIONS_INIT);
|
2000
|
+
return 0;
|
2001
|
+
}
|