Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/README.md2
-rw-r--r--tests-clar/attr/attr_expect.h7
-rw-r--r--tests-clar/attr/file.c2
-rw-r--r--tests-clar/attr/ignore.c48
-rw-r--r--tests-clar/attr/lookup.c4
-rw-r--r--tests-clar/attr/repo.c35
-rw-r--r--tests-clar/buf/splice.c93
-rw-r--r--tests-clar/checkout/binaryunicode.c58
-rw-r--r--tests-clar/checkout/checkout_helpers.c93
-rw-r--r--tests-clar/checkout/checkout_helpers.h21
-rw-r--r--tests-clar/checkout/crlf.c147
-rw-r--r--tests-clar/checkout/head.c63
-rw-r--r--tests-clar/checkout/index.c507
-rw-r--r--tests-clar/checkout/tree.c503
-rw-r--r--tests-clar/checkout/typechange.c240
-rwxr-xr-xtests-clar/clar311
-rw-r--r--tests-clar/clar.c431
-rw-r--r--tests-clar/clar.h88
-rw-r--r--tests-clar/clar/fixtures.h38
-rw-r--r--tests-clar/clar/fs.h325
-rw-r--r--tests-clar/clar/print.h60
-rw-r--r--tests-clar/clar/sandbox.h127
-rw-r--r--tests-clar/clar_helpers.c100
-rw-r--r--tests-clar/clar_libgit2.c333
-rw-r--r--tests-clar/clar_libgit2.h42
-rw-r--r--tests-clar/clone/empty.c83
-rw-r--r--tests-clar/clone/nonetwork.c238
-rw-r--r--tests-clar/commit/commit.c4
-rw-r--r--tests-clar/commit/parent.c60
-rw-r--r--tests-clar/commit/parse.c117
-rw-r--r--tests-clar/commit/signature.c48
-rw-r--r--tests-clar/commit/write.c37
-rw-r--r--tests-clar/config/add.c4
-rw-r--r--tests-clar/config/backend.c23
-rw-r--r--tests-clar/config/config_helpers.c37
-rw-r--r--tests-clar/config/config_helpers.h9
-rw-r--r--tests-clar/config/configlevel.c71
-rw-r--r--tests-clar/config/multivar.c10
-rw-r--r--tests-clar/config/new.c10
-rw-r--r--tests-clar/config/read.c281
-rw-r--r--tests-clar/config/refresh.c67
-rw-r--r--tests-clar/config/stress.c59
-rw-r--r--tests-clar/config/validkeyname.c68
-rw-r--r--tests-clar/config/write.c158
-rw-r--r--tests-clar/core/buffer.c389
-rw-r--r--tests-clar/core/copy.c126
-rw-r--r--tests-clar/core/env.c303
-rw-r--r--tests-clar/core/errors.c29
-rw-r--r--tests-clar/core/filebuf.c4
-rw-r--r--tests-clar/core/mkdir.c182
-rw-r--r--tests-clar/core/oid.c12
-rw-r--r--tests-clar/core/opts.c30
-rw-r--r--tests-clar/core/path.c62
-rw-r--r--tests-clar/core/pool.c50
-rw-r--r--tests-clar/core/rmdir.c42
-rw-r--r--tests-clar/core/stat.c97
-rw-r--r--tests-clar/core/vector.c84
-rw-r--r--tests-clar/date/date.c15
-rw-r--r--tests-clar/diff/blob.c477
-rw-r--r--tests-clar/diff/diff_helpers.c171
-rw-r--r--tests-clar/diff/diff_helpers.h60
-rw-r--r--tests-clar/diff/diffiter.c465
-rw-r--r--tests-clar/diff/index.c121
-rw-r--r--tests-clar/diff/iterator.c399
-rw-r--r--tests-clar/diff/notify.c228
-rw-r--r--tests-clar/diff/patch.c232
-rw-r--r--tests-clar/diff/rename.c393
-rw-r--r--tests-clar/diff/submodules.c168
-rw-r--r--tests-clar/diff/tree.c408
-rw-r--r--tests-clar/diff/workdir.c949
-rw-r--r--tests-clar/fetchhead/fetchhead_data.h31
-rw-r--r--tests-clar/fetchhead/nonetwork.c309
-rw-r--r--tests-clar/generate.py244
-rw-r--r--tests-clar/index/conflicts.c242
-rw-r--r--tests-clar/index/filemodes.c153
-rw-r--r--tests-clar/index/inmemory.c22
-rw-r--r--tests-clar/index/read_tree.c10
-rw-r--r--tests-clar/index/rename.c18
-rw-r--r--tests-clar/index/reuc.c373
-rw-r--r--tests-clar/index/stage.c62
-rw-r--r--tests-clar/index/tests.c262
-rw-r--r--tests-clar/main.c20
-rw-r--r--tests-clar/merge/setup.c139
-rw-r--r--tests-clar/network/cred.c50
-rw-r--r--tests-clar/network/fetchlocal.c78
-rw-r--r--tests-clar/network/refspecs.c84
-rw-r--r--tests-clar/network/remote/createthenload.c (renamed from tests-clar/network/createremotethenload.c)10
-rw-r--r--tests-clar/network/remote/isvalidname.c17
-rw-r--r--tests-clar/network/remote/local.c102
-rw-r--r--tests-clar/network/remote/remotes.c388
-rw-r--r--tests-clar/network/remote/rename.c174
-rw-r--r--tests-clar/network/remotelocal.c128
-rw-r--r--tests-clar/network/remotes.c172
-rw-r--r--tests-clar/network/urlparse.c82
-rw-r--r--tests-clar/notes/notes.c330
-rw-r--r--tests-clar/notes/notesref.c19
-rw-r--r--tests-clar/object/blob/filter.c39
-rw-r--r--tests-clar/object/blob/fromchunks.c87
-rw-r--r--tests-clar/object/blob/write.c6
-rw-r--r--tests-clar/object/commit/commitstagedfile.c16
-rw-r--r--tests-clar/object/lookup.c4
-rw-r--r--tests-clar/object/message.c67
-rw-r--r--tests-clar/object/peel.c110
-rw-r--r--tests-clar/object/raw/convert.c4
-rw-r--r--tests-clar/object/raw/hash.c152
-rw-r--r--tests-clar/object/raw/short.c2
-rw-r--r--tests-clar/object/tag/list.c115
-rw-r--r--tests-clar/object/tag/peel.c5
-rw-r--r--tests-clar/object/tag/read.c170
-rw-r--r--tests-clar/object/tag/write.c48
-rw-r--r--tests-clar/object/tree/attributes.c114
-rw-r--r--tests-clar/object/tree/duplicateentries.c157
-rw-r--r--tests-clar/object/tree/frompath.c79
-rw-r--r--tests-clar/object/tree/walk.c103
-rw-r--r--tests-clar/object/tree/write.c190
-rw-r--r--tests-clar/odb/alternates.c80
-rw-r--r--tests-clar/odb/foreach.c80
-rw-r--r--tests-clar/odb/mixed.c1
-rw-r--r--tests-clar/odb/pack_data_one.h19
-rw-r--r--tests-clar/odb/packed.c1
-rw-r--r--tests-clar/odb/packed_one.c59
-rw-r--r--tests-clar/odb/sorting.c4
-rw-r--r--tests-clar/online/clone.c200
-rw-r--r--tests-clar/online/fetch.c163
-rw-r--r--tests-clar/online/fetchhead.c87
-rw-r--r--tests-clar/online/push.c710
-rw-r--r--tests-clar/online/push_util.c126
-rw-r--r--tests-clar/online/push_util.h69
-rw-r--r--tests-clar/pack/packbuilder.c148
-rw-r--r--tests-clar/refdb/inmemory.c213
-rw-r--r--tests-clar/refdb/testdb.c217
-rw-r--r--tests-clar/refdb/testdb.h3
-rw-r--r--tests-clar/refs/branches/create.c89
-rw-r--r--tests-clar/refs/branches/delete.c86
-rw-r--r--tests-clar/refs/branches/foreach.c155
-rw-r--r--tests-clar/refs/branches/ishead.c116
-rw-r--r--tests-clar/refs/branches/listall.c78
-rw-r--r--tests-clar/refs/branches/lookup.c45
-rw-r--r--tests-clar/refs/branches/move.c118
-rw-r--r--tests-clar/refs/branches/name.c45
-rw-r--r--tests-clar/refs/branches/remote.c79
-rw-r--r--tests-clar/refs/branches/upstream.c130
-rw-r--r--tests-clar/refs/branches/upstreamname.c42
-rw-r--r--tests-clar/refs/crashes.c7
-rw-r--r--tests-clar/refs/create.c71
-rw-r--r--tests-clar/refs/delete.c18
-rw-r--r--tests-clar/refs/foreachglob.c95
-rw-r--r--tests-clar/refs/isvalidname.c31
-rw-r--r--tests-clar/refs/list.c19
-rw-r--r--tests-clar/refs/listall.c11
-rw-r--r--tests-clar/refs/lookup.c10
-rw-r--r--tests-clar/refs/normalize.c445
-rw-r--r--tests-clar/refs/overwrite.c44
-rw-r--r--tests-clar/refs/pack.c17
-rw-r--r--tests-clar/refs/peel.c92
-rw-r--r--tests-clar/refs/read.c104
-rw-r--r--tests-clar/refs/ref_helpers.c25
-rw-r--r--tests-clar/refs/ref_helpers.h1
-rw-r--r--tests-clar/refs/reflog.c123
-rw-r--r--tests-clar/refs/reflog/drop.c124
-rw-r--r--tests-clar/refs/reflog/reflog.c186
-rw-r--r--tests-clar/refs/rename.c180
-rw-r--r--tests-clar/refs/revparse.c697
-rw-r--r--tests-clar/refs/setter.c99
-rw-r--r--tests-clar/refs/unicode.c10
-rw-r--r--tests-clar/refs/update.c26
-rw-r--r--tests-clar/repo/discover.c2
-rw-r--r--tests-clar/repo/getters.c64
-rw-r--r--tests-clar/repo/hashfile.c85
-rw-r--r--tests-clar/repo/head.c196
-rw-r--r--tests-clar/repo/headtree.c53
-rw-r--r--tests-clar/repo/init.c371
-rw-r--r--tests-clar/repo/iterator.c810
-rw-r--r--tests-clar/repo/message.c47
-rw-r--r--tests-clar/repo/open.c6
-rw-r--r--tests-clar/repo/repo_helpers.c22
-rw-r--r--tests-clar/repo/repo_helpers.h6
-rw-r--r--tests-clar/repo/setters.c33
-rw-r--r--tests-clar/repo/state.c96
-rw-r--r--tests-clar/reset/default.c180
-rw-r--r--tests-clar/reset/hard.c200
-rw-r--r--tests-clar/reset/mixed.c49
-rw-r--r--tests-clar/reset/reset_helpers.c10
-rw-r--r--tests-clar/reset/reset_helpers.h6
-rw-r--r--tests-clar/reset/soft.c157
-rw-r--r--tests-clar/resources/attr/.gitted/indexbin1856 -> 1856 bytes
-rw-r--r--tests-clar/resources/attr/.gitted/logs/HEAD1
-rw-r--r--tests-clar/resources/attr/.gitted/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512bin0 -> 446 bytes
-rw-r--r--tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b9111
-rw-r--r--tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b1
-rw-r--r--tests-clar/resources/attr/.gitted/objects/b4/35cd5689a0fb54afbeda4ac20368aa480e8f04bin0 -> 40 bytes
-rw-r--r--tests-clar/resources/attr/.gitted/refs/heads/master2
-rw-r--r--tests-clar/resources/attr/gitignore1
-rw-r--r--tests-clar/resources/attr/root_test4.txt4
-rw-r--r--tests-clar/resources/attr/sub/ign1
-rw-r--r--tests-clar/resources/attr/sub/ign/file1
-rw-r--r--tests-clar/resources/attr/sub/ign/sub/file1
-rw-r--r--tests-clar/resources/bad_tag.git/packed-refs2
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/HEAD1
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/config6
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/description1
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/indexbin0 -> 104 bytes
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/info/refs3
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/objects/info/packs2
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.idxbin0 -> 1380 bytes
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.packbin0 -> 20879 bytes
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/refs/heads/branch11
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/refs/heads/branch21
-rw-r--r--tests-clar/resources/binaryunicode/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/binaryunicode/file.txt1
-rw-r--r--tests-clar/resources/config/config112
-rw-r--r--tests-clar/resources/config/config144
-rw-r--r--tests-clar/resources/config/config153
-rw-r--r--tests-clar/resources/config/config163
-rw-r--r--tests-clar/resources/config/config173
-rw-r--r--tests-clar/resources/config/config185
-rw-r--r--tests-clar/resources/config/config195
-rw-r--r--tests-clar/resources/config/config42
-rw-r--r--tests-clar/resources/crlf/.gitted/HEAD1
-rw-r--r--tests-clar/resources/crlf/.gitted/config0
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448cbin0 -> 28 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88bin0 -> 27 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205fbin0 -> 134 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987bin0 -> 29 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb1
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6bin0 -> 25 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3abin0 -> 20 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49bin0 -> 24 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d59661
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62ebin0 -> 159 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112cbin0 -> 32 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511bin0 -> 32 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407fbin0 -> 139 bytes
-rw-r--r--tests-clar/resources/crlf/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/crlf/.gitted/refs/heads/utf81
-rw-r--r--tests-clar/resources/deprecated-mode.git/HEAD1
-rw-r--r--tests-clar/resources/deprecated-mode.git/config6
-rw-r--r--tests-clar/resources/deprecated-mode.git/description1
-rw-r--r--tests-clar/resources/deprecated-mode.git/indexbin0 -> 112 bytes
-rw-r--r--tests-clar/resources/deprecated-mode.git/info/exclude2
-rw-r--r--tests-clar/resources/deprecated-mode.git/objects/06/262edc257418e9987caf999f9a7a3e1547adffbin0 -> 124 bytes
-rw-r--r--tests-clar/resources/deprecated-mode.git/objects/08/10fb7818088ff5ac41ee49199b51473b1bd6c7bin0 -> 350 bytes
-rw-r--r--tests-clar/resources/deprecated-mode.git/objects/1b/05fdaa881ee45b48cbaa5e9b037d667a47745ebin0 -> 57 bytes
-rw-r--r--tests-clar/resources/deprecated-mode.git/objects/3d/0970ec547fc41ef8a5882dde99c6adce65b021bin0 -> 29 bytes
-rw-r--r--tests-clar/resources/deprecated-mode.git/refs/heads/master1
-rw-r--r--tests-clar/resources/diff/.gitted/HEAD1
-rw-r--r--tests-clar/resources/diff/.gitted/config6
-rw-r--r--tests-clar/resources/diff/.gitted/description1
-rw-r--r--tests-clar/resources/diff/.gitted/indexbin0 -> 225 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/diff/.gitted/logs/HEAD2
-rw-r--r--tests-clar/resources/diff/.gitted/logs/refs/heads/master2
-rw-r--r--tests-clar/resources/diff/.gitted/objects/29/ab7053bb4dde0298e03e2c179e890b7dd465a7bin0 -> 730 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/objects/3e/5bcbad2a68e5bc60a53b8388eea53a1a7ab847bin0 -> 1108 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/objects/54/6c735f16a3b44d9784075c2c0dab2ac9bf1989bin0 -> 1110 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/objects/7a/9e0b02e63179929fed24f0a3e0f19168114d10bin0 -> 160 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/objects/7b/808f723a8ca90df319682c221187235af76693bin0 -> 922 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/objects/88/789109439c1e1c3cd45224001edee5304ed53c1
-rw-r--r--tests-clar/resources/diff/.gitted/objects/cb/8294e696339863df760b2ff5d1e275bee72455bin0 -> 86 bytes
-rw-r--r--tests-clar/resources/diff/.gitted/objects/d7/0d245ed97ed2aa596dd1af6536e4bfdb047b691
-rw-r--r--tests-clar/resources/diff/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/diff/another.txt38
-rw-r--r--tests-clar/resources/diff/readme.txt36
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/applypatch-msg.sample15
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/commit-msg.sample24
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/post-update.sample8
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/pre-applypatch.sample14
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/pre-commit.sample50
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/pre-rebase.sample169
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample36
-rwxr-xr-xtests-clar/resources/duplicate.git/hooks/update.sample128
-rw-r--r--tests-clar/resources/filemodes/.gitted/HEAD1
-rw-r--r--tests-clar/resources/filemodes/.gitted/config6
-rw-r--r--tests-clar/resources/filemodes/.gitted/description1
-rw-r--r--tests-clar/resources/filemodes/.gitted/indexbin0 -> 528 bytes
-rw-r--r--tests-clar/resources/filemodes/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/filemodes/.gitted/logs/HEAD1
-rw-r--r--tests-clar/resources/filemodes/.gitted/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964abin0 -> 139 bytes
-rw-r--r--tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1bin0 -> 21 bytes
-rw-r--r--tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182bin0 -> 99 bytes
-rw-r--r--tests-clar/resources/filemodes/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/filemodes/exec_off1
-rwxr-xr-xtests-clar/resources/filemodes/exec_off2on_staged1
-rwxr-xr-xtests-clar/resources/filemodes/exec_off2on_workdir1
-rw-r--r--tests-clar/resources/filemodes/exec_off_untracked1
-rwxr-xr-xtests-clar/resources/filemodes/exec_on1
-rw-r--r--tests-clar/resources/filemodes/exec_on2off_staged1
-rw-r--r--tests-clar/resources/filemodes/exec_on2off_workdir1
-rwxr-xr-xtests-clar/resources/filemodes/exec_on_untracked1
-rw-r--r--tests-clar/resources/icase/.gitted/HEAD1
-rw-r--r--tests-clar/resources/icase/.gitted/config7
-rw-r--r--tests-clar/resources/icase/.gitted/description1
-rw-r--r--tests-clar/resources/icase/.gitted/indexbin0 -> 1392 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/icase/.gitted/logs/HEAD1
-rw-r--r--tests-clar/resources/icase/.gitted/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdcebin0 -> 114 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93bin0 -> 61 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49bin0 -> 19 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be63
-rw-r--r--tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6bin0 -> 21 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/icase/B1
-rw-r--r--tests-clar/resources/icase/D1
-rw-r--r--tests-clar/resources/icase/F1
-rw-r--r--tests-clar/resources/icase/H1
-rw-r--r--tests-clar/resources/icase/J1
-rw-r--r--tests-clar/resources/icase/L/11
-rw-r--r--tests-clar/resources/icase/L/B1
-rw-r--r--tests-clar/resources/icase/L/D1
-rw-r--r--tests-clar/resources/icase/L/a1
-rw-r--r--tests-clar/resources/icase/L/c1
-rw-r--r--tests-clar/resources/icase/a1
-rw-r--r--tests-clar/resources/icase/c1
-rw-r--r--tests-clar/resources/icase/e1
-rw-r--r--tests-clar/resources/icase/g1
-rw-r--r--tests-clar/resources/icase/i1
-rw-r--r--tests-clar/resources/icase/k/11
-rw-r--r--tests-clar/resources/icase/k/B1
-rw-r--r--tests-clar/resources/icase/k/D1
-rw-r--r--tests-clar/resources/icase/k/a1
-rw-r--r--tests-clar/resources/icase/k/c1
-rw-r--r--tests-clar/resources/issue_1397/.gitted/HEAD1
-rw-r--r--tests-clar/resources/issue_1397/.gitted/config6
-rw-r--r--tests-clar/resources/issue_1397/.gitted/indexbin0 -> 233 bytes
-rw-r--r--tests-clar/resources/issue_1397/.gitted/objects/7f/483a738f867e5b21c8f377d70311f011eb48b53
-rw-r--r--tests-clar/resources/issue_1397/.gitted/objects/83/12e0889a9cbab77c732b6bc39b51a683e3a318bin0 -> 48 bytes
-rw-r--r--tests-clar/resources/issue_1397/.gitted/objects/8a/7ef047fc933edb62e84e7977b0612ec3f6f283bin0 -> 141 bytes
-rw-r--r--tests-clar/resources/issue_1397/.gitted/objects/8e/8f80088a9274fd23584992f587083ca1bcbbacbin0 -> 63 bytes
-rw-r--r--tests-clar/resources/issue_1397/.gitted/objects/f2/c62dea0372a0578e053697d5c1ba1ac05e774abin0 -> 94 bytes
-rw-r--r--tests-clar/resources/issue_1397/.gitted/objects/ff/3578d64d199d5b48d92bbb569e0a273e411741bin0 -> 73 bytes
-rw-r--r--tests-clar/resources/issue_1397/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/issue_1397/crlf_file.txt3
-rw-r--r--tests-clar/resources/issue_1397/some_other_crlf_file.txt3
-rw-r--r--tests-clar/resources/issue_592/.gitted/indexbin392 -> 392 bytes
-rwxr-xr-xtests-clar/resources/issue_592b/.gitted/hooks/post-update.sample8
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG1
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/HEAD1
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD1
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/MERGE_MODE0
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/MERGE_MSG5
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD1
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/config6
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/description1
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/indexbin0 -> 842 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/logs/HEAD5
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch2
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master2
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712bin0 -> 141 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91bin0 -> 141 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81bin0 -> 34 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211ebin0 -> 42 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6bin0 -> 159 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534bin0 -> 74 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c8762
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8cbin0 -> 39 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3bin0 -> 36 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52dabin0 -> 36 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46adbin0 -> 45 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399bin0 -> 49 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8bin0 -> 85 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4bin0 -> 41 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71bin0 -> 41 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038cbin0 -> 40 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cdabin0 -> 66 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673bin0 -> 38 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735abin0 -> 78 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2bin0 -> 57 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8bin0 -> 38 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9bin0 -> 39 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50bin0 -> 140 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c51
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092cbin0 -> 36 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0dbin0 -> 66 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff3
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478bin0 -> 87 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406bin0 -> 141 bytes
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/refs/heads/branch1
-rw-r--r--tests-clar/resources/mergedrepo/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/mergedrepo/conflicts-one.txt5
-rw-r--r--tests-clar/resources/mergedrepo/conflicts-two.txt5
-rw-r--r--tests-clar/resources/mergedrepo/one.txt10
-rw-r--r--tests-clar/resources/mergedrepo/two.txt12
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/HEAD1
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/config7
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/indexbin0 -> 328 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08bin0 -> 19 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0ebin0 -> 163 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925bin0 -> 147 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/18/1037049a54a1eb5fab404658a3a250b44335d7bin0 -> 51 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/18/10dff58d8a660512d4832e740f692884338ccdbin0 -> 119 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057bin0 -> 18 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd20452
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63bin0 -> 50 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/5b/5b025afb0b4c913b4c338a42934a3863bf36442
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dccbin0 -> 50 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735bin0 -> 19 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/75/057dd4114e74cca1d750d0aee1647c903cb60abin0 -> 119 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/81/4889a078c031f61ed08ab5fa863aea9314344dbin0 -> 82 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/84/96071c1b46c854b31185ea97743be6a8774479bin0 -> 126 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a3
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f2
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bdbin0 -> 28 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6bin0 -> 26 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd3
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9bin0 -> 162 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83bin0 -> 147 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1bin0 -> 82 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/fa/49b077972391ad58037050f2a75f74e3671e92bin0 -> 24 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/fd/093bff70906175335656e6ce6ae05783708765bin0 -> 82 bytes
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/objects/pack/.gitkeep0
-rw-r--r--tests-clar/resources/partial-testrepo/.gitted/refs/heads/dir1
-rw-r--r--tests-clar/resources/push.sh55
-rw-r--r--tests-clar/resources/push_src/.gitted/COMMIT_EDITMSG1
-rw-r--r--tests-clar/resources/push_src/.gitted/HEAD1
-rw-r--r--tests-clar/resources/push_src/.gitted/ORIG_HEAD1
-rw-r--r--tests-clar/resources/push_src/.gitted/config10
-rw-r--r--tests-clar/resources/push_src/.gitted/description1
-rw-r--r--tests-clar/resources/push_src/.gitted/indexbin0 -> 470 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/HEAD10
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/refs/heads/b11
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/refs/heads/b21
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/refs/heads/b32
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/refs/heads/b42
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/refs/heads/b52
-rw-r--r--tests-clar/resources/push_src/.gitted/logs/refs/heads/master3
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/HEAD1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/config15
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/description1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/indexbin0 -> 256 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/info/exclude6
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/logs/HEAD1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/08/b041783f40edfe12bb406c9c9a8a040177c125bin0 -> 54 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08bin0 -> 19 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/1037049a54a1eb5fab404658a3a250b44335d7bin0 -> 51 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/10dff58d8a660512d4832e740f692884338ccdbin0 -> 119 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fdbin0 -> 122 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/1b/8cbad43e867676df601306689fe7c3def5e689bin0 -> 51 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/1f/67fc4386b2d171e0d21be1c447e12660561f9bbin0 -> 21 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10bin0 -> 168 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/27/0b8ea76056d5cad83af921837702d3e3c2924dbin0 -> 21 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7bin0 -> 44 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/32/59a6bd5b57fb9c1281bb7ed3167b50f224cb54bin0 -> 50 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022ccbin0 -> 23 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057bin0 -> 18 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd20452
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/4b/22b35d44b5a4f589edf3dc89196399771796eabin0 -> 44 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/52/1d87c1ec3aef9824daf6d96cc0ae3710766d91bin0 -> 152 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/5b/5b025afb0b4c913b4c338a42934a3863bf36442
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/75/057dd4114e74cca1d750d0aee1647c903cb60abin0 -> 119 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/76/3d71aadf09a7951596c9746c024e7eece7c7af1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/7b/4384978d2493e851f9cca7858815fac9b10980bin0 -> 145 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/81/4889a078c031f61ed08ab5fa863aea9314344dbin0 -> 82 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/96071c1b46c854b31185ea97743be6a8774479bin0 -> 126 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe2
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe181621
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/9a/03079b8a8ee85a0bee58bf9be3da8b62414ed4bin0 -> 50 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d22
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a3
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f2
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe45477503
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bdbin0 -> 28 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6bin0 -> 26 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/ae/90f12eea699729ed24555e40b9fd669da12a12bin0 -> 148 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d12
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/b6/361fc6a97178d8fc8639fdeed71c775ab52593bin0 -> 80 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f6443
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd3
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659bin0 -> 149 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/d6/c93164c249c8000205dd4ec5cbca1b516d487fbin0 -> 21 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759bin0 -> 79 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391bin0 -> 15 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/e7/b4ad382349ff96dd8199000580b9b1e2042eb0bin0 -> 21 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/f1/425cef211cc08caa31e7b545ffb232acb098c3bin0 -> 103 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1bin0 -> 82 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/fa/49b077972391ad58037050f2a75f74e3671e92bin0 -> 24 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/093bff70906175335656e6ce6ae05783708765bin0 -> 82 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09bin0 -> 152 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idxbin0 -> 46656 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.packbin0 -> 386089 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idxbin0 -> 1240 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.packbin0 -> 491 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idxbin0 -> 1240 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.packbin0 -> 498 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/packed-refs24
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/refs/heads/master1
-rw-r--r--tests-clar/resources/push_src/.gitted/modules/submodule/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/08/585692ce06452da6f82ae66b90d98b55536fca1
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/27/b7ce66243eb1403862d05f958c002312df173d4
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/28/905c54ea45a4bed8d7b90f51bd8bd81eec8840bin0 -> 109 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/36/6226fb970ac0caa9d3f55967ab01334a548f60bin0 -> 20 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/5c/0bb3d1b9449d1cc69d7519fd05166f01840915bin0 -> 128 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/61/780798228d17af2d34fce4cfbdf35556832472bin0 -> 17 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/64/fd55f9b6390202db5e5666fd1fb339089fba4dbin0 -> 176 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/78/981922613b2afb6025042ff6bd878ac1994e85bin0 -> 17 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/80/5c54522e614f29f70d2413a0470247d8b424acbin0 -> 131 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/95/1bbbb90e2259a4c8950db78946784fb53fcbce2
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/a7/8705c3b2725f931d3ee05348d83cc26700f247bin0 -> 166 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/b4/83ae7ba66decee9aee971f501221dea84b14983
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/b4/e1f2b375a64c1ccd40c5ff6aa8bc96839ba4fdbin0 -> 148 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/c1/0409136a7a75e025fa502a1b2fd7b62b77d279bin0 -> 22 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/cd/881f90f2933db2e4cc26b8c71fe6037ac7fe4cbin0 -> 80 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/d9/b63a88223d8367516f50bd131a5f7349b7f3e42
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/dc/ab83249f6f9d1ed735d651352a80519339b591bin0 -> 80 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/f7/8a3106c85fb549c65198b2a2086276c6174928bin0 -> 65 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/f8/f7aefc2900a3d737cea9eee45729fd55761e1abin0 -> 50 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/fa/38b91f199934685819bea316186d8b008c52a22
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/ff/83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e4
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/ff/fe95c7fd0a37fa2ed702f8f93b56b2196b3925bin0 -> 109 bytes
-rw-r--r--tests-clar/resources/push_src/.gitted/objects/pack/dummy0
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/heads/b11
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/heads/b21
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/heads/b31
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/heads/b41
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/heads/b51
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/heads/b61
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/tags/tag-blob1
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/tags/tag-commit1
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/tags/tag-lightweight1
-rw-r--r--tests-clar/resources/push_src/.gitted/refs/tags/tag-tree1
-rw-r--r--tests-clar/resources/push_src/a.txt2
-rw-r--r--tests-clar/resources/push_src/fold/b.txt1
-rw-r--r--tests-clar/resources/push_src/foldb.txt1
-rw-r--r--tests-clar/resources/push_src/gitmodules3
-rw-r--r--tests-clar/resources/push_src/submodule/.gitted1
-rw-r--r--tests-clar/resources/push_src/submodule/README1
-rw-r--r--tests-clar/resources/push_src/submodule/branch_file.txt2
-rw-r--r--tests-clar/resources/push_src/submodule/new.txt1
-rw-r--r--tests-clar/resources/renames/.gitted/HEAD1
-rw-r--r--tests-clar/resources/renames/.gitted/config7
-rw-r--r--tests-clar/resources/renames/.gitted/description1
-rw-r--r--tests-clar/resources/renames/.gitted/indexbin0 -> 352 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/renames/.gitted/logs/HEAD4
-rw-r--r--tests-clar/resources/renames/.gitted/logs/refs/heads/master4
-rw-r--r--tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7bin0 -> 90 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/19/dd32dfb1520a64e5bbaae8dce6ef423dfa2f131
-rw-r--r--tests-clar/resources/renames/.gitted/objects/1c/068dee5790ef1580cfc4cd670915b48d790084bin0 -> 176 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49abin0 -> 173 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2bin0 -> 131 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/36/020db6cdacaa93497f31edcd8f242ff9bc366dbin0 -> 431 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/3c/04741dd4b96c4ae4b00ec0f6e10c816a30aad2bin0 -> 159 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/42/10ffd5c390b21dd5483375e75288dea9ede512bin0 -> 1145 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/4e/4cae3e7dd56ed74bff39526d0469e554432953bin0 -> 452 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/5e/26abc56a5a84d89790f45416648899cbe13109bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745bin0 -> 106 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bbabin0 -> 1155 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/9a/69d960ae94b060f56c2a8702545e2bb1abb935bin0 -> 464 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113bin0 -> 415 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/d7/9b202de198fa61b02424b9e25e840dc75e1323bin0 -> 421 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/objects/ea/f4a3e3bfe68585e90cada20736ace491cd100b5
-rw-r--r--tests-clar/resources/renames/.gitted/objects/f9/0d4fc20ecddf21eebe6a37e9225d244339d2b5bin0 -> 441 bytes
-rw-r--r--tests-clar/resources/renames/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/renames/ikeepsix.txt27
-rw-r--r--tests-clar/resources/renames/sixserving.txt25
-rw-r--r--tests-clar/resources/renames/songof7cities.txt49
-rw-r--r--tests-clar/resources/renames/untimely.txt24
-rw-r--r--tests-clar/resources/short_tag.git/HEAD1
-rw-r--r--tests-clar/resources/short_tag.git/config5
-rw-r--r--tests-clar/resources/short_tag.git/indexbin0 -> 104 bytes
-rw-r--r--tests-clar/resources/short_tag.git/objects/4a/5ed60bafcf4638b7c8356bd4ce1916bfede93cbin0 -> 169 bytes
-rw-r--r--tests-clar/resources/short_tag.git/objects/4d/5fcadc293a348e88f777dc0920f11e7d71441cbin0 -> 48 bytes
-rw-r--r--tests-clar/resources/short_tag.git/objects/5d/a7760512a953e3c7c4e47e4392c7a4338fb7291
-rw-r--r--tests-clar/resources/short_tag.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391bin0 -> 15 bytes
-rw-r--r--tests-clar/resources/short_tag.git/packed-refs1
-rw-r--r--tests-clar/resources/short_tag.git/refs/heads/master1
-rw-r--r--tests-clar/resources/status/.gitted/indexbin1160 -> 1160 bytes
-rw-r--r--tests-clar/resources/status/è¿™1
-rw-r--r--tests-clar/resources/submod2/.gitted/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/config20
-rw-r--r--tests-clar/resources/submod2/.gitted/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/indexbin0 -> 944 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/logs/HEAD4
-rw-r--r--tests-clar/resources/submod2/.gitted/logs/refs/heads/master4
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/COMMIT_EDITMSG1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/HEAD2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/heads/master2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/3d/9386c507f6b093471a3e324085657a3c2b42473
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/77/fb0ed3e58568d6ad362c78de08ab8649d76e29bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/8e/b1e637ed9fc8e5454fa20d38f809091f9395f42
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/a0/2d31770687965547ab7a04cee199b29ee458d6bin0 -> 134 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/config13
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/description1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/info/exclude6
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/packed-refs2
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/09/460e5b6cbcb05a3e404593c32a3aa7221eca0ebin0 -> 197 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/14/fe9ccf104058df25e0a08361c4494e167ef2431
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/22/ce3e0311dda73a5992d54a4a595518d3876ea74
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/25/5546424b0efb847b1bfc91dbf7348b277f8970bin0 -> 157 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/2a/30f1e6f94b20917005a21273f65b406d0f8badbin0 -> 144 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/42/cfb95cd01bf9225b659b5ee3edcc78e8eeb478bin0 -> 40 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/57/958699c2dc394f81cfc76950e9c3ac3025c398bin0 -> 136 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/59/01da4f1c67756eeadc5121d206bec2431f253b2
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/60/7d96653d4d0a4f733107f7890c2e67b55b620dbin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/74/84482eb8db738cafa696993664607500a3f2b9bin0 -> 173 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/7b/a4c5c3561daa5ab1a86215cfb0587e96d404d6bin0 -> 48 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/87/3585b94bdeabccea991ea5e3ec1a277895b698bin0 -> 137 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/97/4cf7c73de336b0c4e019f918f3cee367d72e842
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/9d/bc299bc013ea253583b40bf327b5a6e4037b89bin0 -> 80 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/a9/104bf89e911387244ef499413960ba472066d9bin0 -> 165 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/b6/14088620bbdc1d29549d223ceba0f4419fd4cbbin0 -> 110 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/d4/07f19e50c1da1ff584beafe0d6dac7237c5d06bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/d9/3e95571d92cceb5de28c205f1d5f3cc8b88bc82
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/e3/b83bf274ee065eee48734cf8c6dfaf5e81471cbin0 -> 246 bytes
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/f5/4414c25e6d24fe39f5c3f128d7c8a17bc238332
-rw-r--r--tests-clar/resources/submod2/.gitted/objects/f9/90a25a74d1a8281ce2ab018ea8df66795cd60b1
-rw-r--r--tests-clar/resources/submod2/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/README.txt3
-rw-r--r--tests-clar/resources/submod2/gitmodules24
-rw-r--r--tests-clar/resources/submod2/just_a_dir/contents1
-rw-r--r--tests-clar/resources/submod2/just_a_file1
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/HEAD1
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/config6
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/description1
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/indexbin0 -> 112 bytes
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/logs/HEAD1
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444bin0 -> 132 bytes
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627bin0 -> 52 bytes
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195ebin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2/not-submodule/README.txt1
-rw-r--r--tests-clar/resources/submod2/not/.gitted/notempty1
-rw-r--r--tests-clar/resources/submod2/not/README.txt1
-rw-r--r--tests-clar/resources/submod2/sm_added_and_uncommited/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_added_and_uncommited/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_added_and_uncommited/file_to_modify3
-rw-r--r--tests-clar/resources/submod2/sm_changed_file/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_changed_file/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_changed_file/file_to_modify4
-rw-r--r--tests-clar/resources/submod2/sm_changed_head/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_changed_head/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_changed_head/file_to_modify4
-rw-r--r--tests-clar/resources/submod2/sm_changed_index/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_changed_index/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_changed_index/file_to_modify4
-rw-r--r--tests-clar/resources/submod2/sm_changed_untracked_file/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_changed_untracked_file/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_changed_untracked_file/file_to_modify3
-rw-r--r--tests-clar/resources/submod2/sm_changed_untracked_file/i_am_untracked1
-rw-r--r--tests-clar/resources/submod2/sm_missing_commits/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_missing_commits/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_missing_commits/file_to_modify3
-rw-r--r--tests-clar/resources/submod2/sm_unchanged/.gitted1
-rw-r--r--tests-clar/resources/submod2/sm_unchanged/README.txt3
-rw-r--r--tests-clar/resources/submod2/sm_unchanged/file_to_modify3
-rw-r--r--tests-clar/resources/submod2_target/.gitted/HEAD1
-rw-r--r--tests-clar/resources/submod2_target/.gitted/config6
-rw-r--r--tests-clar/resources/submod2_target/.gitted/description1
-rw-r--r--tests-clar/resources/submod2_target/.gitted/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/submod2_target/.gitted/logs/HEAD4
-rw-r--r--tests-clar/resources/submod2_target/.gitted/logs/refs/heads/master4
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/submod2_target/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/submod2_target/README.txt3
-rw-r--r--tests-clar/resources/submod2_target/file_to_modify3
-rw-r--r--tests-clar/resources/template/branches/.gitignore2
-rw-r--r--tests-clar/resources/template/description1
l---------tests-clar/resources/template/hooks/link.sample1
-rwxr-xr-xtests-clar/resources/template/hooks/update.sample9
-rw-r--r--tests-clar/resources/template/info/exclude6
-rw-r--r--tests-clar/resources/testrepo.git/FETCH_HEAD2
-rw-r--r--tests-clar/resources/testrepo.git/HEAD_TRACKER (renamed from tests-clar/resources/testrepo.git/head-tracker)0
-rw-r--r--tests-clar/resources/testrepo.git/config28
-rw-r--r--tests-clar/resources/testrepo.git/logs/HEAD7
-rw-r--r--tests-clar/resources/testrepo.git/logs/refs/heads/br22
-rw-r--r--tests-clar/resources/testrepo.git/logs/refs/heads/master2
-rw-r--r--tests-clar/resources/testrepo.git/logs/refs/heads/not-good1
-rw-r--r--tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/testrepo.git/logs/refs/remotes/test/master2
-rw-r--r--tests-clar/resources/testrepo.git/objects/08/b041783f40edfe12bb406c9c9a8a040177c125bin0 -> 54 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fdbin0 -> 122 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/1b/8cbad43e867676df601306689fe7c3def5e689bin0 -> 51 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10bin0 -> 168 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7bin0 -> 44 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679bin0 -> 83 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/4b/22b35d44b5a4f589edf3dc89196399771796eabin0 -> 44 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe2
-rw-r--r--tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d22
-rw-r--r--tests-clar/resources/testrepo.git/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659bin0 -> 149 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759bin0 -> 79 bytes
-rw-r--r--tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09bin0 -> 152 bytes
-rw-r--r--tests-clar/resources/testrepo.git/refs/heads/cannot-fetch1
-rw-r--r--tests-clar/resources/testrepo.git/refs/heads/chomped1
-rw-r--r--tests-clar/resources/testrepo.git/refs/heads/haacked1
-rw-r--r--tests-clar/resources/testrepo.git/refs/heads/not-good1
-rw-r--r--tests-clar/resources/testrepo.git/refs/heads/track-local1
-rw-r--r--tests-clar/resources/testrepo.git/refs/heads/trailing1
-rw-r--r--tests-clar/resources/testrepo.git/refs/notes/fanout1
-rw-r--r--tests-clar/resources/testrepo.git/refs/remotes/test/master1
-rw-r--r--tests-clar/resources/testrepo.git/refs/tags/hard_tag1
-rw-r--r--tests-clar/resources/testrepo.git/refs/tags/taggerless1
-rw-r--r--tests-clar/resources/testrepo.git/refs/tags/wrapped_tag1
-rw-r--r--tests-clar/resources/testrepo/.gitted/HEAD_TRACKER (renamed from tests-clar/resources/testrepo/.gitted/head-tracker)0
-rw-r--r--tests-clar/resources/testrepo/.gitted/config2
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff1
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0ebin0 -> 163 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925bin0 -> 147 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6bin0 -> 156 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63bin0 -> 50 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dccbin0 -> 50 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735bin0 -> 19 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80bin0 -> 161 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346ebin0 -> 22 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9bin0 -> 162 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83bin0 -> 147 bytes
-rw-r--r--tests-clar/resources/testrepo/.gitted/packed-refs1
-rw-r--r--tests-clar/resources/testrepo/.gitted/refs/heads/dir1
-rw-r--r--tests-clar/resources/testrepo/.gitted/refs/heads/master2
-rw-r--r--tests-clar/resources/testrepo/.gitted/refs/tags/foo/bar1
-rw-r--r--tests-clar/resources/testrepo/.gitted/refs/tags/foo/foo/bar1
-rw-r--r--tests-clar/resources/twowaymerge.git/HEAD1
-rw-r--r--tests-clar/resources/twowaymerge.git/config5
-rw-r--r--tests-clar/resources/twowaymerge.git/description1
-rw-r--r--tests-clar/resources/twowaymerge.git/info/exclude6
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/0c/8a3f1f3d5f421cf83048c7c73ee3b55a5e0f29bin0 -> 157 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/10/2dce8e3081f398e4bdd9fd894dc85ac3ca6a67bin0 -> 54 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/17/7d8634a28e26ec7819284752757ebe01a479d5bin0 -> 80 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/1c/30b88f5f3ee66d78df6520a7de9e89b890818b3
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/1f/4c0311a24b63f6fc209a59a1e404942d4a50062
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/22/24e191514cb4bd8c566d80dac22dfcb1e9bb833
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/29/6e56023cdc034d2735fee8c0d85a659d1b07f4bin0 -> 51 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/31/51880ae2b363f1c262cf98b750c1f169a0d432bin0 -> 68 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/3b/287f8730c81d0b763c2d294618a5e32b67b4f8bin0 -> 54 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/42/b7311aa626e712891940c1ec5d5cba201946a43
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/49/6d6428b9cf92981dc9495211e6e1120fb6f2babin0 -> 46 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/59/b0cf7d74659e1cdb13305319d6d4ce2733c118bin0 -> 65 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/6a/b5d28acbf3c3bdff276f7ccfdf29c1520e542f1
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/6c/fca542b55b8b37017e6125a4b8f59a6eae6f11bin0 -> 68 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/76/5b32c65d38f04c4f287abda055818ec0f26912bin0 -> 54 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/7b/8c336c45fc6895c1c60827260fe5d798e5d2473
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/82/bf9a1a10a4b25c1f14c9607b60970705e925451
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/8b/82fb1794cb1c8c7f172ec730a4c2db0ae3e6503
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/9a/40a2f11c191f180c47e54b11567cb3c1e89b30bin0 -> 62 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/9b/219343610c88a1187c996d0dc58330b55cee282
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/9f/e06a50f4d1634d6c6879854d01d80857388706bin0 -> 65 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/a4/1a49f8f5cd9b6cb14a076bf8394881ed0b4d193
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/a9/53a018c5b10b20c86e69fef55ebc8ad4c5a4171
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/a9/cce3cd1b3efbda5b1f4a6dcc3f1570b2d3d74c1
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/bd/1732c43c68d712ad09e1d872b9be6d4b9efdc4bin0 -> 158 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/c3/7a783c20d92ac92362a78a32860f7eebf938efbin0 -> 158 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/cb/dd40facab1682754eb67f7a43f29e672903cf6bin0 -> 51 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/cd/f97fd3bb48eb3827638bb33d208f5fd32d0aa6bin0 -> 158 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/d6/f10d549cb335b9e6d38afc1f0088be69b50494bin0 -> 62 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/d9/acdc7ae7632adfeec67fa73c1e343cf4d1f47e1
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391bin0 -> 15 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/ef/0488f0b722f0be8bcb90a7730ac7efafd1d6941
-rw-r--r--tests-clar/resources/twowaymerge.git/objects/fc/f7e3f51c11d199ab7a78403ee4f9ccd028da25bin0 -> 62 bytes
-rw-r--r--tests-clar/resources/twowaymerge.git/refs/heads/first-branch1
-rw-r--r--tests-clar/resources/twowaymerge.git/refs/heads/master1
-rw-r--r--tests-clar/resources/twowaymerge.git/refs/heads/second-branch1
-rw-r--r--tests-clar/resources/typechanges/.gitted/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/config12
-rw-r--r--tests-clar/resources/typechanges/.gitted/description1
-rw-r--r--tests-clar/resources/typechanges/.gitted/indexbin0 -> 184 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/config13
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/description1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/info/exclude6
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/packed-refs2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/config13
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/description1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/info/exclude6
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/packed-refs2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/config13
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/description1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/indexbin0 -> 192 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/info/exclude6
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1bin0 -> 55 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484bin0 -> 53 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0bin0 -> 163 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccadbin0 -> 167 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babfbin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6ebin0 -> 81 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5bin0 -> 93 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/packed-refs2
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master1
-rw-r--r--tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD1
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8bin0 -> 76 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403affbin0 -> 162 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586bin0 -> 486 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97bin0 -> 89 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475bin0 -> 161 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02bin0 -> 549 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95bin0 -> 24 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592bin0 -> 76 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5bin0 -> 18 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3ebin0 -> 24 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeebbin0 -> 602 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0bin0 -> 160 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0bin0 -> 66 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4bin0 -> 657 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729bin0 -> 226 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2bin0 -> 66 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb2
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963adbin0 -> 451 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37eabin0 -> 76 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3bin0 -> 226 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4abin0 -> 76 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6fbin0 -> 226 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7bin0 -> 701 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a5
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29bin0 -> 162 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447bin0 -> 160 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00dbin0 -> 226 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707bin0 -> 54 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0dbin0 -> 518 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095bin0 -> 577 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7cbin0 -> 78 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3badbin0 -> 19 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7bbin0 -> 225 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391bin0 -> 15 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46ebin0 -> 66 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779dbin0 -> 53 bytes
-rw-r--r--tests-clar/resources/typechanges/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/typechanges/README.md43
-rw-r--r--tests-clar/resources/typechanges/gitmodules0
-rw-r--r--tests-clar/resources/unsymlinked.git/HEAD1
-rw-r--r--tests-clar/resources/unsymlinked.git/config6
-rw-r--r--tests-clar/resources/unsymlinked.git/description1
-rw-r--r--tests-clar/resources/unsymlinked.git/info/exclude2
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbfbin0 -> 49 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30bbin0 -> 44 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41cbin0 -> 29 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773bin0 -> 47 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8cbin0 -> 78 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27bin0 -> 49 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49dbin0 -> 132 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3bin0 -> 170 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230bin0 -> 44 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b62
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7bin0 -> 49 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6abin0 -> 49 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9bin0 -> 44 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006bin0 -> 32 bytes
-rw-r--r--tests-clar/resources/unsymlinked.git/refs/heads/exe-file1
-rw-r--r--tests-clar/resources/unsymlinked.git/refs/heads/master1
-rw-r--r--tests-clar/resources/unsymlinked.git/refs/heads/reg-file1
-rw-r--r--tests-clar/revwalk/basic.c57
-rw-r--r--tests-clar/revwalk/mergebase.c260
-rw-r--r--tests-clar/revwalk/signatureparsing.c47
-rw-r--r--tests-clar/stash/drop.c168
-rw-r--r--tests-clar/stash/foreach.c124
-rw-r--r--tests-clar/stash/save.c373
-rw-r--r--tests-clar/stash/stash_helpers.c68
-rw-r--r--tests-clar/stash/stash_helpers.h8
-rw-r--r--tests-clar/status/ignore.c336
-rw-r--r--tests-clar/status/single.c16
-rw-r--r--tests-clar/status/status_data.h68
-rw-r--r--tests-clar/status/status_helpers.c48
-rw-r--r--tests-clar/status/status_helpers.h12
-rw-r--r--tests-clar/status/submodules.c156
-rw-r--r--tests-clar/status/worktree.c327
-rw-r--r--tests-clar/status/worktree_init.c339
-rw-r--r--tests-clar/submodule/lookup.c114
-rw-r--r--tests-clar/submodule/modify.c266
-rw-r--r--tests-clar/submodule/status.c385
-rw-r--r--tests-clar/submodule/submodule_helpers.c84
-rw-r--r--tests-clar/submodule/submodule_helpers.h2
-rw-r--r--tests-clar/threads/basic.c17
-rw-r--r--tests-clar/trace/trace.c88
-rw-r--r--tests-clar/valgrind-supp-mac.txt82
1074 files changed, 26007 insertions, 2900 deletions
diff --git a/tests-clar/README.md b/tests-clar/README.md
index 03a4d54d3..3aeaaf464 100644
--- a/tests-clar/README.md
+++ b/tests-clar/README.md
@@ -4,7 +4,7 @@ Writing Clar tests for libgit2
For information on the Clar testing framework and a detailed introduction
please visit:
-https://github.com/tanoku/clar
+https://github.com/vmg/clar
* Write your modules and tests. Use good, meaningful names.
diff --git a/tests-clar/attr/attr_expect.h b/tests-clar/attr/attr_expect.h
index df1e1044b..70f1ab4f5 100644
--- a/tests-clar/attr/attr_expect.h
+++ b/tests-clar/attr/attr_expect.h
@@ -18,19 +18,20 @@ struct attr_expected {
GIT_INLINE(void) attr_check_expected(
enum attr_expect_t expected,
const char *expected_str,
+ const char *name,
const char *value)
{
switch (expected) {
case EXPECT_TRUE:
- cl_assert(GIT_ATTR_TRUE(value));
+ cl_assert_(GIT_ATTR_TRUE(value), name);
break;
case EXPECT_FALSE:
- cl_assert(GIT_ATTR_FALSE(value));
+ cl_assert_(GIT_ATTR_FALSE(value), name);
break;
case EXPECT_UNDEFINED:
- cl_assert(GIT_ATTR_UNSPECIFIED(value));
+ cl_assert_(GIT_ATTR_UNSPECIFIED(value), name);
break;
case EXPECT_STRING:
diff --git a/tests-clar/attr/file.c b/tests-clar/attr/file.c
index d19708838..8866fd9bd 100644
--- a/tests-clar/attr/file.c
+++ b/tests-clar/attr/file.c
@@ -114,7 +114,7 @@ static void check_one_assign(
cl_assert_equal_s(name, assign->name);
cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
- attr_check_expected(expected, expected_str, assign->value);
+ attr_check_expected(expected, expected_str, assign->name, assign->value);
}
void test_attr_file__assign_variants(void)
diff --git a/tests-clar/attr/ignore.c b/tests-clar/attr/ignore.c
new file mode 100644
index 000000000..aa81e9249
--- /dev/null
+++ b/tests-clar/attr/ignore.c
@@ -0,0 +1,48 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "path.h"
+
+static git_repository *g_repo = NULL;
+
+void test_attr_ignore__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("attr");
+}
+
+void test_attr_ignore__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}
+
+void assert_is_ignored(bool expected, const char *filepath)
+{
+ int is_ignored;
+
+ cl_git_pass(git_ignore_path_is_ignored(&is_ignored, g_repo, filepath));
+ cl_assert_equal_i(expected, is_ignored == 1);
+}
+
+void test_attr_ignore__honor_temporary_rules(void)
+{
+ cl_git_rewritefile("attr/.gitignore", "/NewFolder\n/NewFolder/NewFolder");
+
+ assert_is_ignored(false, "File.txt");
+ assert_is_ignored(true, "NewFolder");
+ assert_is_ignored(true, "NewFolder/NewFolder");
+ assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
+}
+
+void test_attr_ignore__skip_gitignore_directory(void)
+{
+ cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
+ p_unlink("attr/.gitignore");
+ cl_assert(!git_path_exists("attr/.gitignore"));
+ p_mkdir("attr/.gitignore", 0777);
+ cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
+
+ assert_is_ignored(false, "File.txt");
+ assert_is_ignored(true, "NewFolder");
+ assert_is_ignored(true, "NewFolder/NewFolder");
+ assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
+}
diff --git a/tests-clar/attr/lookup.c b/tests-clar/attr/lookup.c
index b2a6aac64..200bdd2c7 100644
--- a/tests-clar/attr/lookup.c
+++ b/tests-clar/attr/lookup.c
@@ -44,7 +44,7 @@ static void run_test_cases(git_attr_file *file, struct attr_expected *cases, int
error = git_attr_file__lookup_one(file,&path,c->attr,&value);
cl_git_pass(error);
- attr_check_expected(c->expected, c->expected_str, value);
+ attr_check_expected(c->expected, c->expected_str, c->attr, value);
git_attr_path__free(&path);
}
@@ -252,7 +252,7 @@ void test_attr_lookup__from_buffer(void)
cl_git_pass(git_attr_file__new(&file, 0, NULL, NULL));
- cl_git_pass(git_attr_file__parse_buffer(NULL, "a* foo\nabc bar\n* baz", file));
+ cl_git_pass(git_attr_file__parse_buffer(NULL, NULL, "a* foo\nabc bar\n* baz", file));
cl_assert(file->rules.length == 3);
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index a88dfb3f9..ca3e71e7f 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -65,7 +65,7 @@ void test_attr_repo__get_one(void)
for (scan = test_cases; scan->path != NULL; scan++) {
const char *value;
cl_git_pass(git_attr_get(&value, g_repo, 0, scan->path, scan->attr));
- attr_check_expected(scan->expected, scan->expected_str, value);
+ attr_check_expected(scan->expected, scan->expected_str, scan->attr, value);
}
cl_assert(git_attr_cache__is_cached(g_repo, 0, ".git/info/attributes"));
@@ -113,6 +113,22 @@ static int count_attrs(
return 0;
}
+static int cancel_iteration(
+ const char *name,
+ const char *value,
+ void *payload)
+{
+ GIT_UNUSED(name);
+ GIT_UNUSED(value);
+
+ *((int *)payload) -= 1;
+
+ if (*((int *)payload) < 0)
+ return -1;
+
+ return 0;
+}
+
void test_attr_repo__foreach(void)
{
int count;
@@ -131,6 +147,12 @@ void test_attr_repo__foreach(void)
cl_git_pass(git_attr_foreach(g_repo, 0, "sub/subdir_test2.txt",
&count_attrs, &count));
cl_assert(count == 6); /* repoattr, rootattr, subattr, reposub, negattr, another */
+
+ count = 2;
+ cl_assert_equal_i(
+ GIT_EUSER, git_attr_foreach(
+ g_repo, 0, "sub/subdir_test1", &cancel_iteration, &count)
+ );
}
void test_attr_repo__manpage_example(void)
@@ -244,16 +266,15 @@ static void add_to_workdir(const char *filename, const char *content)
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha)
{
- int index_pos;
- git_index_entry *entry;
+ size_t index_pos;
+ const git_index_entry *entry;
add_to_workdir(filename, CONTENT);
- cl_git_pass(git_index_add(index, filename, 0));
+ cl_git_pass(git_index_add_bypath(index, filename));
- index_pos = git_index_find(index, filename);
- cl_assert(index_pos >= 0);
+ cl_assert(!git_index_find(&index_pos, index, filename));
- entry = git_index_get(index, index_pos);
+ entry = git_index_get_byindex(index, index_pos);
cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha));
}
diff --git a/tests-clar/buf/splice.c b/tests-clar/buf/splice.c
new file mode 100644
index 000000000..e80c93105
--- /dev/null
+++ b/tests-clar/buf/splice.c
@@ -0,0 +1,93 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+
+static git_buf _buf;
+
+void test_buf_splice__initialize(void) {
+ git_buf_init(&_buf, 16);
+}
+
+void test_buf_splice__cleanup(void) {
+ git_buf_free(&_buf);
+}
+
+void test_buf_splice__preprend(void)
+{
+ git_buf_sets(&_buf, "world!");
+
+ cl_git_pass(git_buf_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__append(void)
+{
+ git_buf_sets(&_buf, "Hello");
+
+ cl_git_pass(git_buf_splice(&_buf, git_buf_len(&_buf), 0, " world!", strlen(" world!")));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__insert_at(void)
+{
+ git_buf_sets(&_buf, "Hell world!");
+
+ cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__remove_at(void)
+{
+ git_buf_sets(&_buf, "Hello world of warcraft!");
+
+ cl_git_pass(git_buf_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__replace(void)
+{
+ git_buf_sets(&_buf, "Hell0 w0rld!");
+
+ cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__replace_with_longer(void)
+{
+ git_buf_sets(&_buf, "Hello you!");
+
+ cl_git_pass(git_buf_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__replace_with_shorter(void)
+{
+ git_buf_sets(&_buf, "Brave new world!");
+
+ cl_git_pass(git_buf_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__truncate(void)
+{
+ git_buf_sets(&_buf, "Hello world!!");
+
+ cl_git_pass(git_buf_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
+
+void test_buf_splice__dont_do_anything(void)
+{
+ git_buf_sets(&_buf, "Hello world!");
+
+ cl_git_pass(git_buf_splice(&_buf, 3, 0, "Hello", 0));
+
+ cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
+}
diff --git a/tests-clar/checkout/binaryunicode.c b/tests-clar/checkout/binaryunicode.c
new file mode 100644
index 000000000..14ab9fdfa
--- /dev/null
+++ b/tests-clar/checkout/binaryunicode.c
@@ -0,0 +1,58 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "repo/repo_helpers.h"
+#include "path.h"
+#include "fileops.h"
+
+static git_repository *g_repo;
+
+void test_checkout_binaryunicode__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("binaryunicode");
+}
+
+void test_checkout_binaryunicode__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static void execute_test(void)
+{
+ git_oid oid, check;
+ git_commit *commit;
+ git_tree *tree;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/branch1"));
+ cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
+ cl_git_pass(git_commit_tree(&tree, commit));
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_checkout_tree(g_repo, (git_object *)tree, &opts));
+
+ git_tree_free(tree);
+ git_commit_free(commit);
+
+ /* Verify that the lenna.jpg file was checked out correctly */
+ cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1"));
+ cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJ_BLOB));
+ cl_assert(git_oid_equal(&oid, &check));
+
+ /* Verify that the text file was checked out correctly */
+ cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a"));
+ cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJ_BLOB));
+ cl_assert(git_oid_equal(&oid, &check));
+}
+
+void test_checkout_binaryunicode__noautocrlf(void)
+{
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
+ execute_test();
+}
+
+void test_checkout_binaryunicode__autocrlf(void)
+{
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+ execute_test();
+}
diff --git a/tests-clar/checkout/checkout_helpers.c b/tests-clar/checkout/checkout_helpers.c
new file mode 100644
index 000000000..ab93a89bd
--- /dev/null
+++ b/tests-clar/checkout/checkout_helpers.c
@@ -0,0 +1,93 @@
+#include "clar_libgit2.h"
+#include "checkout_helpers.h"
+#include "refs.h"
+#include "fileops.h"
+
+/* this is essentially the code from git__unescape modified slightly */
+void strip_cr_from_buf(git_buf *buf)
+{
+ char *scan, *pos = buf->ptr, *end = pos + buf->size;
+
+ for (scan = pos; scan < end; pos++, scan++) {
+ if (*scan == '\r')
+ scan++; /* skip '\r' */
+ if (pos != scan)
+ *pos = *scan;
+ }
+
+ *pos = '\0';
+ buf->size = (pos - buf->ptr);
+}
+
+void assert_on_branch(git_repository *repo, const char *branch)
+{
+ git_reference *head;
+ git_buf bname = GIT_BUF_INIT;
+
+ cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
+ cl_assert_(git_reference_type(head) == GIT_REF_SYMBOLIC, branch);
+
+ cl_git_pass(git_buf_joinpath(&bname, "refs/heads", branch));
+ cl_assert_equal_s(bname.ptr, git_reference_symbolic_target(head));
+
+ git_reference_free(head);
+ git_buf_free(&bname);
+}
+
+void reset_index_to_treeish(git_object *treeish)
+{
+ git_object *tree;
+ git_index *index;
+ git_repository *repo = git_object_owner(treeish);
+
+ cl_git_pass(git_object_peel(&tree, treeish, GIT_OBJ_TREE));
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_read_tree(index, (git_tree *)tree));
+ cl_git_pass(git_index_write(index));
+
+ git_object_free(tree);
+ git_index_free(index);
+}
+
+static void check_file_contents_internal(
+ const char *path,
+ const char *expected_content,
+ bool strip_cr,
+ const char *file,
+ int line,
+ const char *msg)
+{
+ int fd;
+ char data[1024] = {0};
+ git_buf buf = GIT_BUF_INIT;
+ size_t expected_len = expected_content ? strlen(expected_content) : 0;
+
+ fd = p_open(path, O_RDONLY);
+ cl_assert(fd >= 0);
+
+ buf.ptr = data;
+ buf.size = p_read(fd, buf.ptr, sizeof(data));
+
+ cl_git_pass(p_close(fd));
+
+ if (strip_cr)
+ strip_cr_from_buf(&buf);
+
+ clar__assert_equal_i((int)expected_len, (int)buf.size, file, line, "strlen(expected_content) != strlen(actual_content)", 1);
+ clar__assert_equal_s(expected_content, buf.ptr, file, line, msg, 1);
+}
+
+void check_file_contents_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg)
+{
+ check_file_contents_internal(path, expected, false, file, line, msg);
+}
+
+void check_file_contents_nocr_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg)
+{
+ check_file_contents_internal(path, expected, true, file, line, msg);
+}
diff --git a/tests-clar/checkout/checkout_helpers.h b/tests-clar/checkout/checkout_helpers.h
new file mode 100644
index 000000000..34053809d
--- /dev/null
+++ b/tests-clar/checkout/checkout_helpers.h
@@ -0,0 +1,21 @@
+#include "buffer.h"
+#include "git2/object.h"
+#include "git2/repository.h"
+
+extern void strip_cr_from_buf(git_buf *buf);
+extern void assert_on_branch(git_repository *repo, const char *branch);
+extern void reset_index_to_treeish(git_object *treeish);
+
+extern void check_file_contents_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg);
+
+extern void check_file_contents_nocr_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg);
+
+#define check_file_contents(PATH,EXP) \
+ check_file_contents_at_line(PATH,EXP,__FILE__,__LINE__,"String mismatch: " #EXP " != " #PATH)
+
+#define check_file_contents_nocr(PATH,EXP) \
+ check_file_contents_nocr_at_line(PATH,EXP,__FILE__,__LINE__,"String mismatch: " #EXP " != " #PATH)
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
new file mode 100644
index 000000000..285b1f272
--- /dev/null
+++ b/tests-clar/checkout/crlf.c
@@ -0,0 +1,147 @@
+#include "clar_libgit2.h"
+#include "checkout_helpers.h"
+
+#include "git2/checkout.h"
+#include "repository.h"
+
+#define UTF8_BOM "\xEF\xBB\xBF"
+#define ALL_CRLF_TEXT_RAW "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n"
+#define ALL_LF_TEXT_RAW "lf\nlf\nlf\nlf\nlf\n"
+#define MORE_CRLF_TEXT_RAW "crlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf\r\n"
+#define MORE_LF_TEXT_RAW "lf\nlf\ncrlf\r\nlf\nlf\n"
+
+#define ALL_LF_TEXT_AS_CRLF "lf\r\nlf\r\nlf\r\nlf\r\nlf\r\n"
+#define MORE_CRLF_TEXT_AS_CRLF "crlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf\r\n"
+#define MORE_LF_TEXT_AS_CRLF "lf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\n"
+
+static git_repository *g_repo;
+
+void test_checkout_crlf__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("crlf");
+}
+
+void test_checkout_crlf__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_checkout_crlf__detect_crlf_autocrlf_false(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
+
+ git_checkout_head(g_repo, &opts);
+
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
+
+void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
+{
+ git_index *index;
+ const git_index_entry *entry;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
+
+ git_checkout_head(g_repo, &opts);
+
+ git_repository_index(&index, g_repo);
+
+ cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
+ cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
+
+ cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
+ cl_assert(entry->file_size == strlen(ALL_CRLF_TEXT_RAW));
+
+ git_index_free(index);
+}
+
+void test_checkout_crlf__detect_crlf_autocrlf_true(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ else
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
+
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
+
+void test_checkout_crlf__more_lf_autocrlf_true(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW);
+ else
+ check_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF);
+}
+
+void test_checkout_crlf__more_crlf_autocrlf_true(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW);
+ else
+ check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
+}
+
+void test_checkout_crlf__all_crlf_autocrlf_true(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
+
+void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
+{
+ git_index *index;
+ const git_index_entry *entry;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ git_repository_index(&index, g_repo);
+
+ cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ cl_assert_equal_sz(strlen(ALL_LF_TEXT_RAW), entry->file_size);
+ else
+ cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
+
+ cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
+ cl_assert_equal_sz(strlen(ALL_CRLF_TEXT_RAW), entry->file_size);
+
+ git_index_free(index);
+}
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c
new file mode 100644
index 000000000..46646f8bf
--- /dev/null
+++ b/tests-clar/checkout/head.c
@@ -0,0 +1,63 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "repo/repo_helpers.h"
+#include "path.h"
+#include "fileops.h"
+
+static git_repository *g_repo;
+
+void test_checkout_head__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_checkout_head__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_checkout_head__orphaned_head_returns_GIT_EORPHANEDHEAD(void)
+{
+ make_head_orphaned(g_repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD, git_checkout_head(g_repo, NULL));
+}
+
+void test_checkout_head__with_index_only_tree(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_index *index;
+
+ /* let's start by getting things into a known state */
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ /* now let's stage some new stuff including a new directory */
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ p_mkdir("testrepo/newdir", 0777);
+ cl_git_mkfile("testrepo/newdir/newfile.txt", "new file\n");
+
+ cl_git_pass(git_index_add_bypath(index, "newdir/newfile.txt"));
+ cl_git_pass(git_index_write(index));
+
+ cl_assert(git_path_isfile("testrepo/newdir/newfile.txt"));
+ cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) != NULL);
+
+ git_index_free(index);
+
+ /* okay, so now we have staged this new file; let's see if we can remove */
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_read(index)); /* reload if needed */
+
+ cl_assert(!git_path_isfile("testrepo/newdir/newfile.txt"));
+ cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) == NULL);
+
+ git_index_free(index);
+}
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
new file mode 100644
index 000000000..78ff5ac62
--- /dev/null
+++ b/tests-clar/checkout/index.c
@@ -0,0 +1,507 @@
+#include "clar_libgit2.h"
+#include "checkout_helpers.h"
+
+#include "git2/checkout.h"
+#include "repository.h"
+
+static git_repository *g_repo;
+
+void test_checkout_index__initialize(void)
+{
+ git_tree *tree;
+
+ g_repo = cl_git_sandbox_init("testrepo");
+
+ cl_git_pass(git_repository_head_tree(&tree, g_repo));
+
+ reset_index_to_treeish((git_object *)tree);
+ git_tree_free(tree);
+
+ cl_git_rewritefile(
+ "./testrepo/.gitattributes",
+ "* text eol=lf\n");
+}
+
+void test_checkout_index__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_checkout_index__cannot_checkout_a_bare_repository(void)
+{
+ test_checkout_index__cleanup();
+
+ g_repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_fail(git_checkout_index(g_repo, NULL, NULL));
+}
+
+void test_checkout_index__can_create_missing_files(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/README", "hey there\n");
+ check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
+}
+
+void test_checkout_index__can_remove_untracked_files(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ git_futils_mkdir("./testrepo/dir/subdir/subsubdir", NULL, 0755, GIT_MKDIR_PATH);
+ cl_git_mkfile("./testrepo/dir/one", "one\n");
+ cl_git_mkfile("./testrepo/dir/subdir/two", "two\n");
+
+ cl_assert_equal_i(true, git_path_isdir("./testrepo/dir/subdir/subsubdir"));
+
+ opts.checkout_strategy =
+ GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ cl_assert_equal_i(false, git_path_isdir("./testrepo/dir"));
+}
+
+void test_checkout_index__honor_the_specified_pathspecs(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ char *entries[] = { "*.txt" };
+
+ opts.paths.strings = entries;
+ opts.paths.count = 1;
+
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
+ check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
+}
+
+void test_checkout_index__honor_the_gitattributes_directives(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ const char *attributes =
+ "branch_file.txt text eol=crlf\n"
+ "new.txt text eol=lf\n";
+
+ cl_git_mkfile("./testrepo/.gitattributes", attributes);
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/README", "hey there\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
+ check_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n");
+}
+
+void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
+{
+#ifdef GIT_WIN32
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ const char *expected_readme_text = "hey there\r\n";
+
+ cl_git_pass(p_unlink("./testrepo/.gitattributes"));
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/README", expected_readme_text);
+#endif
+}
+
+void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_repo_set_bool(g_repo, "core.symlinks", true);
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+#ifdef GIT_WIN32
+ check_file_contents("./testrepo/link_to_new.txt", "new.txt");
+#else
+ {
+ char link_data[1024];
+ size_t link_size = 1024;
+
+ link_size = p_readlink("./testrepo/link_to_new.txt", link_data, link_size);
+ link_data[link_size] = '\0';
+ cl_assert_equal_i(link_size, strlen("new.txt"));
+ cl_assert_equal_s(link_data, "new.txt");
+ check_file_contents("./testrepo/link_to_new.txt", "my new file\n");
+ }
+#endif
+}
+
+void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_repo_set_bool(g_repo, "core.symlinks", false);
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/link_to_new.txt", "new.txt");
+}
+
+void test_checkout_index__donot_overwrite_modified_file_by_default(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
+
+ /* set this up to not return an error code on conflicts, but it
+ * still will not have permission to overwrite anything...
+ */
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/new.txt", "This isn't what's stored!");
+}
+
+void test_checkout_index__can_overwrite_modified_file(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/new.txt", "my new file\n");
+}
+
+void test_checkout_index__options_disable_filters(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_git_mkfile("./testrepo/.gitattributes", "*.txt text eol=crlf\n");
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.disable_filters = false;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/new.txt", "my new file\r\n");
+
+ p_unlink("./testrepo/new.txt");
+
+ opts.disable_filters = true;
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/new.txt", "my new file\n");
+}
+
+void test_checkout_index__options_dir_modes(void)
+{
+#ifndef GIT_WIN32
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ struct stat st;
+ git_oid oid;
+ git_commit *commit;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
+ cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
+
+ reset_index_to_treeish((git_object *)commit);
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.dir_mode = 0701;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ cl_git_pass(p_stat("./testrepo/a", &st));
+ cl_assert_equal_i(st.st_mode & 0777, 0701);
+
+ /* File-mode test, since we're on the 'dir' branch */
+ cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
+ cl_assert_equal_i(st.st_mode & 0777, 0755);
+
+ git_commit_free(commit);
+#endif
+}
+
+void test_checkout_index__options_override_file_modes(void)
+{
+#ifndef GIT_WIN32
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ struct stat st;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.file_mode = 0700;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ cl_git_pass(p_stat("./testrepo/new.txt", &st));
+ cl_assert_equal_i(st.st_mode & 0777, 0700);
+#endif
+}
+
+void test_checkout_index__options_open_flags(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_git_mkfile("./testrepo/new.txt", "hi\n");
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND;
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./testrepo/new.txt", "hi\nmy new file\n");
+}
+
+struct notify_data {
+ const char *file;
+ const char *sha;
+};
+
+static int test_checkout_notify_cb(
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *baseline,
+ const git_diff_file *target,
+ const git_diff_file *workdir,
+ void *payload)
+{
+ struct notify_data *expectations = (struct notify_data *)payload;
+
+ GIT_UNUSED(workdir);
+
+ cl_assert_equal_i(GIT_CHECKOUT_NOTIFY_CONFLICT, why);
+ cl_assert_equal_s(expectations->file, path);
+ cl_assert_equal_i(0, git_oid_streq(&baseline->oid, expectations->sha));
+ cl_assert_equal_i(0, git_oid_streq(&target->oid, expectations->sha));
+
+ return 0;
+}
+
+void test_checkout_index__can_notify_of_skipped_files(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ struct notify_data data;
+
+ cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
+
+ /*
+ * $ git ls-tree HEAD
+ * 100644 blob a8233120f6ad708f843d861ce2b7228ec4e3dec6 README
+ * 100644 blob 3697d64be941a53d4ae8f6a271e4e3fa56b022cc branch_file.txt
+ * 100644 blob a71586c1dfe8a71c6cbf6c129f404c5642ff31bd new.txt
+ */
+ data.file = "new.txt";
+ data.sha = "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd";
+
+ opts.checkout_strategy =
+ GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
+ opts.notify_cb = test_checkout_notify_cb;
+ opts.notify_payload = &data;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+}
+
+static int dont_notify_cb(
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *baseline,
+ const git_diff_file *target,
+ const git_diff_file *workdir,
+ void *payload)
+{
+ GIT_UNUSED(why);
+ GIT_UNUSED(path);
+ GIT_UNUSED(baseline);
+ GIT_UNUSED(target);
+ GIT_UNUSED(workdir);
+ GIT_UNUSED(payload);
+
+ cl_assert(false);
+
+ return 0;
+}
+
+void test_checkout_index__wont_notify_of_expected_line_ending_changes(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_git_pass(p_unlink("./testrepo/.gitattributes"));
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ cl_git_mkfile("./testrepo/new.txt", "my new file\r\n");
+
+ opts.checkout_strategy =
+ GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
+ opts.notify_cb = dont_notify_cb;
+ opts.notify_payload = NULL;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+}
+
+static void checkout_progress_counter(
+ const char *path, size_t cur, size_t tot, void *payload)
+{
+ GIT_UNUSED(path); GIT_UNUSED(cur); GIT_UNUSED(tot);
+ (*(int *)payload)++;
+}
+
+void test_checkout_index__calls_progress_callback(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ int calls = 0;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.progress_cb = checkout_progress_counter;
+ opts.progress_payload = &calls;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+ cl_assert(calls > 0);
+}
+
+void test_checkout_index__can_overcome_name_clashes(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_index *index;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ git_index_clear(index);
+
+ cl_git_mkfile("./testrepo/path0", "content\r\n");
+ cl_git_pass(p_mkdir("./testrepo/path1", 0777));
+ cl_git_mkfile("./testrepo/path1/file1", "content\r\n");
+
+ cl_git_pass(git_index_add_bypath(index, "path0"));
+ cl_git_pass(git_index_add_bypath(index, "path1/file1"));
+
+ cl_git_pass(p_unlink("./testrepo/path0"));
+ cl_git_pass(git_futils_rmdir_r(
+ "./testrepo/path1", NULL, GIT_RMDIR_REMOVE_FILES));
+
+ cl_git_mkfile("./testrepo/path1", "content\r\n");
+ cl_git_pass(p_mkdir("./testrepo/path0", 0777));
+ cl_git_mkfile("./testrepo/path0/file0", "content\r\n");
+
+ cl_assert(git_path_isfile("./testrepo/path1"));
+ cl_assert(git_path_isfile("./testrepo/path0/file0"));
+
+ opts.checkout_strategy =
+ GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ cl_git_pass(git_checkout_index(g_repo, index, &opts));
+
+ cl_assert(git_path_isfile("./testrepo/path1"));
+ cl_assert(git_path_isfile("./testrepo/path0/file0"));
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_index(g_repo, index, &opts));
+
+ cl_assert(git_path_isfile("./testrepo/path0"));
+ cl_assert(git_path_isfile("./testrepo/path1/file1"));
+
+ git_index_free(index);
+}
+
+void test_checkout_index__validates_struct_version(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ const git_error *err;
+
+ opts.version = 1024;
+ cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
+
+ err = giterr_last();
+ cl_assert_equal_i(err->klass, GITERR_INVALID);
+
+ opts.version = 0;
+ giterr_clear();
+ cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
+
+ err = giterr_last();
+ cl_assert_equal_i(err->klass, GITERR_INVALID);
+}
+
+void test_checkout_index__can_update_prefixed_files(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
+ cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+
+ cl_git_mkfile("./testrepo/READ", "content\n");
+ cl_git_mkfile("./testrepo/README.after", "content\n");
+ cl_git_pass(p_mkdir("./testrepo/branch_file", 0777));
+ cl_git_pass(p_mkdir("./testrepo/branch_file/contained_dir", 0777));
+ cl_git_mkfile("./testrepo/branch_file/contained_file", "content\n");
+ cl_git_pass(p_mkdir("./testrepo/branch_file.txt.after", 0777));
+
+ opts.checkout_strategy =
+ GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ /* remove untracked will remove the .gitattributes file before the blobs
+ * were created, so they will have had crlf filtering applied on Windows
+ */
+ check_file_contents_nocr("./testrepo/README", "hey there\n");
+ check_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents_nocr("./testrepo/new.txt", "my new file\n");
+
+ cl_assert(!git_path_exists("testrepo/READ"));
+ cl_assert(!git_path_exists("testrepo/README.after"));
+ cl_assert(!git_path_exists("testrepo/branch_file"));
+ cl_assert(!git_path_exists("testrepo/branch_file.txt.after"));
+}
+
+void test_checkout_index__can_checkout_a_newly_initialized_repository(void)
+{
+ test_checkout_index__cleanup();
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt");
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, NULL));
+}
+
+void test_checkout_index__issue_1397(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ test_checkout_index__cleanup();
+
+ g_repo = cl_git_sandbox_init("issue_1397");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
+
+ check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
+}
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
new file mode 100644
index 000000000..0748b22e0
--- /dev/null
+++ b/tests-clar/checkout/tree.c
@@ -0,0 +1,503 @@
+#include "clar_libgit2.h"
+#include "checkout_helpers.h"
+
+#include "git2/checkout.h"
+#include "repository.h"
+#include "buffer.h"
+#include "fileops.h"
+
+static git_repository *g_repo;
+static git_checkout_opts g_opts;
+static git_object *g_object;
+
+void test_checkout_tree__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+
+ GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
+ g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+}
+
+void test_checkout_tree__cleanup(void)
+{
+ git_object_free(g_object);
+ g_object = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_checkout_tree__cannot_checkout_a_non_treeish(void)
+{
+ /* blob */
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"));
+ cl_git_fail(git_checkout_tree(g_repo, g_object, NULL));
+}
+
+void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
+{
+ char *entries[] = { "ab/de/" };
+
+ g_opts.paths.strings = entries;
+ g_opts.paths.count = 1;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
+
+ cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
+ cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
+}
+
+void test_checkout_tree__can_checkout_and_remove_directory(void)
+{
+ cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+
+ /* Checkout brach "subtrees" and update HEAD, so that HEAD matches the
+ * current working tree
+ */
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
+
+ cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/"));
+ cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
+ cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
+
+ git_object_free(g_object);
+ g_object = NULL;
+
+ /* Checkout brach "master" and update HEAD, so that HEAD matches the
+ * current working tree
+ */
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
+
+ /* This directory should no longer exist */
+ cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+}
+
+void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void)
+{
+ char *entries[] = { "de/" };
+
+ g_opts.paths.strings = entries;
+ g_opts.paths.count = 1;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab"));
+
+ cl_assert_equal_i(false, git_path_isdir("./testrepo/de/"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert_equal_i(true, git_path_isfile("./testrepo/de/2.txt"));
+ cl_assert_equal_i(true, git_path_isfile("./testrepo/de/fgh/1.txt"));
+}
+
+static void progress(const char *path, size_t cur, size_t tot, void *payload)
+{
+ bool *was_called = (bool*)payload;
+ GIT_UNUSED(path); GIT_UNUSED(cur); GIT_UNUSED(tot);
+ *was_called = true;
+}
+
+void test_checkout_tree__calls_progress_callback(void)
+{
+ bool was_called = 0;
+
+ g_opts.progress_cb = progress;
+ g_opts.progress_payload = &was_called;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert_equal_i(was_called, true);
+}
+
+void test_checkout_tree__doesnt_write_unrequested_files_to_worktree(void)
+{
+ git_oid master_oid;
+ git_oid chomped_oid;
+ git_commit* p_master_commit;
+ git_commit* p_chomped_commit;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ git_oid_fromstr(&master_oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ git_oid_fromstr(&chomped_oid, "e90810b8df3e80c413d903f631643c716887138d");
+ cl_git_pass(git_commit_lookup(&p_master_commit, g_repo, &master_oid));
+ cl_git_pass(git_commit_lookup(&p_chomped_commit, g_repo, &chomped_oid));
+
+ /* GIT_CHECKOUT_NONE should not add any file to the working tree from the
+ * index as it is supposed to be a dry run.
+ */
+ opts.checkout_strategy = GIT_CHECKOUT_NONE;
+ git_checkout_tree(g_repo, (git_object*)p_chomped_commit, &opts);
+ cl_assert_equal_i(false, git_path_isfile("testrepo/readme.txt"));
+
+ git_commit_free(p_master_commit);
+ git_commit_free(p_chomped_commit);
+}
+
+void test_checkout_tree__can_switch_branches(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_oid oid;
+ git_object *obj = NULL;
+
+ assert_on_branch(g_repo, "master");
+
+ /* do first checkout with FORCE because we don't know if testrepo
+ * base data is clean for a checkout or not
+ */
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
+
+ cl_assert(git_path_isfile("testrepo/README"));
+ cl_assert(git_path_isfile("testrepo/branch_file.txt"));
+ cl_assert(git_path_isfile("testrepo/new.txt"));
+ cl_assert(git_path_isfile("testrepo/a/b.txt"));
+
+ cl_assert(!git_path_isdir("testrepo/ab"));
+
+ assert_on_branch(g_repo, "dir");
+
+ git_object_free(obj);
+
+ /* do second checkout safe because we should be clean after first */
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees"));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
+
+ cl_assert(git_path_isfile("testrepo/README"));
+ cl_assert(git_path_isfile("testrepo/branch_file.txt"));
+ cl_assert(git_path_isfile("testrepo/new.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/4.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/c/3.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/de/2.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt"));
+
+ cl_assert(!git_path_isdir("testrepo/a"));
+
+ assert_on_branch(g_repo, "subtrees");
+
+ git_object_free(obj);
+}
+
+void test_checkout_tree__can_remove_untracked(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_mkfile("testrepo/untracked_file", "as you wish");
+ cl_assert(git_path_isfile("testrepo/untracked_file"));
+
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ cl_assert(!git_path_isfile("testrepo/untracked_file"));
+}
+
+void test_checkout_tree__can_remove_ignored(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ int ignored = 0;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_REMOVE_IGNORED;
+
+ cl_git_mkfile("testrepo/ignored_file", "as you wish");
+
+ cl_git_pass(git_ignore_add_rule(g_repo, "ignored_file\n"));
+
+ cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "ignored_file"));
+ cl_assert_equal_i(1, ignored);
+
+ cl_assert(git_path_isfile("testrepo/ignored_file"));
+
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ cl_assert(!git_path_isfile("testrepo/ignored_file"));
+}
+
+void test_checkout_tree__can_update_only(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_oid oid;
+ git_object *obj = NULL;
+
+ /* first let's get things into a known state - by checkout out the HEAD */
+
+ assert_on_branch(g_repo, "master");
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ cl_assert(!git_path_isdir("testrepo/a"));
+
+ check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
+
+ /* now checkout branch but with update only */
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
+
+ assert_on_branch(g_repo, "dir");
+
+ /* this normally would have been created (which was tested separately in
+ * the test_checkout_tree__can_switch_branches test), but with
+ * UPDATE_ONLY it will not have been created.
+ */
+ cl_assert(!git_path_isdir("testrepo/a"));
+
+ /* but this file still should have been updated */
+ check_file_contents_nocr("testrepo/branch_file.txt", "hi\n");
+
+ git_object_free(obj);
+}
+
+void test_checkout_tree__can_checkout_with_pattern(void)
+{
+ char *entries[] = { "[l-z]*.txt" };
+
+ /* reset to beginning of history (i.e. just a README file) */
+
+ g_opts.checkout_strategy =
+ GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+ cl_git_pass(
+ git_repository_set_head_detached(g_repo, git_object_id(g_object)));
+
+ git_object_free(g_object);
+ g_object = NULL;
+
+ cl_assert(git_path_exists("testrepo/README"));
+ cl_assert(!git_path_exists("testrepo/branch_file.txt"));
+ cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
+ cl_assert(!git_path_exists("testrepo/new.txt"));
+
+ /* now to a narrow patterned checkout */
+
+ g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_opts.paths.strings = entries;
+ g_opts.paths.count = 1;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert(git_path_exists("testrepo/README"));
+ cl_assert(!git_path_exists("testrepo/branch_file.txt"));
+ cl_assert(git_path_exists("testrepo/link_to_new.txt"));
+ cl_assert(git_path_exists("testrepo/new.txt"));
+}
+
+void test_checkout_tree__can_disable_pattern_match(void)
+{
+ char *entries[] = { "b*.txt" };
+
+ /* reset to beginning of history (i.e. just a README file) */
+
+ g_opts.checkout_strategy =
+ GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+ cl_git_pass(
+ git_repository_set_head_detached(g_repo, git_object_id(g_object)));
+
+ git_object_free(g_object);
+ g_object = NULL;
+
+ cl_assert(!git_path_isfile("testrepo/branch_file.txt"));
+
+ /* now to a narrow patterned checkout, but disable pattern */
+
+ g_opts.checkout_strategy =
+ GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
+ g_opts.paths.strings = entries;
+ g_opts.paths.count = 1;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert(!git_path_isfile("testrepo/branch_file.txt"));
+
+ /* let's try that again, but allow the pattern match */
+
+ g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert(git_path_isfile("testrepo/branch_file.txt"));
+}
+
+void assert_conflict(
+ const char *entry_path,
+ const char *new_content,
+ const char *parent_sha,
+ const char *commit_sha)
+{
+ git_index *index;
+ git_object *hack_tree;
+ git_reference *branch, *head;
+ git_buf file_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ /* Create a branch pointing at the parent */
+ cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
+ cl_git_pass(git_branch_create(&branch, g_repo,
+ "potential_conflict", (git_commit *)g_object, 0));
+
+ /* Make HEAD point to this branch */
+ cl_git_pass(git_reference_symbolic_create(
+ &head, g_repo, "HEAD", git_reference_name(branch), 1));
+ git_reference_free(head);
+ git_reference_free(branch);
+
+ /* Checkout the parent */
+ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ /* Hack-ishy workaound to ensure *all* the index entries
+ * match the content of the tree
+ */
+ cl_git_pass(git_object_peel(&hack_tree, g_object, GIT_OBJ_TREE));
+ cl_git_pass(git_index_read_tree(index, (git_tree *)hack_tree));
+ git_object_free(hack_tree);
+ git_object_free(g_object);
+ g_object = NULL;
+
+ /* Create a conflicting file */
+ cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path));
+ cl_git_mkfile(git_buf_cstr(&file_path), new_content);
+ git_buf_free(&file_path);
+
+ /* Trying to checkout the original commit */
+ cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha));
+
+ g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+ cl_assert_equal_i(
+ GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
+
+ /* Stage the conflicting change */
+ cl_git_pass(git_index_add_bypath(index, entry_path));
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
+
+ cl_assert_equal_i(
+ GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
+}
+
+void test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT(void)
+{
+ /*
+ * 099faba adds a symlink named 'link_to_new.txt'
+ * a65fedf is the parent of 099faba
+ */
+
+ assert_conflict("link_to_new.txt", "old.txt", "a65fedf", "099faba");
+}
+
+void test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT_2(void)
+{
+ /*
+ * cf80f8d adds a directory named 'a/'
+ * a4a7dce is the parent of cf80f8d
+ */
+
+ assert_conflict("a", "hello\n", "a4a7dce", "cf80f8d");
+}
+
+void test_checkout_tree__checking_out_a_conflicting_content_change_returns_EMERGECONFLICT(void)
+{
+ /*
+ * c47800c adds a symlink named 'branch_file.txt'
+ * 5b5b025 is the parent of 763d71a
+ */
+
+ assert_conflict("branch_file.txt", "hello\n", "5b5b025", "c47800c");
+}
+
+void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
+{
+ git_index *index = NULL;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_oid tree_id, commit_id;
+ git_tree *tree = NULL;
+ git_commit *commit = NULL;
+
+ git_repository_index(&index, g_repo);
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ cl_git_pass(git_reference_name_to_id(&commit_id, g_repo, "refs/heads/master"));
+ cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
+
+ cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
+
+ cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777));
+ cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n");
+
+ cl_git_pass(git_index_add_bypath(index, "this-is-dir/contained_file"));
+ git_index_write_tree(&tree_id, index);
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
+
+ cl_git_pass(p_unlink("./testrepo/this-is-dir/contained_file"));
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ opts.checkout_strategy = 1;
+ git_checkout_tree(g_repo, (git_object *)tree, &opts);
+
+ git_tree_free(tree);
+ git_commit_free(commit);
+ git_index_free(index);
+}
+
+void test_checkout_tree__issue_1397(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ const char *partial_oid = "8a7ef04";
+ git_object *tree = NULL;
+
+ test_checkout_tree__cleanup(); /* cleanup default checkout */
+
+ g_repo = cl_git_sandbox_init("issue_1397");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ cl_git_pass(git_revparse_single(&tree, g_repo, partial_oid));
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ cl_git_pass(git_checkout_tree(g_repo, tree, &opts));
+
+ check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
+
+ git_object_free(tree);
+}
diff --git a/tests-clar/checkout/typechange.c b/tests-clar/checkout/typechange.c
new file mode 100644
index 000000000..b92cc23fa
--- /dev/null
+++ b/tests-clar/checkout/typechange.c
@@ -0,0 +1,240 @@
+#include "clar_libgit2.h"
+#include "git2/checkout.h"
+#include "path.h"
+#include "posix.h"
+#include "fileops.h"
+
+static git_repository *g_repo = NULL;
+
+static const char *g_typechange_oids[] = {
+ "79b9f23e85f55ea36a472a902e875bc1121a94cb",
+ "9bdb75b73836a99e3dbeea640a81de81031fdc29",
+ "0e7ed140b514b8cae23254cb8656fe1674403aff",
+ "9d0235c7a7edc0889a18f97a42ee6db9fe688447",
+ "9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a",
+ "1b63caae4a5ca96f78e8dfefc376c6a39a142475",
+ "6eae26c90e8ccc4d16208972119c40635489c6f0",
+ NULL
+};
+
+static bool g_typechange_empty[] = {
+ true, false, false, false, false, false, true, true
+};
+
+void test_checkout_typechange__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("typechanges");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+}
+
+void test_checkout_typechange__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ cl_fixture_cleanup("submod2_target");
+}
+
+static void assert_file_exists(const char *path)
+{
+ cl_assert_(git_path_isfile(path), path);
+}
+
+static void assert_dir_exists(const char *path)
+{
+ cl_assert_(git_path_isdir(path), path);
+}
+
+static void assert_workdir_matches_tree(
+ git_repository *repo, const git_oid *id, const char *root, bool recurse)
+{
+ git_object *obj;
+ git_tree *tree;
+ size_t i, max_i;
+ git_buf path = GIT_BUF_INIT;
+
+ if (!root)
+ root = git_repository_workdir(repo);
+ cl_assert(root);
+
+ cl_git_pass(git_object_lookup(&obj, repo, id, GIT_OBJ_ANY));
+ cl_git_pass(git_object_peel((git_object **)&tree, obj, GIT_OBJ_TREE));
+ git_object_free(obj);
+
+ max_i = git_tree_entrycount(tree);
+
+ for (i = 0; i < max_i; ++i) {
+ const git_tree_entry *te = git_tree_entry_byindex(tree, i);
+ cl_assert(te);
+
+ cl_git_pass(git_buf_joinpath(&path, root, git_tree_entry_name(te)));
+
+ switch (git_tree_entry_type(te)) {
+ case GIT_OBJ_COMMIT:
+ assert_dir_exists(path.ptr);
+ break;
+ case GIT_OBJ_TREE:
+ assert_dir_exists(path.ptr);
+ if (recurse)
+ assert_workdir_matches_tree(
+ repo, git_tree_entry_id(te), path.ptr, true);
+ break;
+ case GIT_OBJ_BLOB:
+ switch (git_tree_entry_filemode(te)) {
+ case GIT_FILEMODE_BLOB:
+ case GIT_FILEMODE_BLOB_EXECUTABLE:
+ assert_file_exists(path.ptr);
+ /* because of cross-platform, don't confirm exec bit yet */
+ break;
+ case GIT_FILEMODE_LINK:
+ cl_assert_(git_path_exists(path.ptr), path.ptr);
+ /* because of cross-platform, don't confirm link yet */
+ break;
+ default:
+ cl_assert(false); /* really?! */
+ }
+ break;
+ default:
+ cl_assert(false); /* really?!! */
+ }
+ }
+
+ git_tree_free(tree);
+ git_buf_free(&path);
+}
+
+void test_checkout_typechange__checkout_typechanges_safe(void)
+{
+ int i;
+ git_object *obj;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ for (i = 0; g_typechange_oids[i] != NULL; ++i) {
+ cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ /* There are bugs in some submodule->tree changes that prevent
+ * SAFE from passing here, even though the following should work:
+ */
+ /* !i ? GIT_CHECKOUT_FORCE : GIT_CHECKOUT_SAFE; */
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+
+ cl_git_pass(
+ git_repository_set_head_detached(g_repo, git_object_id(obj)));
+
+ assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
+
+ git_object_free(obj);
+
+ if (!g_typechange_empty[i]) {
+ cl_assert(git_path_isdir("typechanges"));
+ cl_assert(git_path_exists("typechanges/a"));
+ cl_assert(git_path_exists("typechanges/b"));
+ cl_assert(git_path_exists("typechanges/c"));
+ cl_assert(git_path_exists("typechanges/d"));
+ cl_assert(git_path_exists("typechanges/e"));
+ } else {
+ cl_assert(git_path_isdir("typechanges"));
+ cl_assert(!git_path_exists("typechanges/a"));
+ cl_assert(!git_path_exists("typechanges/b"));
+ cl_assert(!git_path_exists("typechanges/c"));
+ cl_assert(!git_path_exists("typechanges/d"));
+ cl_assert(!git_path_exists("typechanges/e"));
+ }
+ }
+}
+
+typedef struct {
+ int conflicts;
+ int dirty;
+ int updates;
+ int untracked;
+ int ignored;
+} notify_counts;
+
+static int notify_counter(
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *baseline,
+ const git_diff_file *target,
+ const git_diff_file *workdir,
+ void *payload)
+{
+ notify_counts *cts = payload;
+
+ GIT_UNUSED(path);
+ GIT_UNUSED(baseline);
+ GIT_UNUSED(target);
+ GIT_UNUSED(workdir);
+
+ switch (why) {
+ case GIT_CHECKOUT_NOTIFY_CONFLICT: cts->conflicts++; break;
+ case GIT_CHECKOUT_NOTIFY_DIRTY: cts->dirty++; break;
+ case GIT_CHECKOUT_NOTIFY_UPDATED: cts->updates++; break;
+ case GIT_CHECKOUT_NOTIFY_UNTRACKED: cts->untracked++; break;
+ case GIT_CHECKOUT_NOTIFY_IGNORED: cts->ignored++; break;
+ default: break;
+ }
+
+ return 0;
+}
+
+static void force_create_file(const char *file)
+{
+ int error = git_futils_rmdir_r(file, NULL,
+ GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
+ cl_assert(!error || error == GIT_ENOTFOUND);
+ cl_git_pass(git_futils_mkpath2file(file, 0777));
+ cl_git_rewritefile(file, "yowza!");
+}
+
+void test_checkout_typechange__checkout_with_conflicts(void)
+{
+ int i;
+ git_object *obj;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ notify_counts cts = {0};
+
+ opts.notify_flags =
+ GIT_CHECKOUT_NOTIFY_CONFLICT | GIT_CHECKOUT_NOTIFY_UNTRACKED;
+ opts.notify_cb = notify_counter;
+ opts.notify_payload = &cts;
+
+ for (i = 0; g_typechange_oids[i] != NULL; ++i) {
+ cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));
+
+ force_create_file("typechanges/a/blocker");
+ force_create_file("typechanges/b");
+ force_create_file("typechanges/c/sub/sub/file");
+ git_futils_rmdir_r("typechanges/d", NULL, GIT_RMDIR_REMOVE_FILES);
+ p_mkdir("typechanges/d", 0777); /* intentionally empty dir */
+ force_create_file("typechanges/untracked");
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ memset(&cts, 0, sizeof(cts));
+
+ cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
+ cl_assert(cts.conflicts > 0);
+ cl_assert(cts.untracked > 0);
+
+ opts.checkout_strategy =
+ GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+ memset(&cts, 0, sizeof(cts));
+
+ cl_assert(git_path_exists("typechanges/untracked"));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+ cl_assert_equal_i(0, cts.conflicts);
+
+ cl_assert(!git_path_exists("typechanges/untracked"));
+
+ cl_git_pass(
+ git_repository_set_head_detached(g_repo, git_object_id(obj)));
+
+ assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
+
+ git_object_free(obj);
+ }
+}
diff --git a/tests-clar/clar b/tests-clar/clar
deleted file mode 100755
index 873dc3b0c..000000000
--- a/tests-clar/clar
+++ /dev/null
@@ -1,311 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import with_statement
-from string import Template
-import re, fnmatch, os
-
-VERSION = "0.10.0"
-
-TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*void\s*\))\s*\{"
-
-EVENT_CB_REGEX = re.compile(
- r"^(void\s+clar_on_(\w+)\(\s*void\s*\))\s*\{",
- re.MULTILINE)
-
-SKIP_COMMENTS_REGEX = re.compile(
- r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
- re.DOTALL | re.MULTILINE)
-
-CLAR_HEADER = """
-/*
- * Clar v%s
- *
- * This is an autogenerated file. Do not modify.
- * To add new unit tests or suites, regenerate the whole
- * file with `./clar`
- */
-""" % VERSION
-
-CLAR_EVENTS = [
- 'init',
- 'shutdown',
- 'test',
- 'suite'
-]
-
-def main():
- from optparse import OptionParser
-
- parser = OptionParser()
-
- parser.add_option('-c', '--clar-path', dest='clar_path')
- parser.add_option('-v', '--report-to', dest='print_mode', default='default')
-
- options, args = parser.parse_args()
-
- for folder in args or ['.']:
- builder = ClarTestBuilder(folder,
- clar_path = options.clar_path,
- print_mode = options.print_mode)
-
- builder.render()
-
-
-class ClarTestBuilder:
- def __init__(self, path, clar_path = None, print_mode = 'default'):
- self.declarations = []
- self.suite_names = []
- self.callback_data = {}
- self.suite_data = {}
- self.event_callbacks = []
-
- self.clar_path = os.path.abspath(clar_path) if clar_path else None
-
- self.path = os.path.abspath(path)
- self.modules = [
- "clar_sandbox.c",
- "clar_fixtures.c",
- "clar_fs.c"
- ]
-
- self.modules.append("clar_print_%s.c" % print_mode)
-
- print("Loading test suites...")
-
- for root, dirs, files in os.walk(self.path):
- module_root = root[len(self.path):]
- module_root = [c for c in module_root.split(os.sep) if c]
-
- tests_in_module = fnmatch.filter(files, "*.c")
-
- for test_file in tests_in_module:
- full_path = os.path.join(root, test_file)
- test_name = "_".join(module_root + [test_file[:-2]])
-
- with open(full_path) as f:
- self._process_test_file(test_name, f.read())
-
- if not self.suite_data:
- raise RuntimeError(
- 'No tests found under "%s"' % path)
-
- def render(self):
- main_file = os.path.join(self.path, 'clar_main.c')
- with open(main_file, "w") as out:
- out.write(self._render_main())
-
- header_file = os.path.join(self.path, 'clar.h')
- with open(header_file, "w") as out:
- out.write(self._render_header())
-
- print ('Written Clar suite to "%s"' % self.path)
-
- #####################################################
- # Internal methods
- #####################################################
-
- def _render_cb(self, cb):
- return '{"%s", &%s}' % (cb['short_name'], cb['symbol'])
-
- def _render_suite(self, suite, index):
- template = Template(
-r"""
- {
- ${suite_index},
- "${clean_name}",
- ${initialize},
- ${cleanup},
- ${cb_ptr}, ${cb_count}
- }
-""")
-
- callbacks = {}
- for cb in ['initialize', 'cleanup']:
- callbacks[cb] = (self._render_cb(suite[cb])
- if suite[cb] else "{NULL, NULL}")
-
- return template.substitute(
- suite_index = index,
- clean_name = suite['name'].replace("_", "::"),
- initialize = callbacks['initialize'],
- cleanup = callbacks['cleanup'],
- cb_ptr = "_clar_cb_%s" % suite['name'],
- cb_count = suite['cb_count']
- ).strip()
-
- def _render_callbacks(self, suite_name, callbacks):
- template = Template(
-r"""
-static const struct clar_func _clar_cb_${suite_name}[] = {
- ${callbacks}
-};
-""")
- callbacks = [
- self._render_cb(cb)
- for cb in callbacks
- if cb['short_name'] not in ('initialize', 'cleanup')
- ]
-
- return template.substitute(
- suite_name = suite_name,
- callbacks = ",\n\t".join(callbacks)
- ).strip()
-
- def _render_event_overrides(self):
- overrides = []
- for event in CLAR_EVENTS:
- if event in self.event_callbacks:
- continue
-
- overrides.append(
- "#define clar_on_%s() /* nop */" % event
- )
-
- return '\n'.join(overrides)
-
- def _render_header(self):
- template = Template(self._load_file('clar.h'))
-
- declarations = "\n".join(
- "extern %s;" % decl
- for decl in sorted(self.declarations)
- )
-
- return template.substitute(
- extern_declarations = declarations,
- )
-
- def _render_main(self):
- template = Template(self._load_file('clar.c'))
- suite_names = sorted(self.suite_names)
-
- suite_data = [
- self._render_suite(self.suite_data[s], i)
- for i, s in enumerate(suite_names)
- ]
-
- callbacks = [
- self._render_callbacks(s, self.callback_data[s])
- for s in suite_names
- ]
-
- callback_count = sum(
- len(cbs) for cbs in self.callback_data.values()
- )
-
- return template.substitute(
- clar_modules = self._get_modules(),
- clar_callbacks = "\n".join(callbacks),
- clar_suites = ",\n\t".join(suite_data),
- clar_suite_count = len(suite_data),
- clar_callback_count = callback_count,
- clar_event_overrides = self._render_event_overrides(),
- )
-
- def _load_file(self, filename):
- if self.clar_path:
- filename = os.path.join(self.clar_path, filename)
- with open(filename) as cfile:
- return cfile.read()
-
- else:
- import zlib, base64, sys
- content = CLAR_FILES[filename]
-
- if sys.version_info >= (3, 0):
- content = bytearray(content, 'utf_8')
- content = base64.b64decode(content)
- content = zlib.decompress(content)
- return str(content, 'utf-8')
- else:
- content = base64.b64decode(content)
- return zlib.decompress(content)
-
- def _get_modules(self):
- return "\n".join(self._load_file(f) for f in self.modules)
-
- def _skip_comments(self, text):
- def _replacer(match):
- s = match.group(0)
- return "" if s.startswith('/') else s
-
- return re.sub(SKIP_COMMENTS_REGEX, _replacer, text)
-
- def _process_test_file(self, suite_name, contents):
- contents = self._skip_comments(contents)
-
- self._process_events(contents)
- self._process_declarations(suite_name, contents)
-
- def _process_events(self, contents):
- for (decl, event) in EVENT_CB_REGEX.findall(contents):
- if event not in CLAR_EVENTS:
- continue
-
- self.declarations.append(decl)
- self.event_callbacks.append(event)
-
- def _process_declarations(self, suite_name, contents):
- callbacks = []
- initialize = cleanup = None
-
- regex_string = TEST_FUNC_REGEX % suite_name
- regex = re.compile(regex_string, re.MULTILINE)
-
- for (declaration, symbol, short_name) in regex.findall(contents):
- data = {
- "short_name" : short_name,
- "declaration" : declaration,
- "symbol" : symbol
- }
-
- if short_name == 'initialize':
- initialize = data
- elif short_name == 'cleanup':
- cleanup = data
- else:
- callbacks.append(data)
-
- if not callbacks:
- return
-
- tests_in_suite = len(callbacks)
-
- suite = {
- "name" : suite_name,
- "initialize" : initialize,
- "cleanup" : cleanup,
- "cb_count" : tests_in_suite
- }
-
- if initialize:
- self.declarations.append(initialize['declaration'])
-
- if cleanup:
- self.declarations.append(cleanup['declaration'])
-
- self.declarations += [
- callback['declaration']
- for callback in callbacks
- ]
-
- callbacks.sort(key=lambda x: x['short_name'])
- self.callback_data[suite_name] = callbacks
- self.suite_data[suite_name] = suite
- self.suite_names.append(suite_name)
-
- print(" %s (%d tests)" % (suite_name, tests_in_suite))
-
-
-
-CLAR_FILES = {
-"clar.c" : r"""eJytGWtv20byM/krNs4lpmxasZTD4c5OXAS55mC0dYA8kAKJQazIlbUORcpcMrHb6r93ZvbB5UN2D2g+xOa8dmZ2nuvHskjzJhPsBVdKVPV0dRY+djAl6uv1pgers1wuBjBZ9kGVLK66sDWvVwNGXhFV+OyAVeKmkZXI2LKsmOJFtihvQQg7eOaz3Kln9d1GqJ4kAKuakwEAXmZiyZJP5xfP5+HjwFF9l0VWftesLdTo3gLUSuQ538geOAPlUnNCAAfIQrDkl1fnF8nr1yxJ0kykuYdCdaIN2BzDrxOWdL9buvVXEGwQ6zITQNqCPLp05YAs8T5aCp6mQqmuqCHM17DKmk0EP0g994FGyGVBPkx+Ob/436fn8yQBYLCp+NWas7Rcr0VRRxAJMdsjdz2f76FkT3SRbu6iuozZsirXMavLRMnfQCWDShQhDdhSJR/efbx4/erDj76wT8nbn9jx3IO8T87f//f8XXQ7YVF0y56yBCBvADJhj16y444mxQZCsU7ETbRolrH6LV6u65jHC7RZ45agi8G58x0ViBK5EqMS7a9LJCoyuQwDjE10HFjZpLW+dfb+w6sPyYfT8LGR1Anb71xiUDHIAPx1I7NoPqGgb+maQkKu6HjsRZ53nSN69fXpqUM6t2m0l+a8mq72whDpZMq+lRLSUSXVOkrLQtUQhLxiB4kqmyoVk9M+XVrCnY9QxswHZgIS4NQd4qPCpbytm0okGLAdSQuuemIsacHXQosjE9GGRFQVFJHfw8BnqOHc0xC8WjP8NSma9UJUp10i1cha9GBLmQvDmIOnxxnpyGStrhBu7UwruallWYB6wVC/g0Lcgkbb1heGpqc4T2v5TSRG/xGMUVqrSB/6BGXNLWueO5DngrRsitpCKrEpq9qQJWWR3+1Q28keweVcGRHITIERHeRlCuenueBFs5lEBD2AO9P4Lhqu/i4veYbs0H4SyExWV3y9KdH31iAHSETBF7kA8i2URVCkFwnLpkj7/sSIOXXKbaDkkUoTexUtN/kS2fFQ6B7i9nRU1OBEWcha8hxK2xjWmOpkDQgoVsnDICHpXhbqCMXiDRRMzaHT/mCaYtXwM9LDoj5R99pj1kaLAQwSgZJL9RLdE6tWTQ0ttXhYNAJ0ihBgt0giInmQZlalXUG4W0xZoDpRP//JIK2NVwM0YMkhz7P7RJJF0biXfJspUu4TxBeQaR1BUDhiNp1OJ/3bNZPQjtttCoO3EWwoUBef3aJR9o/fBGJ5ni94+pWV38CVEooVHvCP37WPkSRxmC3xvWrq8koUouI1TGnoPpbxmrPFHR3lsVvZyNip8sPcStrf1edL9hKSjcE/I0jDt50SqTPC49MRBaw+kwZuT0fZrH59zi7cJNrrshLaWkxNrOaqdxUhMXfKp/Z3aCsHHDEbr5f0I7atIAw0+KVWdOoq7fcVxCaLNBZmnIuPP/88wcIUICPQE+boTIsJgmFCHR7GzOZMECwrISLD4/WpHo4+rUZGNFxp4CvndG0rP9P6QakKR9zUFNTJovuLX7wb3dbWe4hss7FXoGuPqp263TYZao+VRjc0XJMNO42+S5C6ZJFekaI+6YS9xDGU7gfJWo2PzqDduAsEdNDD4dEARi3ct+fzUXWOrTrmIvx26p81gh5jsR14YsUa+EB3H671Nkq6RnB4iFBa7tZQTRgv7hiddQSes22QrUW9KjPKqjEdXTiNIa2yjsj3xHCimdjc6GYrOpmG807mmB6Ct6Tvg+o8fvbtJGA0DCx25gKPLnuyOyf83jIsk7rRUDTflzXgBSI8OusNENI65tGDnuk2OyNOdzjzYdubyxlN6kWAP5e2OplhacRNJoZx848kfUHNfOHbYqYfdngodV51DjK244/P8nJqDgq6BeepQcfsqTPEVRIHs4WD0m5LrwnsGLezWkDmVbyS+R3LpNLJN9oI8DZlcZWPXecDFW5w27uc9dcdPXSRJQh7DiKt/qJztm59HNjfKH7VnZJ4dUXG6K002vuIFCfsiWKfS+o76vJL8aXYixlSnraEbzX2BHA+mLEj9euvX+ov9bumYBi9rF4JbT3TIx2DUEIrGdANmG8YQ+a3yKgzgfyiQArsxyuoJrzQiWt4xS2Mz0ezHem74ZUSCaiuaG6FX9LYWI6mf2vngE6Qz3SQI7kX185jDb6xABlKgKiltoAZbFGfjy+xGO8f7VNp8VxPHMeXupOo77JOVx7b7NIcBBs121f7J/QVmIkbDkQjJhCUdZk7LnbI5hAG9jNms2MaDjoaYdcz2iK9PiawJeia6AN9xtFMf5EzrnXGX4MzBmMdeuaaDNRngV4pdNxWkc4Aea1z3++/7ZlGgSBYVIJ/NR/b0P6H0pHwBT4gBbs8aggjbdQEGc5eDtW2Z49M/Xvv/TB9krGshNm7KGFGuZWqnlIeAFYf5oWeVbTXMp52PACMRk1nJU4P5rZv9k/a9jXsAWZMdbwhPXrxJq9PdoYYKbX18gJs1WlBNWV3QvS3U5BEkTc2osddpL9ZAmZvLwy8YcXbeiZ0mzrcR27iDW18rC7tezOVEaqU4F/YdKYm//1b2HrDIinujkY7oePP2lbaFgbtAzK+O6N0K7g/2betOxh0xtE8kZMHw0NedkzobfHh+GSz2/OG2nteMjfhJgMruoW2KyuqUom6qQo2FESltq2xif4LRaQLKTSXTGJriIcvdXH7UhfveKLrwb0FyDCrVdnkWUJhQsG6a3NzUWcVwivQNvnbHEZzmUazmPbQchkN5E16YWF7fX96dzNA5/jBBjac+h1OL4m+hJH9zeEMi5keBhPFaYfCPKc4Qv/ZytLZUWUY/S0NXiOQmHdXA/SeXgFnHgMNzt2sVV0/xGrneNfr+2W4/eIApf8M0l2Jx6Yw3GxGwl8vPNSo/BBym+CjXWucaRgjVYq6AJQqOETbdsJ4b3ViFZdK6KnlNhWk91QXrk7/oE6Ql8XV2NIaM1vfTOIxP/EScdOAlSrqPZfPermk5v9vSu5KOQSuOc4uMJKomU0F9scfTM3bSvmDRSoYOE7cgKAw1+ZmEHDLD8nz5qxFs/z8z+P//OsSvdP7UxFDRMz29p+ofRq04Cd0ZiPYrRe2MB3HFK+xthJvKmYkpmPYQ/6VpsDJmXGL/Pv8iQ8RM7REznsumM3/PeoBgIMDYEQBpicZGA9qIfffY3yiRO3eIcxjfP9vBLF+6zwoN/ym8Tei/gtB+6R+/yOBFkTNxTz6rcusyemNE93m/qK75rIYTC809lyiGvhIaXpXO+x0mvw2/BMhekzB""",
-"clar_print_default.c" : r"""eJyFU8Fu2zAMPdtfwQUwIgVuenew9tZTsMuwU1sYqiW3AhzJkOhswNB/n0Q5rRws6Ukmxff4RD6XHgXqDo5WS+gG4drRaYOtNhpZ+ABUHtvOTgZriLGfNKpTorPGI3RvwsEmXRhxUJ6Xf8uCRUr+Cd+VBVH3bLW3QioJlUxsvoHKP5lVDbEjX3TIWTOGnygcKhlAIftelhde4d8mlPa3+folMaGcsy4lLr0gpTLkRy4D78pPoU8maSxIlVOjddhSrWdXpVMN6TbT4TRpj27qMJVRAWzoILmnlhAGy+FB6GFyqqG5Bgqeq6p801QeWOU5PIagks/weIPhiOVlURDrzR09NIvjLGK4Mhak8p3TI2q7gPR6yBGDNmF90+FFuTOeObvQBScjzHVpqAf/SlW6BzZfZM3h23f48Wu/54H+Ek9Wzpfbue4fa6JSlts8SQ9+TJ7JXpISfZi7kuf+iYDdMkOYzNJVF/QmNNzD+mENDay36y/00YbY///D3ObaSPWHVN1uwFg7wuZ2aWeqOLN4kn2tv3gJhl70D9uqYbvdUrOjaAcdroR7HXcU+vjnshjXkBZbHPt5Bh5lWBjla4LwhFFGsjl8L/8BsUiTTQ==""",
-"clar_print_tap.c" : r"""eJyNVE1vnDAQPcOvmGWFBAiQot6yaqr2HFU9tLdKyAGzscLayDbbVlX+e8cDJPbuJtsTzPObmTcfdmwss6KFoxIdtAPTzaiFtI2Qwmb4A5Yb27RqkrYEZ5tJWL4CrZLGQvvINBTzgWQHbvL4bxxlLmT+6r5bIY94gq08ktBnyffP3+DItRFKws2HnzLJd/FzHL8h2TxOtlO/5HXZDuBaKz0D/yM3xDznXRxHoodsEwSMXmrYwsiM4R2wYYC0I2GZybGY0hOJhUV8MDxw7JkY0BGd2EHJ/am3l7BEvyiMtoa5qeu0O8/2dhspLPVQTod1xMbqqbUzjQhQ0MdrHbJdL9a8AFVVzSPzMJy5YXsOt5Ca1yKqu7mWg9mHdMNx/ML+uaVenEWj0QCcRSM8pLri4QLV4SGzx6ZfYjo8ZA5CrszOZzq8wXY8cJ2v67Ecddy0WozWbfTmI3z9cX/vLwuARzgV4B3lYafrur52OZSk1fEvLO2Du4bzhZhNUj0D8/rRhNdUqXFLWC3CUPiyop8gkcqCekqwGQl+3Jkf8MXEdHFE8kmc5qPSy86Z7EoFNNbs8pvj33IhO/470L2FoihQNWTbtMudQY313X3X92WwB5QcyMC9Ld0QKOeRNYPAI6b3445MjIQOzi5hWfF+UWbwxZrwRUq+YCMBfzdAO348JVAKFyKfY3LZZYv5HP8D5Mbj9w==""",
-"clar_sandbox.c" : r"""eJydVWtP4kAU/dz+iism0gpKfWQ3G9YPm+gasioEMJgomdR2KhPplMwM7KLxv++dTqEP0DVrTKjcO+eec+6cKpWvWADBxBdAgqkvyMxXk/tT79uXcdu2pSkzrmwmycKfspCoeJY2OUHCpTJH9/UXrv1qW4PhjyEZglR42mIROBrC0eUm7Enlws4ZeK5tWYKqueDgrfp2BqQzOO/08cChVCROQupW+7Jnxw8CKmWGOiLdXy6cadi2/VbiHDFe5JsyfZxHERVNkOyFEgVTyp8M9V0W8ZBGQEadm5Nj28pwjMqse4EGBcmcKziD03alx+BTvkCjhLwfYw8aYtWG1z3UVWuCfko/Lszn7eCi3+t3f3auLmo2WG8oEaxsEtN6o0SAwxDHawOD7/n4NjQazE3hK7Ox+YkqfHDWRNgYjbGMyfilNlWfUozPqZ6SVjbXq1vNCJQpeDBbOivvsNRcOaehC0uyrDcbf22rtQ+dCNSE6m4mEh5TtC1MqOR19NNfgs+XasL4UxOUWIJKYC4ptHA+7Lfsd0jVdL2W8arSMsUSswIxJLVLp5Ia6EuqhjSe9TSocz7q9s9dc6wJBq5y+XYpD1lkdA0nTIJcSkXjtaApe6YooKRFiw/mQqTCmaCBSrD4gbjDd5UdfiRr9efBUTEAi4SFkEZ6zqXPw8fkj6O/S2OqCRTy7o11gOoPXj1XjVcDI1FMRDBBFcgSaRYMiSQRcQGsmkL0k01DklEwStc8CrdXF4jy2TRNTi3F09bcpT81nbZ1ZFcvjXLAcw4m3klUpOVigIpvHu2WbSEYTkO/8aEsoqr+FXD1PBExLu2FpnT1onvdQecOMKm/fRGCnPpyQmW65EKUrY0oaxF5iKv7YNk+HtJ9WFalBPVWfR219SIqGFrZARyN9RsX+82gcr3RyMH0PVpdu7wLGpppM1/ONmdxDDZllgF6xjgNHUKuOzeXo5NjQtyMXPyMkZmVjqLMm9urq4296P74Wd+34la9r5638S9EH8BkF0enKytPJfKf92ML7v8QWb1i8NQn5a5XmOe6HKEU4fMhhr29banbngCNYpJdJLrVixK9v7GvgW8=""",
-"clar_fixtures.c" : r"""eJyFUV1LwzAUfW5+xZU9rLUVJ4ggZQ9DFAUfZEwQSglZmrBAl5Qkk6n43236tWbKfMvNOfecc+81llhBgSppLNAN0XCOuNjbnWa4InYTjpE1MSzxuD1Vki2L0BcKTKfn0EYgu57d3uRpjYhPhi1opSwumUwRCvo3zMFYXT9C5xA5stWSVh9hI5FAa+wUFG//osgJCA5tmQ1SF3CVw9kcppfTCAWBj8ZxDg3UN4/zZ7MaHBrHSBw7vpcJ4mGS5Ijtai9qnannNqk1q7myXU+KvhGaCF4wDnfPiyV+eHpbvS7v8cti9YjGq6Yl7lzCkxfo1L0j/lJOwOtrUrwrUcDBBRsii7Xan3bjBlNVL2WUzuMkgGlJdLuIP21oyYjcVf/a6G3ozXTQPRqmsZkwWQiOfgAVGffP""",
-"clar_fs.c" : r"""eJylVdtu20YQfSa/YkAD8TKWY8dJX6L0wXDEVqgsBhINN7UFhiGX1qIkl9hd+dLG/57ZCynJUWEkfZE0s7NnZufMGe2xsqAlpJfj6ZsT399DgzUUojhKo8npb3Mg+ud8PBlNE/hq/NP4LJ5G49n5aTKOp71zNJvFs4vx06DzPz6MZ6HvS5UplkO+zAS89EtWUd7KtM3UkuS8kcqdGE/o/+t71tYm/ArTi8lk6HuS/UNTBRVtbtRyAGzo+x4rgaQ2zMaFvucJqlaicdd8z15AHKkE/rbxIQI6+DqrKp4TF3YAJ2GH/AxwTeu8fTBRA0jtl0Xp0K+sucAsx9suzPPauX2v5AIIMxYweO9AhnBwwELAbvTFXLGFrmf/aF+X4/Uu2L++3scEjwjmitRnQ/+x7/0tZ0XXecIaBTUv6AC22i/5SuRPnQWVynAy/z3CSYg/zpPZxVkCJQLp4m2YvYqVbJHrEHU7bJgG+y7IZNBQf1HBz2nNxQN5oeEHoDnnJdlOHYa2aa18dRetmlxziI8ZOl8bCV5ruk3u3ptw9OlUnaeMquxGorOfd/OcKs2kpEKlBFuMibHUuKUCm8gbW1aoOTge4HFwyZqC30l4EgdlhmYR+J4tVVBK1q0wpnv0U4JkKmqygxTDQEdfFKcfRpNRMsKx6zgzM7oLL+c4oz9A80aSs/jjp40U6bpmA46t0vgVzZpVS7TLApg3lOwe55A6ivMqE04hwcsgtCB7tJK0KxdH0pdLWlUpXylii3IVZuLm9mphsPXg6gsrqeXECtwH+Kl7jF96sLj4m6z1i773cGw1VLYCb5dEqoIKodnzgvmDVLQGtLl4B5/t7c+Q40ZwFL66bgLNmUfvmSKHr0Onsg5eT4LFp/c0vyWm1uPFwBTdBd9lTGGwvjCAF7b+Ad4b9mq9HP05TubJaXIxJ/b8f3DZU2lNU9Ivi+G2VNcL1dopLh3dt17IuC0LpHVDwuvA9TLtT21LrHm1EXlo9ly/s/4rwC5C1z00g6MvrDnK22DovCYoOJz1jpPFpsaN6412udkJndTNwdtF/zdiFF6vpMJxlNKIfD12hjQj7MiwD4qD7jkovbfcSEvtlVlTfOH3uxX+rKg3NL3B0dvFrh6I+rselNtN6F68oxk/+2araVBLuv3SZ6RvZL5q3BVi9r52bTgeUfZNwUr/G9kaoSs=""",
-"clar.h" : r"""eJy9VU1P4zAQPZNfYZo9JJUFlCMLSAi1AqlCKyjavVmO4xBrEyfYztLVav874yRtmq922QOX1pnxzHvOe+O4IpIhjxAht8ubR7KaP63IHSGOC0EheS/uuEKypAg5utQmTERwEl87zq9MhIglVBFCtebKeM6RkAaxTIbCiExi5wjWGiIxVWgaiYTjaksCKJ0sVypTnVjINVMir3vZQh1nRRISGmTK+F8HOBD+WtCEaG+3Dx5/gKa9ADQe6ys8WzBUNNRl04ZobghLOJVF7pUxb1o/+tXz1MeoWmQ5fS14Q4FEulVq27oisvKVIi3uf6yeH+fk283qztnlYEvF2hSKe20VyhiRNG2h1GFNZRhk64+UbNjtKXE5WCJynNPp1EFTdFO+UlAVpZSpTKM3YWLE13kimDCotAJKudb0hcP+060xATUttCE5iEI8KFAYWZP4bR+WGR9dX6EzDGZe3C/nhNjV8v6hXE0WhWQlAUaTBEUUrBleoAlym54YzfwesN15GPhyFHe+zjkzPERRi4DJSg4HGNROPAh/PH5uwFfwXi2w0EhmBhlV8CHcjVa3MWc//0MnZus+Sagzv4/8yUoNUfgEoc78A0Mls38cp5rS0IQ9PC+Xw6PQKdp9572i+ujbirabq+3jpjt0jsZuDULfgj1SjVe6ZXvPUm7pVgyeZJEpZk0E3eA+PH2jSgr50mVfEhjwyZg7Vhxu2moYTibDl0WN9JGu36sSFBbK/hkLwtecFdZVF5MBz61+53A42nFe93SdL7OeYX3eprTNQdLHHqTxluGW4OTJlLxSoVNqWFwOg57BL8yRXZ6PXJjbT/cMi2Fg4UESgMUgsCsaELEfJPCCGQ7GQI6PIe1j+zcMFDRAwX6g3MtnOD/fmSQPIj66ukIehHcksiqm3MRZCPpZWtRKVYn05Q9fG64k2c38dTbf63eIKlZw"""
-}
-if __name__ == '__main__':
- main()
diff --git a/tests-clar/clar.c b/tests-clar/clar.c
new file mode 100644
index 000000000..fed87c30d
--- /dev/null
+++ b/tests-clar/clar.c
@@ -0,0 +1,431 @@
+/*
+ * Copyright (c) Vicent Marti. All rights reserved.
+ *
+ * This file is part of clar, distributed under the ISC license.
+ * For full terms see the included COPYING file.
+ */
+#include <assert.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <stdarg.h>
+
+/* required for sandboxing */
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifdef _WIN32
+# include <windows.h>
+# include <io.h>
+# include <shellapi.h>
+# include <direct.h>
+
+# define _MAIN_CC __cdecl
+
+# define stat(path, st) _stat(path, st)
+# define mkdir(path, mode) _mkdir(path)
+# define chdir(path) _chdir(path)
+# define access(path, mode) _access(path, mode)
+# define strdup(str) _strdup(str)
+# define strcasecmp(a,b) _stricmp(a,b)
+
+# ifndef __MINGW32__
+# pragma comment(lib, "shell32")
+# define strncpy(to, from, to_size) strncpy_s(to, to_size, from, _TRUNCATE)
+# define W_OK 02
+# define S_ISDIR(x) ((x & _S_IFDIR) != 0)
+# define snprint_eq(buf,sz,fmt,a,b) _snprintf_s(buf,sz,_TRUNCATE,fmt,a,b)
+# else
+# define snprint_eq snprintf
+# endif
+ typedef struct _stat STAT_T;
+#else
+# include <sys/wait.h> /* waitpid(2) */
+# include <unistd.h>
+# define _MAIN_CC
+# define snprint_eq snprintf
+ typedef struct stat STAT_T;
+#endif
+
+#include "clar.h"
+
+static void fs_rm(const char *_source);
+static void fs_copy(const char *_source, const char *dest);
+
+static const char *
+fixture_path(const char *base, const char *fixture_name);
+
+struct clar_error {
+ const char *test;
+ int test_number;
+ const char *suite;
+ const char *file;
+ int line_number;
+ const char *error_msg;
+ char *description;
+
+ struct clar_error *next;
+};
+
+static struct {
+ const char *active_test;
+ const char *active_suite;
+
+ int suite_errors;
+ int total_errors;
+
+ int tests_ran;
+ int suites_ran;
+
+ int report_errors_only;
+ int exit_on_error;
+ int report_suite_names;
+
+ struct clar_error *errors;
+ struct clar_error *last_error;
+
+ void (*local_cleanup)(void *);
+ void *local_cleanup_payload;
+
+ jmp_buf trampoline;
+ int trampoline_enabled;
+} _clar;
+
+struct clar_func {
+ const char *name;
+ void (*ptr)(void);
+};
+
+struct clar_suite {
+ const char *name;
+ struct clar_func initialize;
+ struct clar_func cleanup;
+ const struct clar_func *tests;
+ size_t test_count;
+ int enabled;
+};
+
+/* From clar_print_*.c */
+static void clar_print_init(int test_count, int suite_count, const char *suite_names);
+static void clar_print_shutdown(int test_count, int suite_count, int error_count);
+static void clar_print_error(int num, const struct clar_error *error);
+static void clar_print_ontest(const char *test_name, int test_number, int failed);
+static void clar_print_onsuite(const char *suite_name, int suite_index);
+static void clar_print_onabort(const char *msg, ...);
+
+/* From clar_sandbox.c */
+static void clar_unsandbox(void);
+static int clar_sandbox(void);
+
+/* Load the declarations for the test suite */
+#include "clar.suite"
+
+/* Core test functions */
+static void
+clar_report_errors(void)
+{
+ int i = 1;
+ struct clar_error *error, *next;
+
+ error = _clar.errors;
+ while (error != NULL) {
+ next = error->next;
+ clar_print_error(i++, error);
+ free(error->description);
+ free(error);
+ error = next;
+ }
+
+ _clar.errors = _clar.last_error = NULL;
+}
+
+static void
+clar_run_test(
+ const struct clar_func *test,
+ const struct clar_func *initialize,
+ const struct clar_func *cleanup)
+{
+ int error_st = _clar.suite_errors;
+
+ _clar.trampoline_enabled = 1;
+
+ if (setjmp(_clar.trampoline) == 0) {
+ if (initialize->ptr != NULL)
+ initialize->ptr();
+
+ test->ptr();
+ }
+
+ _clar.trampoline_enabled = 0;
+
+ if (_clar.local_cleanup != NULL)
+ _clar.local_cleanup(_clar.local_cleanup_payload);
+
+ if (cleanup->ptr != NULL)
+ cleanup->ptr();
+
+ _clar.tests_ran++;
+
+ /* remove any local-set cleanup methods */
+ _clar.local_cleanup = NULL;
+ _clar.local_cleanup_payload = NULL;
+
+ if (_clar.report_errors_only)
+ clar_report_errors();
+ else
+ clar_print_ontest(
+ test->name,
+ _clar.tests_ran,
+ (_clar.suite_errors > error_st)
+ );
+}
+
+static void
+clar_run_suite(const struct clar_suite *suite)
+{
+ const struct clar_func *test = suite->tests;
+ size_t i;
+
+ if (!suite->enabled)
+ return;
+
+ if (_clar.exit_on_error && _clar.total_errors)
+ return;
+
+ if (!_clar.report_errors_only)
+ clar_print_onsuite(suite->name, ++_clar.suites_ran);
+
+ _clar.active_suite = suite->name;
+ _clar.suite_errors = 0;
+
+ for (i = 0; i < suite->test_count; ++i) {
+ _clar.active_test = test[i].name;
+ clar_run_test(&test[i], &suite->initialize, &suite->cleanup);
+
+ if (_clar.exit_on_error && _clar.total_errors)
+ return;
+ }
+}
+
+static void
+clar_usage(const char *arg)
+{
+ printf("Usage: %s [options]\n\n", arg);
+ printf("Options:\n");
+ printf(" -sname\tRun only the suite with `name`\n");
+ printf(" -iname\tInclude the suite with `name`\n");
+ printf(" -xname\tExclude the suite with `name`\n");
+ printf(" -q \tOnly report tests that had an error\n");
+ printf(" -Q \tQuit as soon as a test fails\n");
+ printf(" -l \tPrint suite names\n");
+ exit(-1);
+}
+
+static void
+clar_parse_args(int argc, char **argv)
+{
+ int i;
+
+ for (i = 1; i < argc; ++i) {
+ char *argument = argv[i];
+
+ if (argument[0] != '-')
+ clar_usage(argv[0]);
+
+ switch (argument[1]) {
+ case 's':
+ case 'i':
+ case 'x': { /* given suite name */
+ int offset = (argument[2] == '=') ? 3 : 2, found = 0;
+ char action = argument[1];
+ size_t j, len;
+
+ argument += offset;
+ len = strlen(argument);
+
+ if (len == 0)
+ clar_usage(argv[0]);
+
+ for (j = 0; j < _clar_suite_count; ++j) {
+ if (strncmp(argument, _clar_suites[j].name, len) == 0) {
+ int exact = !strcmp(argument, _clar_suites[j].name);
+
+ ++found;
+
+ if (!exact)
+ _clar.report_suite_names = 1;
+
+ switch (action) {
+ case 's': clar_run_suite(&_clar_suites[j]); break;
+ case 'i': _clar_suites[j].enabled = 1; break;
+ case 'x': _clar_suites[j].enabled = 0; break;
+ }
+
+ if (exact)
+ break;
+ }
+ }
+
+ if (!found) {
+ clar_print_onabort("No suite matching '%s' found.\n", argument);
+ exit(-1);
+ }
+ break;
+ }
+
+ case 'q':
+ _clar.report_errors_only = 1;
+ break;
+
+ case 'Q':
+ _clar.exit_on_error = 1;
+ break;
+
+ case 'l': {
+ size_t j;
+ printf("Test suites (use -s<name> to run just one):\n");
+ for (j = 0; j < _clar_suite_count; ++j)
+ printf(" %3d: %s\n", (int)j, _clar_suites[j].name);
+
+ exit(0);
+ }
+
+ default:
+ clar_usage(argv[0]);
+ }
+ }
+}
+
+int
+clar_test(int argc, char **argv)
+{
+ clar_print_init(
+ (int)_clar_callback_count,
+ (int)_clar_suite_count,
+ ""
+ );
+
+ if (clar_sandbox() < 0) {
+ clar_print_onabort("Failed to sandbox the test runner.\n");
+ exit(-1);
+ }
+
+ if (argc > 1)
+ clar_parse_args(argc, argv);
+
+ if (!_clar.suites_ran) {
+ size_t i;
+ for (i = 0; i < _clar_suite_count; ++i)
+ clar_run_suite(&_clar_suites[i]);
+ }
+
+ clar_print_shutdown(
+ _clar.tests_ran,
+ (int)_clar_suite_count,
+ _clar.total_errors
+ );
+
+ clar_unsandbox();
+ return _clar.total_errors;
+}
+
+void clar__fail(
+ const char *file,
+ int line,
+ const char *error_msg,
+ const char *description,
+ int should_abort)
+{
+ struct clar_error *error = calloc(1, sizeof(struct clar_error));
+
+ if (_clar.errors == NULL)
+ _clar.errors = error;
+
+ if (_clar.last_error != NULL)
+ _clar.last_error->next = error;
+
+ _clar.last_error = error;
+
+ error->test = _clar.active_test;
+ error->test_number = _clar.tests_ran;
+ error->suite = _clar.active_suite;
+ error->file = file;
+ error->line_number = line;
+ error->error_msg = error_msg;
+
+ if (description != NULL)
+ error->description = strdup(description);
+
+ _clar.suite_errors++;
+ _clar.total_errors++;
+
+ if (should_abort) {
+ if (!_clar.trampoline_enabled) {
+ clar_print_onabort(
+ "Fatal error: a cleanup method raised an exception.");
+ clar_report_errors();
+ exit(-1);
+ }
+
+ longjmp(_clar.trampoline, -1);
+ }
+}
+
+void clar__assert(
+ int condition,
+ const char *file,
+ int line,
+ const char *error_msg,
+ const char *description,
+ int should_abort)
+{
+ if (condition)
+ return;
+
+ clar__fail(file, line, error_msg, description, should_abort);
+}
+
+void clar__assert_equal_s(
+ const char *s1,
+ const char *s2,
+ const char *file,
+ int line,
+ const char *err,
+ int should_abort)
+{
+ int match = (s1 == NULL || s2 == NULL) ? (s1 == s2) : (strcmp(s1, s2) == 0);
+
+ if (!match) {
+ char buf[4096];
+ snprint_eq(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
+ clar__fail(file, line, err, buf, should_abort);
+ }
+}
+
+void clar__assert_equal_i(
+ int i1,
+ int i2,
+ const char *file,
+ int line,
+ const char *err,
+ int should_abort)
+{
+ if (i1 != i2) {
+ char buf[128];
+ snprint_eq(buf, sizeof(buf), "%d != %d", i1, i2);
+ clar__fail(file, line, err, buf, should_abort);
+ }
+}
+
+void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
+{
+ _clar.local_cleanup = cleanup;
+ _clar.local_cleanup_payload = opaque;
+}
+
+#include "clar/sandbox.h"
+#include "clar/fixtures.h"
+#include "clar/fs.h"
+#include "clar/print.h"
diff --git a/tests-clar/clar.h b/tests-clar/clar.h
new file mode 100644
index 000000000..d92318bd4
--- /dev/null
+++ b/tests-clar/clar.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) Vicent Marti. All rights reserved.
+ *
+ * This file is part of clar, distributed under the ISC license.
+ * For full terms see the included COPYING file.
+ */
+#ifndef __CLAR_TEST_H__
+#define __CLAR_TEST_H__
+
+#include <stdlib.h>
+
+int clar_test(int argc, char *argv[]);
+
+void cl_set_cleanup(void (*cleanup)(void *), void *opaque);
+void cl_fs_cleanup(void);
+
+#ifdef CLAR_FIXTURE_PATH
+const char *cl_fixture(const char *fixture_name);
+void cl_fixture_sandbox(const char *fixture_name);
+void cl_fixture_cleanup(const char *fixture_name);
+#endif
+
+/**
+ * Assertion macros with explicit error message
+ */
+#define cl_must_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __LINE__, "Function call failed: " #expr, desc, 1)
+#define cl_must_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __LINE__, "Expected function call to fail: " #expr, desc, 1)
+#define cl_assert_(expr, desc) clar__assert((expr) != 0, __FILE__, __LINE__, "Expression is not true: " #expr, desc, 1)
+
+/**
+ * Check macros with explicit error message
+ */
+#define cl_check_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __LINE__, "Function call failed: " #expr, desc, 0)
+#define cl_check_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __LINE__, "Expected function call to fail: " #expr, desc, 0)
+#define cl_check_(expr, desc) clar__assert((expr) != 0, __FILE__, __LINE__, "Expression is not true: " #expr, desc, 0)
+
+/**
+ * Assertion macros with no error message
+ */
+#define cl_must_pass(expr) cl_must_pass_(expr, NULL)
+#define cl_must_fail(expr) cl_must_fail_(expr, NULL)
+#define cl_assert(expr) cl_assert_(expr, NULL)
+
+/**
+ * Check macros with no error message
+ */
+#define cl_check_pass(expr) cl_check_pass_(expr, NULL)
+#define cl_check_fail(expr) cl_check_fail_(expr, NULL)
+#define cl_check(expr) cl_check_(expr, NULL)
+
+/**
+ * Forced failure/warning
+ */
+#define cl_fail(desc) clar__fail(__FILE__, __LINE__, "Test failed.", desc, 1)
+#define cl_warning(desc) clar__fail(__FILE__, __LINE__, "Warning during test execution:", desc, 0)
+
+/**
+ * Typed assertion macros
+ */
+#define cl_assert_equal_s(s1,s2) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2, 1)
+#define cl_assert_equal_s_(s1,s2,note) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1)
+
+#define cl_assert_equal_i(i1,i2) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2, 1)
+#define cl_assert_equal_i_(i1,i2,note) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2 " (" #note ")", 1)
+
+#define cl_assert_equal_b(b1,b2) clar__assert_equal_i(!!(b1),!!(b2),__FILE__,__LINE__,#b1 " != " #b2, 1)
+
+#define cl_assert_equal_p(p1,p2) cl_assert((p1) == (p2))
+
+void clar__fail(
+ const char *file,
+ int line,
+ const char *error,
+ const char *description,
+ int should_abort);
+
+void clar__assert(
+ int condition,
+ const char *file,
+ int line,
+ const char *error,
+ const char *description,
+ int should_abort);
+
+void clar__assert_equal_s(const char *,const char *,const char *,int,const char *,int);
+void clar__assert_equal_i(int,int,const char *,int,const char *,int);
+
+#endif
diff --git a/tests-clar/clar/fixtures.h b/tests-clar/clar/fixtures.h
new file mode 100644
index 000000000..264cd7f4f
--- /dev/null
+++ b/tests-clar/clar/fixtures.h
@@ -0,0 +1,38 @@
+static const char *
+fixture_path(const char *base, const char *fixture_name)
+{
+ static char _path[4096];
+ size_t root_len;
+
+ root_len = strlen(base);
+ strncpy(_path, base, sizeof(_path));
+
+ if (_path[root_len - 1] != '/')
+ _path[root_len++] = '/';
+
+ if (fixture_name[0] == '/')
+ fixture_name++;
+
+ strncpy(_path + root_len,
+ fixture_name,
+ sizeof(_path) - root_len);
+
+ return _path;
+}
+
+#ifdef CLAR_FIXTURE_PATH
+const char *cl_fixture(const char *fixture_name)
+{
+ return fixture_path(CLAR_FIXTURE_PATH, fixture_name);
+}
+
+void cl_fixture_sandbox(const char *fixture_name)
+{
+ fs_copy(cl_fixture(fixture_name), _clar_path);
+}
+
+void cl_fixture_cleanup(const char *fixture_name)
+{
+ fs_rm(fixture_path(_clar_path, fixture_name));
+}
+#endif
diff --git a/tests-clar/clar/fs.h b/tests-clar/clar/fs.h
new file mode 100644
index 000000000..b7a1ff9d2
--- /dev/null
+++ b/tests-clar/clar/fs.h
@@ -0,0 +1,325 @@
+#ifdef _WIN32
+
+#define RM_RETRY_COUNT 5
+#define RM_RETRY_DELAY 10
+
+#ifdef __MINGW32__
+
+/* These security-enhanced functions are not available
+ * in MinGW, so just use the vanilla ones */
+#define wcscpy_s(a, b, c) wcscpy((a), (c))
+#define wcscat_s(a, b, c) wcscat((a), (c))
+
+#endif /* __MINGW32__ */
+
+static int
+fs__dotordotdot(WCHAR *_tocheck)
+{
+ return _tocheck[0] == '.' &&
+ (_tocheck[1] == '\0' ||
+ (_tocheck[1] == '.' && _tocheck[2] == '\0'));
+}
+
+static int
+fs_rmdir_rmdir(WCHAR *_wpath)
+{
+ unsigned retries = 1;
+
+ while (!RemoveDirectoryW(_wpath)) {
+ /* Only retry when we have retries remaining, and the
+ * error was ERROR_DIR_NOT_EMPTY. */
+ if (retries++ > RM_RETRY_COUNT ||
+ ERROR_DIR_NOT_EMPTY != GetLastError())
+ return -1;
+
+ /* Give whatever has a handle to a child item some time
+ * to release it before trying again */
+ Sleep(RM_RETRY_DELAY * retries * retries);
+ }
+
+ return 0;
+}
+
+static void
+fs_rmdir_helper(WCHAR *_wsource)
+{
+ WCHAR buffer[MAX_PATH];
+ HANDLE find_handle;
+ WIN32_FIND_DATAW find_data;
+ size_t buffer_prefix_len;
+
+ /* Set up the buffer and capture the length */
+ wcscpy_s(buffer, MAX_PATH, _wsource);
+ wcscat_s(buffer, MAX_PATH, L"\\");
+ buffer_prefix_len = wcslen(buffer);
+
+ /* FindFirstFile needs a wildcard to match multiple items */
+ wcscat_s(buffer, MAX_PATH, L"*");
+ find_handle = FindFirstFileW(buffer, &find_data);
+ cl_assert(INVALID_HANDLE_VALUE != find_handle);
+
+ do {
+ /* FindFirstFile/FindNextFile gives back . and ..
+ * entries at the beginning */
+ if (fs__dotordotdot(find_data.cFileName))
+ continue;
+
+ wcscpy_s(buffer + buffer_prefix_len, MAX_PATH - buffer_prefix_len, find_data.cFileName);
+
+ if (FILE_ATTRIBUTE_DIRECTORY & find_data.dwFileAttributes)
+ fs_rmdir_helper(buffer);
+ else {
+ /* If set, the +R bit must be cleared before deleting */
+ if (FILE_ATTRIBUTE_READONLY & find_data.dwFileAttributes)
+ cl_assert(SetFileAttributesW(buffer, find_data.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY));
+
+ cl_assert(DeleteFileW(buffer));
+ }
+ }
+ while (FindNextFileW(find_handle, &find_data));
+
+ /* Ensure that we successfully completed the enumeration */
+ cl_assert(ERROR_NO_MORE_FILES == GetLastError());
+
+ /* Close the find handle */
+ FindClose(find_handle);
+
+ /* Now that the directory is empty, remove it */
+ cl_assert(0 == fs_rmdir_rmdir(_wsource));
+}
+
+static int
+fs_rm_wait(WCHAR *_wpath)
+{
+ unsigned retries = 1;
+ DWORD last_error;
+
+ do {
+ if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(_wpath))
+ last_error = GetLastError();
+ else
+ last_error = ERROR_SUCCESS;
+
+ /* Is the item gone? */
+ if (ERROR_FILE_NOT_FOUND == last_error ||
+ ERROR_PATH_NOT_FOUND == last_error)
+ return 0;
+
+ Sleep(RM_RETRY_DELAY * retries * retries);
+ }
+ while (retries++ <= RM_RETRY_COUNT);
+
+ return -1;
+}
+
+static void
+fs_rm(const char *_source)
+{
+ WCHAR wsource[MAX_PATH];
+ DWORD attrs;
+
+ /* The input path is UTF-8. Convert it to wide characters
+ * for use with the Windows API */
+ cl_assert(MultiByteToWideChar(CP_UTF8,
+ MB_ERR_INVALID_CHARS,
+ _source,
+ -1, /* Indicates NULL termination */
+ wsource,
+ MAX_PATH));
+
+ /* Does the item exist? If not, we have no work to do */
+ attrs = GetFileAttributesW(wsource);
+
+ if (INVALID_FILE_ATTRIBUTES == attrs)
+ return;
+
+ if (FILE_ATTRIBUTE_DIRECTORY & attrs)
+ fs_rmdir_helper(wsource);
+ else {
+ /* The item is a file. Strip the +R bit */
+ if (FILE_ATTRIBUTE_READONLY & attrs)
+ cl_assert(SetFileAttributesW(wsource, attrs & ~FILE_ATTRIBUTE_READONLY));
+
+ cl_assert(DeleteFileW(wsource));
+ }
+
+ /* Wait for the DeleteFile or RemoveDirectory call to complete */
+ cl_assert(0 == fs_rm_wait(wsource));
+}
+
+static void
+fs_copydir_helper(WCHAR *_wsource, WCHAR *_wdest)
+{
+ WCHAR buf_source[MAX_PATH], buf_dest[MAX_PATH];
+ HANDLE find_handle;
+ WIN32_FIND_DATAW find_data;
+ size_t buf_source_prefix_len, buf_dest_prefix_len;
+
+ wcscpy_s(buf_source, MAX_PATH, _wsource);
+ wcscat_s(buf_source, MAX_PATH, L"\\");
+ buf_source_prefix_len = wcslen(buf_source);
+
+ wcscpy_s(buf_dest, MAX_PATH, _wdest);
+ wcscat_s(buf_dest, MAX_PATH, L"\\");
+ buf_dest_prefix_len = wcslen(buf_dest);
+
+ /* Get an enumerator for the items in the source. */
+ wcscat_s(buf_source, MAX_PATH, L"*");
+ find_handle = FindFirstFileW(buf_source, &find_data);
+ cl_assert(INVALID_HANDLE_VALUE != find_handle);
+
+ /* Create the target directory. */
+ cl_assert(CreateDirectoryW(_wdest, NULL));
+
+ do {
+ /* FindFirstFile/FindNextFile gives back . and ..
+ * entries at the beginning */
+ if (fs__dotordotdot(find_data.cFileName))
+ continue;
+
+ wcscpy_s(buf_source + buf_source_prefix_len, MAX_PATH - buf_source_prefix_len, find_data.cFileName);
+ wcscpy_s(buf_dest + buf_dest_prefix_len, MAX_PATH - buf_dest_prefix_len, find_data.cFileName);
+
+ if (FILE_ATTRIBUTE_DIRECTORY & find_data.dwFileAttributes)
+ fs_copydir_helper(buf_source, buf_dest);
+ else
+ cl_assert(CopyFileW(buf_source, buf_dest, TRUE));
+ }
+ while (FindNextFileW(find_handle, &find_data));
+
+ /* Ensure that we successfully completed the enumeration */
+ cl_assert(ERROR_NO_MORE_FILES == GetLastError());
+
+ /* Close the find handle */
+ FindClose(find_handle);
+}
+
+static void
+fs_copy(const char *_source, const char *_dest)
+{
+ WCHAR wsource[MAX_PATH], wdest[MAX_PATH];
+ DWORD source_attrs, dest_attrs;
+ HANDLE find_handle;
+ WIN32_FIND_DATAW find_data;
+
+ /* The input paths are UTF-8. Convert them to wide characters
+ * for use with the Windows API. */
+ cl_assert(MultiByteToWideChar(CP_UTF8,
+ MB_ERR_INVALID_CHARS,
+ _source,
+ -1,
+ wsource,
+ MAX_PATH));
+
+ cl_assert(MultiByteToWideChar(CP_UTF8,
+ MB_ERR_INVALID_CHARS,
+ _dest,
+ -1,
+ wdest,
+ MAX_PATH));
+
+ /* Check the source for existence */
+ source_attrs = GetFileAttributesW(wsource);
+ cl_assert(INVALID_FILE_ATTRIBUTES != source_attrs);
+
+ /* Check the target for existence */
+ dest_attrs = GetFileAttributesW(wdest);
+
+ if (INVALID_FILE_ATTRIBUTES != dest_attrs) {
+ /* Target exists; append last path part of source to target.
+ * Use FindFirstFile to parse the path */
+ find_handle = FindFirstFileW(wsource, &find_data);
+ cl_assert(INVALID_HANDLE_VALUE != find_handle);
+ wcscat_s(wdest, MAX_PATH, L"\\");
+ wcscat_s(wdest, MAX_PATH, find_data.cFileName);
+ FindClose(find_handle);
+
+ /* Check the new target for existence */
+ cl_assert(INVALID_FILE_ATTRIBUTES == GetFileAttributesW(wdest));
+ }
+
+ if (FILE_ATTRIBUTE_DIRECTORY & source_attrs)
+ fs_copydir_helper(wsource, wdest);
+ else
+ cl_assert(CopyFileW(wsource, wdest, TRUE));
+}
+
+void
+cl_fs_cleanup(void)
+{
+ fs_rm(fixture_path(_clar_path, "*"));
+}
+
+#else
+static int
+shell_out(char * const argv[])
+{
+ int status;
+ pid_t pid;
+
+ pid = fork();
+
+ if (pid < 0) {
+ fprintf(stderr,
+ "System error: `fork()` call failed.\n");
+ exit(-1);
+ }
+
+ if (pid == 0) {
+ execv(argv[0], argv);
+ }
+
+ waitpid(pid, &status, 0);
+ return WEXITSTATUS(status);
+}
+
+static void
+fs_copy(const char *_source, const char *dest)
+{
+ char *argv[5];
+ char *source;
+ size_t source_len;
+
+ source = strdup(_source);
+ source_len = strlen(source);
+
+ if (source[source_len - 1] == '/')
+ source[source_len - 1] = 0;
+
+ argv[0] = "/bin/cp";
+ argv[1] = "-R";
+ argv[2] = source;
+ argv[3] = (char *)dest;
+ argv[4] = NULL;
+
+ cl_must_pass_(
+ shell_out(argv),
+ "Failed to copy test fixtures to sandbox"
+ );
+
+ free(source);
+}
+
+static void
+fs_rm(const char *source)
+{
+ char *argv[4];
+
+ argv[0] = "/bin/rm";
+ argv[1] = "-Rf";
+ argv[2] = (char *)source;
+ argv[3] = NULL;
+
+ cl_must_pass_(
+ shell_out(argv),
+ "Failed to cleanup the sandbox"
+ );
+}
+
+void
+cl_fs_cleanup(void)
+{
+ clar_unsandbox();
+ clar_sandbox();
+}
+#endif
diff --git a/tests-clar/clar/print.h b/tests-clar/clar/print.h
new file mode 100644
index 000000000..368016f2f
--- /dev/null
+++ b/tests-clar/clar/print.h
@@ -0,0 +1,60 @@
+
+static void clar_print_init(int test_count, int suite_count, const char *suite_names)
+{
+ (void)test_count;
+ printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
+ printf("Started\n");
+}
+
+static void clar_print_shutdown(int test_count, int suite_count, int error_count)
+{
+ (void)test_count;
+ (void)suite_count;
+ (void)error_count;
+
+ printf("\n\n");
+ clar_report_errors();
+}
+
+static void clar_print_error(int num, const struct clar_error *error)
+{
+ printf(" %d) Failure:\n", num);
+
+ printf("%s::%s [%s:%d]\n",
+ error->suite,
+ error->test,
+ error->file,
+ error->line_number);
+
+ printf(" %s\n", error->error_msg);
+
+ if (error->description != NULL)
+ printf(" %s\n", error->description);
+
+ printf("\n");
+ fflush(stdout);
+}
+
+static void clar_print_ontest(const char *test_name, int test_number, int failed)
+{
+ (void)test_name;
+ (void)test_number;
+ printf("%c", failed ? 'F' : '.');
+ fflush(stdout);
+}
+
+static void clar_print_onsuite(const char *suite_name, int suite_index)
+{
+ if (_clar.report_suite_names)
+ printf("\n%s", suite_name);
+
+ (void)suite_index;
+}
+
+static void clar_print_onabort(const char *msg, ...)
+{
+ va_list argp;
+ va_start(argp, msg);
+ vfprintf(stderr, msg, argp);
+ va_end(argp);
+}
diff --git a/tests-clar/clar/sandbox.h b/tests-clar/clar/sandbox.h
new file mode 100644
index 000000000..bed3011fe
--- /dev/null
+++ b/tests-clar/clar/sandbox.h
@@ -0,0 +1,127 @@
+static char _clar_path[4096];
+
+static int
+is_valid_tmp_path(const char *path)
+{
+ STAT_T st;
+
+ if (stat(path, &st) != 0)
+ return 0;
+
+ if (!S_ISDIR(st.st_mode))
+ return 0;
+
+ return (access(path, W_OK) == 0);
+}
+
+static int
+find_tmp_path(char *buffer, size_t length)
+{
+#ifndef _WIN32
+ static const size_t var_count = 4;
+ static const char *env_vars[] = {
+ "TMPDIR", "TMP", "TEMP", "USERPROFILE"
+ };
+
+ size_t i;
+
+ for (i = 0; i < var_count; ++i) {
+ const char *env = getenv(env_vars[i]);
+ if (!env)
+ continue;
+
+ if (is_valid_tmp_path(env)) {
+ strncpy(buffer, env, length);
+ return 0;
+ }
+ }
+
+ /* If the environment doesn't say anything, try to use /tmp */
+ if (is_valid_tmp_path("/tmp")) {
+ strncpy(buffer, "/tmp", length);
+ return 0;
+ }
+
+#else
+ if (GetTempPath((DWORD)length, buffer))
+ return 0;
+#endif
+
+ /* This system doesn't like us, try to use the current directory */
+ if (is_valid_tmp_path(".")) {
+ strncpy(buffer, ".", length);
+ return 0;
+ }
+
+ return -1;
+}
+
+static void clar_unsandbox(void)
+{
+ if (_clar_path[0] == '\0')
+ return;
+
+#ifdef _WIN32
+ chdir("..");
+#endif
+
+ fs_rm(_clar_path);
+}
+
+static int build_sandbox_path(void)
+{
+ const char path_tail[] = "clar_tmp_XXXXXX";
+ size_t len;
+
+ if (find_tmp_path(_clar_path, sizeof(_clar_path)) < 0)
+ return -1;
+
+ len = strlen(_clar_path);
+
+#ifdef _WIN32
+ { /* normalize path to POSIX forward slashes */
+ size_t i;
+ for (i = 0; i < len; ++i) {
+ if (_clar_path[i] == '\\')
+ _clar_path[i] = '/';
+ }
+ }
+#endif
+
+ if (_clar_path[len - 1] != '/') {
+ _clar_path[len++] = '/';
+ }
+
+ strncpy(_clar_path + len, path_tail, sizeof(_clar_path) - len);
+
+#if defined(__MINGW32__)
+ if (_mktemp(_clar_path) == NULL)
+ return -1;
+
+ if (mkdir(_clar_path, 0700) != 0)
+ return -1;
+#elif defined(_WIN32)
+ if (_mktemp_s(_clar_path, sizeof(_clar_path)) != 0)
+ return -1;
+
+ if (mkdir(_clar_path, 0700) != 0)
+ return -1;
+#else
+ if (mkdtemp(_clar_path) == NULL)
+ return -1;
+#endif
+
+ return 0;
+}
+
+static int clar_sandbox(void)
+{
+ if (_clar_path[0] == '\0' && build_sandbox_path() < 0)
+ return -1;
+
+ if (chdir(_clar_path) != 0)
+ return -1;
+
+ return 0;
+}
+
diff --git a/tests-clar/clar_helpers.c b/tests-clar/clar_helpers.c
deleted file mode 100644
index d180285b8..000000000
--- a/tests-clar/clar_helpers.c
+++ /dev/null
@@ -1,100 +0,0 @@
-#include "clar_libgit2.h"
-#include "posix.h"
-
-void clar_on_init(void)
-{
- git_threads_init();
-}
-
-void clar_on_shutdown(void)
-{
- git_threads_shutdown();
-}
-
-void cl_git_mkfile(const char *filename, const char *content)
-{
- int fd;
-
- fd = p_creat(filename, 0666);
- cl_assert(fd != 0);
-
- if (content) {
- cl_must_pass(p_write(fd, content, strlen(content)));
- } else {
- cl_must_pass(p_write(fd, filename, strlen(filename)));
- cl_must_pass(p_write(fd, "\n", 1));
- }
-
- cl_must_pass(p_close(fd));
-}
-
-void cl_git_write2file(const char *filename, const char *new_content, int flags)
-{
- int fd = p_open(filename, flags, 0644);
- cl_assert(fd >= 0);
- if (!new_content)
- new_content = "\n";
- cl_must_pass(p_write(fd, new_content, strlen(new_content)));
- cl_must_pass(p_close(fd));
-}
-
-void cl_git_append2file(const char *filename, const char *new_content)
-{
- cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_APPEND);
-}
-
-void cl_git_rewritefile(const char *filename, const char *new_content)
-{
- cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_TRUNC);
-}
-
-static const char *_cl_sandbox = NULL;
-static git_repository *_cl_repo = NULL;
-
-git_repository *cl_git_sandbox_init(const char *sandbox)
-{
- /* Copy the whole sandbox folder from our fixtures to our test sandbox
- * area. After this it can be accessed with `./sandbox`
- */
- cl_fixture_sandbox(sandbox);
- _cl_sandbox = sandbox;
-
- cl_git_pass(p_chdir(sandbox));
-
- /* If this is not a bare repo, then rename `sandbox/.gitted` to
- * `sandbox/.git` which must be done since we cannot store a folder
- * named `.git` inside the fixtures folder of our libgit2 repo.
- */
- if (p_access(".gitted", F_OK) == 0)
- cl_git_pass(p_rename(".gitted", ".git"));
-
- /* If we have `gitattributes`, rename to `.gitattributes`. This may
- * be necessary if we don't want the attributes to be applied in the
- * libgit2 repo, but just during testing.
- */
- if (p_access("gitattributes", F_OK) == 0)
- cl_git_pass(p_rename("gitattributes", ".gitattributes"));
-
- /* As with `gitattributes`, we may need `gitignore` just for testing. */
- if (p_access("gitignore", F_OK) == 0)
- cl_git_pass(p_rename("gitignore", ".gitignore"));
-
- cl_git_pass(p_chdir(".."));
-
- /* Now open the sandbox repository and make it available for tests */
- cl_git_pass(git_repository_open(&_cl_repo, sandbox));
-
- return _cl_repo;
-}
-
-void cl_git_sandbox_cleanup(void)
-{
- if (_cl_repo) {
- git_repository_free(_cl_repo);
- _cl_repo = NULL;
- }
- if (_cl_sandbox) {
- cl_fixture_cleanup(_cl_sandbox);
- _cl_sandbox = NULL;
- }
-}
diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c
new file mode 100644
index 000000000..68d17162b
--- /dev/null
+++ b/tests-clar/clar_libgit2.c
@@ -0,0 +1,333 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "path.h"
+
+void cl_git_report_failure(
+ int error, const char *file, int line, const char *fncall)
+{
+ char msg[4096];
+ const git_error *last = giterr_last();
+ p_snprintf(msg, 4096, "error %d - %s",
+ error, last ? last->message : "<no message>");
+ clar__assert(0, file, line, fncall, msg, 1);
+}
+
+void cl_git_mkfile(const char *filename, const char *content)
+{
+ int fd;
+
+ fd = p_creat(filename, 0666);
+ cl_assert(fd != 0);
+
+ if (content) {
+ cl_must_pass(p_write(fd, content, strlen(content)));
+ } else {
+ cl_must_pass(p_write(fd, filename, strlen(filename)));
+ cl_must_pass(p_write(fd, "\n", 1));
+ }
+
+ cl_must_pass(p_close(fd));
+}
+
+void cl_git_write2file(
+ const char *filename, const char *new_content, int flags, unsigned int mode)
+{
+ int fd = p_open(filename, flags, mode);
+ cl_assert(fd >= 0);
+ if (!new_content)
+ new_content = "\n";
+ cl_must_pass(p_write(fd, new_content, strlen(new_content)));
+ cl_must_pass(p_close(fd));
+}
+
+void cl_git_append2file(const char *filename, const char *new_content)
+{
+ cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_APPEND, 0644);
+}
+
+void cl_git_rewritefile(const char *filename, const char *new_content)
+{
+ cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+}
+
+#ifdef GIT_WIN32
+
+#include "win32/utf-conv.h"
+
+char *cl_getenv(const char *name)
+{
+ wchar_t name_utf16[GIT_WIN_PATH];
+ DWORD alloc_len;
+ wchar_t *value_utf16;
+ char *value_utf8;
+
+ git__utf8_to_16(name_utf16, GIT_WIN_PATH, name);
+ alloc_len = GetEnvironmentVariableW(name_utf16, NULL, 0);
+ if (alloc_len <= 0)
+ return NULL;
+
+ alloc_len = GIT_WIN_PATH;
+ cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t)));
+
+ GetEnvironmentVariableW(name_utf16, value_utf16, alloc_len);
+
+ cl_assert(value_utf8 = git__malloc(alloc_len));
+ git__utf16_to_8(value_utf8, value_utf16);
+
+ git__free(value_utf16);
+
+ return value_utf8;
+}
+
+int cl_setenv(const char *name, const char *value)
+{
+ wchar_t name_utf16[GIT_WIN_PATH];
+ wchar_t value_utf16[GIT_WIN_PATH];
+
+ git__utf8_to_16(name_utf16, GIT_WIN_PATH, name);
+
+ if (value) {
+ git__utf8_to_16(value_utf16, GIT_WIN_PATH, value);
+ cl_assert(SetEnvironmentVariableW(name_utf16, value_utf16));
+ } else {
+ /* Windows XP returns 0 (failed) when passing NULL for lpValue when
+ * lpName does not exist in the environment block. This behavior
+ * seems to have changed in later versions. Don't check return value
+ * of SetEnvironmentVariable when passing NULL for lpValue.
+ */
+ SetEnvironmentVariableW(name_utf16, NULL);
+ }
+
+ return 0;
+}
+
+/* This function performs retries on calls to MoveFile in order
+ * to provide enhanced reliability in the face of antivirus
+ * agents that may be scanning the source (or in the case that
+ * the source is a directory, a child of the source). */
+int cl_rename(const char *source, const char *dest)
+{
+ wchar_t source_utf16[GIT_WIN_PATH];
+ wchar_t dest_utf16[GIT_WIN_PATH];
+ unsigned retries = 1;
+
+ git__utf8_to_16(source_utf16, GIT_WIN_PATH, source);
+ git__utf8_to_16(dest_utf16, GIT_WIN_PATH, dest);
+
+ while (!MoveFileW(source_utf16, dest_utf16)) {
+ /* Only retry if the error is ERROR_ACCESS_DENIED;
+ * this may indicate that an antivirus agent is
+ * preventing the rename from source to target */
+ if (retries > 5 ||
+ ERROR_ACCESS_DENIED != GetLastError())
+ return -1;
+
+ /* With 5 retries and a coefficient of 10ms, the maximum
+ * delay here is 550 ms */
+ Sleep(10 * retries * retries);
+ retries++;
+ }
+
+ return 0;
+}
+
+#else
+
+#include <stdlib.h>
+char *cl_getenv(const char *name)
+{
+ return getenv(name);
+}
+
+int cl_setenv(const char *name, const char *value)
+{
+ return (value == NULL) ? unsetenv(name) : setenv(name, value, 1);
+}
+
+int cl_rename(const char *source, const char *dest)
+{
+ return p_rename(source, dest);
+}
+
+#endif
+
+static const char *_cl_sandbox = NULL;
+static git_repository *_cl_repo = NULL;
+
+git_repository *cl_git_sandbox_init(const char *sandbox)
+{
+ /* Copy the whole sandbox folder from our fixtures to our test sandbox
+ * area. After this it can be accessed with `./sandbox`
+ */
+ cl_fixture_sandbox(sandbox);
+ _cl_sandbox = sandbox;
+
+ cl_git_pass(p_chdir(sandbox));
+
+ /* If this is not a bare repo, then rename `sandbox/.gitted` to
+ * `sandbox/.git` which must be done since we cannot store a folder
+ * named `.git` inside the fixtures folder of our libgit2 repo.
+ */
+ if (p_access(".gitted", F_OK) == 0)
+ cl_git_pass(cl_rename(".gitted", ".git"));
+
+ /* If we have `gitattributes`, rename to `.gitattributes`. This may
+ * be necessary if we don't want the attributes to be applied in the
+ * libgit2 repo, but just during testing.
+ */
+ if (p_access("gitattributes", F_OK) == 0)
+ cl_git_pass(cl_rename("gitattributes", ".gitattributes"));
+
+ /* As with `gitattributes`, we may need `gitignore` just for testing. */
+ if (p_access("gitignore", F_OK) == 0)
+ cl_git_pass(cl_rename("gitignore", ".gitignore"));
+
+ cl_git_pass(p_chdir(".."));
+
+ /* Now open the sandbox repository and make it available for tests */
+ cl_git_pass(git_repository_open(&_cl_repo, sandbox));
+
+ return _cl_repo;
+}
+
+void cl_git_sandbox_cleanup(void)
+{
+ if (_cl_repo) {
+ git_repository_free(_cl_repo);
+ _cl_repo = NULL;
+ }
+ if (_cl_sandbox) {
+ cl_fixture_cleanup(_cl_sandbox);
+ _cl_sandbox = NULL;
+ }
+}
+
+bool cl_toggle_filemode(const char *filename)
+{
+ struct stat st1, st2;
+
+ cl_must_pass(p_stat(filename, &st1));
+ cl_must_pass(p_chmod(filename, st1.st_mode ^ 0100));
+ cl_must_pass(p_stat(filename, &st2));
+
+ return (st1.st_mode != st2.st_mode);
+}
+
+bool cl_is_chmod_supported(void)
+{
+ static int _is_supported = -1;
+
+ if (_is_supported < 0) {
+ cl_git_mkfile("filemode.t", "Test if filemode can be modified");
+ _is_supported = cl_toggle_filemode("filemode.t");
+ cl_must_pass(p_unlink("filemode.t"));
+ }
+
+ return _is_supported;
+}
+
+const char* cl_git_fixture_url(const char *fixturename)
+{
+ return cl_git_path_url(cl_fixture(fixturename));
+}
+
+const char* cl_git_path_url(const char *path)
+{
+ static char url[4096];
+
+ const char *in_buf;
+ git_buf path_buf = GIT_BUF_INIT;
+ git_buf url_buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_path_prettify_dir(&path_buf, path, NULL));
+ cl_git_pass(git_buf_puts(&url_buf, "file://"));
+
+#ifdef GIT_WIN32
+ /*
+ * A FILE uri matches the following format: file://[host]/path
+ * where "host" can be empty and "path" is an absolute path to the resource.
+ *
+ * In this test, no hostname is used, but we have to ensure the leading triple slashes:
+ *
+ * *nix: file:///usr/home/...
+ * Windows: file:///C:/Users/...
+ */
+ cl_git_pass(git_buf_putc(&url_buf, '/'));
+#endif
+
+ in_buf = git_buf_cstr(&path_buf);
+
+ /*
+ * A very hacky Url encoding that only takes care of escaping the spaces
+ */
+ while (*in_buf) {
+ if (*in_buf == ' ')
+ cl_git_pass(git_buf_puts(&url_buf, "%20"));
+ else
+ cl_git_pass(git_buf_putc(&url_buf, *in_buf));
+
+ in_buf++;
+ }
+
+ strncpy(url, git_buf_cstr(&url_buf), 4096);
+ git_buf_free(&url_buf);
+ git_buf_free(&path_buf);
+ return url;
+}
+
+typedef struct {
+ const char *filename;
+ size_t filename_len;
+} remove_data;
+
+static int remove_placeholders_recurs(void *_data, git_buf *path)
+{
+ remove_data *data = (remove_data *)_data;
+ size_t pathlen;
+
+ if (git_path_isdir(path->ptr) == true)
+ return git_path_direach(path, remove_placeholders_recurs, data);
+
+ pathlen = path->size;
+
+ if (pathlen < data->filename_len)
+ return 0;
+
+ /* if path ends in '/'+filename (or equals filename) */
+ if (!strcmp(data->filename, path->ptr + pathlen - data->filename_len) &&
+ (pathlen == data->filename_len ||
+ path->ptr[pathlen - data->filename_len - 1] == '/'))
+ return p_unlink(path->ptr);
+
+ return 0;
+}
+
+int cl_git_remove_placeholders(const char *directory_path, const char *filename)
+{
+ int error;
+ remove_data data;
+ git_buf buffer = GIT_BUF_INIT;
+
+ if (git_path_isdir(directory_path) == false)
+ return -1;
+
+ if (git_buf_sets(&buffer, directory_path) < 0)
+ return -1;
+
+ data.filename = filename;
+ data.filename_len = strlen(filename);
+
+ error = remove_placeholders_recurs(&data, &buffer);
+
+ git_buf_free(&buffer);
+
+ return error;
+}
+
+void cl_repo_set_bool(git_repository *repo, const char *cfg, int value)
+{
+ git_config *config;
+ cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_config_set_bool(config, cfg, value != 0));
+ git_config_free(config);
+}
diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h
index d250494f5..93909d8a5 100644
--- a/tests-clar/clar_libgit2.h
+++ b/tests-clar/clar_libgit2.h
@@ -6,17 +6,17 @@
#include "common.h"
/**
- * Special wrapper for `clar_must_pass` that passes
- * the last library error as the test failure message.
+ * Replace for `clar_must_pass` that passes the last library error as the
+ * test failure message.
*
- * Use this wrapper around all `git_` library calls that
- * return error codes!
+ * Use this wrapper around all `git_` library calls that return error codes!
*/
#define cl_git_pass(expr) do { \
+ int _lg2_error; \
giterr_clear(); \
- if ((expr) != 0) \
- clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, giterr_last() ? giterr_last()->message : NULL, 1); \
- } while(0)
+ if ((_lg2_error = (expr)) != 0) \
+ cl_git_report_failure(_lg2_error, __FILE__, __LINE__, "Function call failed: " #expr); \
+ } while (0)
/**
* Wrapper for `clar_must_fail` -- this one is
@@ -25,6 +25,12 @@
*/
#define cl_git_fail(expr) cl_must_fail(expr)
+#define cl_git_fail_with(expr, error) cl_assert_equal_i(error,expr)
+
+void cl_git_report_failure(int, const char *, int, const char *);
+
+#define cl_assert_equal_sz(sz1,sz2) cl_assert_equal_i((int)sz1, (int)(sz2))
+
/*
* Some utility macros for building long strings
*/
@@ -38,11 +44,31 @@
void cl_git_mkfile(const char *filename, const char *content);
void cl_git_append2file(const char *filename, const char *new_content);
void cl_git_rewritefile(const char *filename, const char *new_content);
-void cl_git_write2file(const char *filename, const char *new_content, int mode);
+void cl_git_write2file(const char *filename, const char *new_content, int flags, unsigned int mode);
+
+bool cl_toggle_filemode(const char *filename);
+bool cl_is_chmod_supported(void);
+
+/* Environment wrappers */
+char *cl_getenv(const char *name);
+int cl_setenv(const char *name, const char *value);
+
+/* Reliable rename */
+int cl_rename(const char *source, const char *dest);
/* Git sandbox setup helpers */
git_repository *cl_git_sandbox_init(const char *sandbox);
void cl_git_sandbox_cleanup(void);
+/* Local-repo url helpers */
+const char* cl_git_fixture_url(const char *fixturename);
+const char* cl_git_path_url(const char *path);
+
+/* Test repository cleaner */
+int cl_git_remove_placeholders(const char *directory_path, const char *filename);
+
+/* config setting helpers */
+void cl_repo_set_bool(git_repository *repo, const char *cfg, int value);
+
#endif
diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c
new file mode 100644
index 000000000..f190523b6
--- /dev/null
+++ b/tests-clar/clone/empty.c
@@ -0,0 +1,83 @@
+#include "clar_libgit2.h"
+
+#include "git2/clone.h"
+#include "repository.h"
+
+static git_clone_options g_options;
+static git_repository *g_repo;
+static git_repository *g_repo_cloned;
+
+void test_clone_empty__initialize(void)
+{
+ git_repository *sandbox = cl_git_sandbox_init("empty_bare.git");
+ cl_git_remove_placeholders(git_repository_path(sandbox), "dummy-marker.txt");
+
+ g_repo = NULL;
+
+ memset(&g_options, 0, sizeof(git_clone_options));
+ g_options.version = GIT_CLONE_OPTIONS_VERSION;
+}
+
+void test_clone_empty__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static void cleanup_repository(void *path)
+{
+ cl_fixture_cleanup((const char *)path);
+
+ git_repository_free(g_repo_cloned);
+ g_repo_cloned = NULL;
+}
+
+void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
+{
+ char *local_name = "refs/heads/master";
+ const char *expected_tracked_branch_name = "refs/remotes/origin/master";
+ const char *expected_remote_name = "origin";
+ char buffer[1024];
+ git_reference *ref;
+
+ cl_set_cleanup(&cleanup_repository, "./empty");
+
+ g_options.bare = true;
+ cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options));
+
+ /* Although the HEAD is orphaned... */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name));
+
+ /* ...one can still retrieve the name of the remote tracking reference */
+ cl_assert_equal_i((int)strlen(expected_tracked_branch_name) + 1,
+ git_branch_upstream_name(buffer, 1024, g_repo_cloned, local_name));
+
+ cl_assert_equal_s(expected_tracked_branch_name, buffer);
+
+ /* ...and the name of the remote... */
+ cl_assert_equal_i((int)strlen(expected_remote_name) + 1,
+ git_branch_remote_name(buffer, 1024, g_repo_cloned, expected_tracked_branch_name));
+
+ cl_assert_equal_s(expected_remote_name, buffer);
+
+ /* ...even when the remote HEAD is orphaned as well */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned,
+ expected_tracked_branch_name));
+}
+
+void test_clone_empty__can_clone_an_empty_local_repo(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./empty");
+
+ cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options));
+}
+
+void test_clone_empty__can_clone_an_empty_standard_repo(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt");
+
+ cl_set_cleanup(&cleanup_repository, "./empty");
+
+ cl_git_pass(git_clone(&g_repo_cloned, "./empty_standard_repo", "./empty", &g_options));
+}
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
new file mode 100644
index 000000000..c4b482234
--- /dev/null
+++ b/tests-clar/clone/nonetwork.c
@@ -0,0 +1,238 @@
+#include "clar_libgit2.h"
+
+#include "git2/clone.h"
+#include "repository.h"
+
+#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
+
+static git_clone_options g_options;
+static git_repository *g_repo;
+static git_reference* g_ref;
+static git_remote* g_remote;
+
+void test_clone_nonetwork__initialize(void)
+{
+ git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
+
+ g_repo = NULL;
+
+ memset(&g_options, 0, sizeof(git_clone_options));
+ g_options.version = GIT_CLONE_OPTIONS_VERSION;
+ g_options.checkout_opts = dummy_opts;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+}
+
+void test_clone_nonetwork__cleanup(void)
+{
+ if (g_repo) {
+ git_repository_free(g_repo);
+ g_repo = NULL;
+ }
+
+ if (g_ref) {
+ git_reference_free(g_ref);
+ g_ref = NULL;
+ }
+
+ if (g_remote) {
+ git_remote_free(g_remote);
+ g_remote = NULL;
+ }
+
+ cl_fixture_cleanup("./foo");
+}
+
+void test_clone_nonetwork__bad_url(void)
+{
+ /* Clone should clean up the mess if the URL isn't a git repository */
+ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
+ cl_assert(!git_path_exists("./foo"));
+ g_options.bare = true;
+ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
+ cl_assert(!git_path_exists("./foo"));
+}
+
+static int dont_call_me(void *state, git_buf *path)
+{
+ GIT_UNUSED(state);
+ GIT_UNUSED(path);
+ return GIT_ERROR;
+}
+
+void test_clone_nonetwork__do_not_clean_existing_directory(void)
+{
+ git_buf path_buf = GIT_BUF_INIT;
+
+ git_buf_put(&path_buf, "./foo", 5);
+
+ /* Clone should not remove the directory if it already exists, but
+ * Should clean up entries it creates. */
+ p_mkdir("./foo", GIT_DIR_MODE);
+ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
+ cl_assert(git_path_exists("./foo"));
+
+ /* Make sure the directory is empty. */
+ cl_git_pass(git_path_direach(&path_buf,
+ dont_call_me,
+ NULL));
+
+ /* Try again with a bare repository. */
+ g_options.bare = true;
+ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
+ cl_assert(git_path_exists("./foo"));
+
+ /* Make sure the directory is empty. */
+ cl_git_pass(git_path_direach(&path_buf,
+ dont_call_me,
+ NULL));
+
+ git_buf_free(&path_buf);
+}
+
+void test_clone_nonetwork__local(void)
+{
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__local_absolute_path(void)
+{
+ const char *local_src;
+ local_src = cl_fixture("testrepo.git");
+ cl_git_pass(git_clone(&g_repo, local_src, "./foo", &g_options));
+}
+
+void test_clone_nonetwork__local_bare(void)
+{
+ g_options.bare = true;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__fail_when_the_target_is_a_file(void)
+{
+ cl_git_mkfile("./foo", "Bar!");
+ cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(void)
+{
+ p_mkdir("./foo", GIT_DIR_MODE);
+ cl_git_mkfile("./foo/bar", "Baz!");
+ cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__custom_origin_name(void)
+{
+ g_options.remote_name = "my_origin";
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin"));
+}
+
+void test_clone_nonetwork__custom_push_url(void)
+{
+ const char *url = "http://example.com";
+
+ g_options.pushurl = url;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
+ cl_assert_equal_s(url, git_remote_pushurl(g_remote));
+}
+
+void test_clone_nonetwork__custom_fetch_spec(void)
+{
+ const git_refspec *actual_fs;
+ const char *spec = "+refs/heads/master:refs/heads/foo";
+
+ g_options.fetch_spec = spec;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
+ actual_fs = git_remote_fetchspec(g_remote);
+ cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
+ cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));
+
+ cl_git_pass(git_reference_lookup(&g_ref, g_repo, "refs/heads/foo"));
+}
+
+void test_clone_nonetwork__custom_push_spec(void)
+{
+ const git_refspec *actual_fs;
+ const char *spec = "+refs/heads/master:refs/heads/foo";
+
+ g_options.push_spec = spec;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
+ actual_fs = git_remote_pushspec(g_remote);
+ cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
+ cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));
+}
+
+void test_clone_nonetwork__custom_autotag(void)
+{
+ git_strarray tags = {0};
+
+ g_options.remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_NONE;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_tag_list(&tags, g_repo));
+ cl_assert_equal_sz(0, tags.count);
+
+ git_strarray_free(&tags);
+}
+
+void test_clone_nonetwork__cope_with_already_existing_directory(void)
+{
+ p_mkdir("./foo", GIT_DIR_MODE);
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ g_options.checkout_opts.checkout_strategy = 0;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
+ cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&path)));
+
+ git_buf_free(&path);
+}
+
+void test_clone_nonetwork__can_checkout_given_branch(void)
+{
+ g_options.checkout_branch = "test";
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_assert_equal_i(0, git_repository_head_orphan(g_repo));
+
+ cl_git_pass(git_repository_head(&g_ref, g_repo));
+ cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test");
+}
+
+void test_clone_nonetwork__can_detached_head(void)
+{
+ git_object *obj;
+ git_repository *cloned;
+ git_reference *cloned_head;
+
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_revparse_single(&obj, g_repo, "master~1"));
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(obj)));
+
+ cl_git_pass(git_clone(&cloned, "./foo", "./foo1", &g_options));
+
+ cl_assert(git_repository_head_detached(cloned));
+
+ cl_git_pass(git_repository_head(&cloned_head, cloned));
+ cl_assert(!git_oid_cmp(git_object_id(obj), git_reference_target(cloned_head)));
+
+ git_object_free(obj);
+ git_reference_free(cloned_head);
+ git_repository_free(cloned);
+
+ cl_fixture_cleanup("./foo1");
+}
diff --git a/tests-clar/commit/commit.c b/tests-clar/commit/commit.c
index 1205e5285..8f071ff94 100644
--- a/tests-clar/commit/commit.c
+++ b/tests-clar/commit/commit.c
@@ -11,6 +11,8 @@ void test_commit_commit__initialize(void)
void test_commit_commit__cleanup(void)
{
git_repository_free(_repo);
+ _repo = NULL;
+
cl_fixture_cleanup("testrepo.git");
}
@@ -35,7 +37,7 @@ void test_commit_commit__create_unexisting_update_ref(void)
NULL, "some msg", tree, 1, (const git_commit **) &commit));
cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
- cl_assert(!git_oid_cmp(&oid, git_reference_oid(ref)));
+ cl_assert(!git_oid_cmp(&oid, git_reference_target(ref)));
git_tree_free(tree);
git_commit_free(commit);
diff --git a/tests-clar/commit/parent.c b/tests-clar/commit/parent.c
new file mode 100644
index 000000000..18ce0bba6
--- /dev/null
+++ b/tests-clar/commit/parent.c
@@ -0,0 +1,60 @@
+#include "clar_libgit2.h"
+
+static git_repository *_repo;
+static git_commit *commit;
+
+void test_commit_parent__initialize(void)
+{
+ git_oid oid;
+
+ cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+
+ git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
+}
+
+void test_commit_parent__cleanup(void)
+{
+ git_commit_free(commit);
+ commit = NULL;
+
+ git_repository_free(_repo);
+ _repo = NULL;
+}
+
+static void assert_nth_gen_parent(unsigned int gen, const char *expected_oid)
+{
+ git_commit *parent = NULL;
+ int error;
+
+ error = git_commit_nth_gen_ancestor(&parent, commit, gen);
+
+ if (expected_oid != NULL) {
+ cl_assert_equal_i(0, error);
+ cl_assert_equal_i(0, git_oid_streq(git_commit_id(parent), expected_oid));
+ } else
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+
+ git_commit_free(parent);
+}
+
+/*
+ * $ git show be35~0
+ * commit be3563ae3f795b2b4353bcce3a527ad0a4f7f644
+ *
+ * $ git show be35~1
+ * commit 9fd738e8f7967c078dceed8190330fc8648ee56a
+ *
+ * $ git show be35~3
+ * commit 5b5b025afb0b4c913b4c338a42934a3863bf3644
+ *
+ * $ git show be35~42
+ * fatal: ambiguous argument 'be35~42': unknown revision or path not in the working tree.
+ */
+void test_commit_parent__can_retrieve_nth_generation_parent(void)
+{
+ assert_nth_gen_parent(0, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ assert_nth_gen_parent(1, "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ assert_nth_gen_parent(3, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ assert_nth_gen_parent(42, NULL);
+}
diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c
index bbb502cb5..b99d27991 100644
--- a/tests-clar/commit/parse.c
+++ b/tests-clar/commit/parse.c
@@ -108,19 +108,20 @@ passing_signature_test_case passing_signature_cases[] = {
// Parse an obviously invalid signature
{"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
// Parse an obviously invalid signature
- {"committer foo<@bar>123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
+ {"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
// Parse an obviously invalid signature
{"committer <>\n", "committer ", "", "", 0, 0},
- {"committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
- {"committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
- {"author Vicent Marti <tanoku@gmail.com> notime \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
- {"author Vicent Marti <tanoku@gmail.com> 123456 notimezone \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
- {"author Vicent Marti <tanoku@gmail.com> notime +0100\n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
+ {"committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0},
+ {"committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0},
{"author Vicent Marti <tanoku@gmail.com>\n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
- {"author A U Thor <author@example.com>, C O. Miter <comiter@example.com> 1234567890 -0700\n", "author ", "A U Thor", "author@example.com", 1234567890, -420},
- {"author A U Thor <author@example.com> and others 1234567890 -0700\n", "author ", "A U Thor", "author@example.com", 1234567890, -420},
- {"author A U Thor <author@example.com> and others 1234567890\n", "author ", "A U Thor", "author@example.com", 1234567890, 0},
- {"author A U Thor> <author@example.com> and others 1234567890\n", "author ", "A U Thor>", "author@example.com", 1234567890, 0},
+ /* a variety of dates */
+ {"author Vicent Marti <tanoku@gmail.com> 0 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
+ {"author Vicent Marti <tanoku@gmail.com> 1234567890 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 1234567890, 0},
+ {"author Vicent Marti <tanoku@gmail.com> 2147483647 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0x7fffffff, 0},
+ {"author Vicent Marti <tanoku@gmail.com> 4294967295 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0xffffffff, 0},
+ {"author Vicent Marti <tanoku@gmail.com> 4294967296 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 4294967296, 0},
+ {"author Vicent Marti <tanoku@gmail.com> 8589934592 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 8589934592, 0},
+
{NULL,NULL,NULL,NULL,0,0}
};
@@ -137,7 +138,7 @@ failing_signature_test_case failing_signature_cases[] = {
{"author Vicent Marti <broken@email 12345 \n", "author "},
{"committer Vicent Marti ><\n", "committer "},
{"author ", "author "},
- {NULL,NULL,}
+ {NULL, NULL,}
};
void test_commit_parse__signature(void)
@@ -149,12 +150,13 @@ void test_commit_parse__signature(void)
{
const char *str = passcase->string;
size_t len = strlen(passcase->string);
- struct git_signature person = {NULL, NULL, {0, 0}};
+ struct git_signature person = {0};
+
cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n'));
- cl_assert(strcmp(passcase->name, person.name) == 0);
- cl_assert(strcmp(passcase->email, person.email) == 0);
- cl_assert(passcase->time == person.when.time);
- cl_assert(passcase->offset == person.when.offset);
+ cl_assert_equal_s(passcase->name, person.name);
+ cl_assert_equal_s(passcase->email, person.email);
+ cl_assert_equal_i((int)passcase->time, (int)person.when.time);
+ cl_assert_equal_i(passcase->offset, person.when.offset);
git__free(person.name); git__free(person.email);
}
@@ -162,7 +164,7 @@ void test_commit_parse__signature(void)
{
const char *str = failcase->string;
size_t len = strlen(failcase->string);
- git_signature person = {NULL, NULL, {0, 0}};
+ git_signature person = {0};
cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n'));
git__free(person.name); git__free(person.email);
}
@@ -236,6 +238,30 @@ author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
\n\
a simple commit which works\n",
+/* simple commit with GPG signature */
+"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\
+parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
+author Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\
+committer Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\
+gpgsig -----BEGIN PGP SIGNATURE-----\n\
+ Version: GnuPG v1.4.12 (Darwin)\n\
+ \n\
+ iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
+ o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
+ JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
+ AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
+ SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
+ who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
+ 6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
+ cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
+ c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
+ ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
+ 7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
+ cpxtDQQMGYFpXK/71stq\n\
+ =ozeK\n\
+ -----END PGP SIGNATURE-----\n\
+\n\
+a simple commit which works\n",
};
void test_commit_parse__entire_commit(void)
@@ -251,10 +277,8 @@ void test_commit_parse__entire_commit(void)
commit->object.repo = g_repo;
cl_git_fail(git_commit__parse_buffer(
- commit,
- failing_commit_cases[i],
- strlen(failing_commit_cases[i]))
- );
+ commit, failing_commit_cases[i], strlen(failing_commit_cases[i]))
+ );
git_commit__free(commit);
}
@@ -272,17 +296,11 @@ void test_commit_parse__entire_commit(void)
strlen(passing_commit_cases[i]))
);
- git_commit__free(commit);
-
- commit = (git_commit*)git__malloc(sizeof(git_commit));
- memset(commit, 0x0, sizeof(git_commit));
- commit->object.repo = g_repo;
-
- cl_git_pass(git_commit__parse_buffer(
- commit,
- passing_commit_cases[i],
- strlen(passing_commit_cases[i]))
- );
+ if (!i)
+ cl_assert_equal_s("", git_commit_message(commit));
+ else
+ cl_assert(git__prefixcmp(
+ git_commit_message(commit), "a simple commit which works") == 0);
git_commit__free(commit);
}
@@ -323,10 +341,10 @@ void test_commit_parse__details0(void) {
commit_time = git_commit_time(commit);
parents = git_commit_parentcount(commit);
- cl_assert(strcmp(author->name, "Scott Chacon") == 0);
- cl_assert(strcmp(author->email, "schacon@gmail.com") == 0);
- cl_assert(strcmp(committer->name, "Scott Chacon") == 0);
- cl_assert(strcmp(committer->email, "schacon@gmail.com") == 0);
+ cl_assert_equal_s("Scott Chacon", author->name);
+ cl_assert_equal_s("schacon@gmail.com", author->email);
+ cl_assert_equal_s("Scott Chacon", committer->name);
+ cl_assert_equal_s("schacon@gmail.com", committer->email);
cl_assert(message != NULL);
cl_assert(strchr(message, '\n') != NULL);
cl_assert(commit_time > 0);
@@ -348,3 +366,30 @@ void test_commit_parse__details0(void) {
}
}
+void test_commit_parse__leading_lf(void)
+{
+ git_commit *commit;
+ const char *buffer =
+"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
+parent e90810b8df3e80c413d903f631643c716887138d\n\
+author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
+committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
+\n\
+\n\
+\n\
+This commit has a few LF at the start of the commit message";
+ const char *message =
+"\n\
+\n\
+This commit has a few LF at the start of the commit message";
+
+ commit = (git_commit*)git__malloc(sizeof(git_commit));
+ memset(commit, 0x0, sizeof(git_commit));
+ commit->object.repo = g_repo;
+
+ cl_git_pass(git_commit__parse_buffer(commit, buffer, strlen(buffer)));
+
+ cl_assert_equal_s(message, git_commit_message(commit));
+
+ git_commit__free(commit);
+}
diff --git a/tests-clar/commit/signature.c b/tests-clar/commit/signature.c
index 290b11fa3..9364efb10 100644
--- a/tests-clar/commit/signature.c
+++ b/tests-clar/commit/signature.c
@@ -13,17 +13,39 @@ static int try_build_signature(const char *name, const char *email, git_time_t t
return error;
}
+static void assert_name_and_email(
+ const char *expected_name,
+ const char *expected_email,
+ const char *name,
+ const char *email)
+{
+ git_signature *sign;
+
+ cl_git_pass(git_signature_new(&sign, name, email, 1234567890, 60));
+ cl_assert_equal_s(expected_name, sign->name);
+ cl_assert_equal_s(expected_email, sign->email);
+
+ git_signature_free(sign);
+}
-void test_commit_signature__create_trim(void)
+void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void)
{
- // creating a signature trims leading and trailing spaces
- git_signature *sign;
- cl_git_pass(git_signature_new(&sign, " nulltoken ", " emeric.fermas@gmail.com ", 1234567890, 60));
- cl_assert(strcmp(sign->name, "nulltoken") == 0);
- cl_assert(strcmp(sign->email, "emeric.fermas@gmail.com") == 0);
- git_signature_free((git_signature *)sign);
+ assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " nulltoken ", " emeric.fermas@gmail.com ");
}
+void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
+{
+ cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));
+ cl_git_fail(try_build_signature("Phil>Haack", "phil@haack", 1234567890, 60));
+ cl_git_fail(try_build_signature("<Phil Haack>", "phil@haack", 1234567890, 60));
+}
+
+void test_commit_signature__angle_brackets_in_email_are_not_supported(void)
+{
+ cl_git_fail(try_build_signature("Phil Haack", ">phil@haack", 1234567890, 60));
+ cl_git_fail(try_build_signature("Phil Haack", "phil@>haack", 1234567890, 60));
+ cl_git_fail(try_build_signature("Phil Haack", "<phil@haack>", 1234567890, 60));
+}
void test_commit_signature__create_empties(void)
{
@@ -39,21 +61,13 @@ void test_commit_signature__create_empties(void)
void test_commit_signature__create_one_char(void)
{
// creating a one character signature
- git_signature *sign;
- cl_git_pass(git_signature_new(&sign, "x", "foo@bar.baz", 1234567890, 60));
- cl_assert(strcmp(sign->name, "x") == 0);
- cl_assert(strcmp(sign->email, "foo@bar.baz") == 0);
- git_signature_free((git_signature *)sign);
+ assert_name_and_email("x", "foo@bar.baz", "x", "foo@bar.baz");
}
void test_commit_signature__create_two_char(void)
{
// creating a two character signature
- git_signature *sign;
- cl_git_pass(git_signature_new(&sign, "xx", "x@y.z", 1234567890, 60));
- cl_assert(strcmp(sign->name, "xx") == 0);
- cl_assert(strcmp(sign->email, "x@y.z") == 0);
- git_signature_free((git_signature *)sign);
+ assert_name_and_email("xx", "foo@bar.baz", "xx", "foo@bar.baz");
}
void test_commit_signature__create_zero_char(void)
diff --git a/tests-clar/commit/write.c b/tests-clar/commit/write.c
index 9c4d077a6..e9946af89 100644
--- a/tests-clar/commit/write.c
+++ b/tests-clar/commit/write.c
@@ -17,16 +17,22 @@ void test_commit_write__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
+
void test_commit_write__cleanup(void)
{
- git_reference_free(head);
- git_reference_free(branch);
+ git_reference_free(head);
+ head = NULL;
+
+ git_reference_free(branch);
+ branch = NULL;
- git_commit_free(commit);
+ git_commit_free(commit);
+ commit = NULL;
- git__free(head_old);
+ git__free(head_old);
+ head_old = NULL;
- cl_git_sandbox_cleanup();
+ cl_git_sandbox_cleanup();
}
@@ -72,19 +78,19 @@ void test_commit_write__from_memory(void)
/* Check attributes were set correctly */
author1 = git_commit_author(commit);
cl_assert(author1 != NULL);
- cl_assert(strcmp(author1->name, committer_name) == 0);
- cl_assert(strcmp(author1->email, committer_email) == 0);
+ cl_assert_equal_s(committer_name, author1->name);
+ cl_assert_equal_s(committer_email, author1->email);
cl_assert(author1->when.time == 987654321);
cl_assert(author1->when.offset == 90);
committer1 = git_commit_committer(commit);
cl_assert(committer1 != NULL);
- cl_assert(strcmp(committer1->name, committer_name) == 0);
- cl_assert(strcmp(committer1->email, committer_email) == 0);
+ cl_assert_equal_s(committer_name, committer1->name);
+ cl_assert_equal_s(committer_email, committer1->email);
cl_assert(committer1->when.time == 123456789);
cl_assert(committer1->when.offset == 60);
- cl_assert(strcmp(git_commit_message(commit), commit_message) == 0);
+ cl_assert_equal_s(commit_message, git_commit_message(commit));
}
// create a root commit
@@ -106,10 +112,11 @@ void test_commit_write__root(void)
/* First we need to update HEAD so it points to our non-existant branch */
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC);
- head_old = git__strdup(git_reference_target(head));
+ head_old = git__strdup(git_reference_symbolic_target(head));
cl_assert(head_old != NULL);
-
- cl_git_pass(git_reference_set_target(head, branch_name));
+ git_reference_free(head);
+
+ cl_git_pass(git_reference_symbolic_create(&head, g_repo, "HEAD", branch_name, 1));
cl_git_pass(git_commit_create_v(
&commit_id, /* out id */
@@ -134,7 +141,7 @@ void test_commit_write__root(void)
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
cl_assert(git_commit_parentcount(commit) == 0);
cl_git_pass(git_reference_lookup(&branch, g_repo, branch_name));
- branch_oid = git_reference_oid(branch);
+ branch_oid = git_reference_target(branch);
cl_git_pass(git_oid_cmp(branch_oid, &commit_id));
- cl_assert(!strcmp(git_commit_message(commit), root_commit_message));
+ cl_assert_equal_s(root_commit_message, git_commit_message(commit));
}
diff --git a/tests-clar/config/add.c b/tests-clar/config/add.c
index 9854fbb39..405f1e2c9 100644
--- a/tests-clar/config/add.c
+++ b/tests-clar/config/add.c
@@ -19,7 +19,7 @@ void test_config_add__to_existing_section(void)
cl_git_pass(git_config_set_int32(cfg, "empty.tmp", 5));
cl_git_pass(git_config_get_int32(&i, cfg, "empty.tmp"));
cl_assert(i == 5);
- cl_git_pass(git_config_delete(cfg, "empty.tmp"));
+ cl_git_pass(git_config_delete_entry(cfg, "empty.tmp"));
git_config_free(cfg);
}
@@ -32,6 +32,6 @@ void test_config_add__to_new_section(void)
cl_git_pass(git_config_set_int32(cfg, "section.tmp", 5));
cl_git_pass(git_config_get_int32(&i, cfg, "section.tmp"));
cl_assert(i == 5);
- cl_git_pass(git_config_delete(cfg, "section.tmp"));
+ cl_git_pass(git_config_delete_entry(cfg, "section.tmp"));
git_config_free(cfg);
}
diff --git a/tests-clar/config/backend.c b/tests-clar/config/backend.c
new file mode 100644
index 000000000..28502a8ba
--- /dev/null
+++ b/tests-clar/config/backend.c
@@ -0,0 +1,23 @@
+#include "clar_libgit2.h"
+
+void test_config_backend__checks_version(void)
+{
+ git_config *cfg;
+ git_config_backend backend = GIT_CONFIG_BACKEND_INIT;
+ const git_error *err;
+
+ backend.version = 1024;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_fail(git_config_add_backend(cfg, &backend, 0, false));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ giterr_clear();
+ backend.version = 1024;
+ cl_git_fail(git_config_add_backend(cfg, &backend, 0, false));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ git_config_free(cfg);
+}
diff --git a/tests-clar/config/config_helpers.c b/tests-clar/config/config_helpers.c
new file mode 100644
index 000000000..53bd945a0
--- /dev/null
+++ b/tests-clar/config/config_helpers.c
@@ -0,0 +1,37 @@
+#include "clar_libgit2.h"
+#include "config_helpers.h"
+#include "repository.h"
+
+void assert_config_entry_existence(
+ git_repository *repo,
+ const char *name,
+ bool is_supposed_to_exist)
+{
+ git_config *config;
+ const char *out;
+ int result;
+
+ cl_git_pass(git_repository_config__weakptr(&config, repo));
+
+ result = git_config_get_string(&out, config, name);
+
+ if (is_supposed_to_exist)
+ cl_git_pass(result);
+ else
+ cl_assert_equal_i(GIT_ENOTFOUND, result);
+}
+
+void assert_config_entry_value(
+ git_repository *repo,
+ const char *name,
+ const char *expected_value)
+{
+ git_config *config;
+ const char *out;
+
+ cl_git_pass(git_repository_config__weakptr(&config, repo));
+
+ cl_git_pass(git_config_get_string(&out, config, name));
+
+ cl_assert_equal_s(expected_value, out);
+}
diff --git a/tests-clar/config/config_helpers.h b/tests-clar/config/config_helpers.h
new file mode 100644
index 000000000..b887b3d38
--- /dev/null
+++ b/tests-clar/config/config_helpers.h
@@ -0,0 +1,9 @@
+extern void assert_config_entry_existence(
+ git_repository *repo,
+ const char *name,
+ bool is_supposed_to_exist);
+
+extern void assert_config_entry_value(
+ git_repository *repo,
+ const char *name,
+ const char *expected_value);
diff --git a/tests-clar/config/configlevel.c b/tests-clar/config/configlevel.c
new file mode 100644
index 000000000..1c22e8d9f
--- /dev/null
+++ b/tests-clar/config/configlevel.c
@@ -0,0 +1,71 @@
+#include "clar_libgit2.h"
+
+void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
+{
+ int error;
+ git_config *cfg;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ error = git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0);
+
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_EEXISTS, error);
+
+ git_config_free(cfg);
+}
+
+void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
+{
+ git_config *cfg;
+ const char *s;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
+ GIT_CONFIG_LEVEL_LOCAL, 1));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
+ GIT_CONFIG_LEVEL_LOCAL, 1));
+
+ cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal"));
+ cl_assert_equal_s("don't find me!", s);
+
+ git_config_free(cfg);
+}
+
+void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void)
+{
+ git_config *cfg;
+ git_config *single_level_cfg;
+ const char *s;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+
+ cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
+
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_get_string(&s, single_level_cfg, "core.stringglobal"));
+ cl_assert_equal_s("don't find me!", s);
+
+ git_config_free(single_level_cfg);
+}
+
+void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_returns_ENOTFOUND(void)
+{
+ git_config *cfg;
+ git_config *local_cfg;
+
+ cl_git_pass(git_config_new(&cfg));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_config_open_level(&local_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
+
+ git_config_free(cfg);
+}
diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c
index 3b40cd09a..26537e20a 100644
--- a/tests-clar/config/multivar.c
+++ b/tests-clar/config/multivar.c
@@ -12,13 +12,11 @@ void test_config_multivar__cleanup(void)
cl_fixture_cleanup("config");
}
-static int mv_read_cb(const char *name, const char *value, void *data)
+static int mv_read_cb(const git_config_entry *entry, void *data)
{
int *n = (int *) data;
- GIT_UNUSED(value);
-
- if (!strcmp(name, _name))
+ if (!strcmp(entry->name, _name))
(*n)++;
return 0;
@@ -37,11 +35,11 @@ void test_config_multivar__foreach(void)
git_config_free(cfg);
}
-static int cb(const char *val, void *data)
+static int cb(const git_config_entry *entry, void *data)
{
int *n = (int *) data;
- GIT_UNUSED(val);
+ GIT_UNUSED(entry);
(*n)++;
diff --git a/tests-clar/config/new.c b/tests-clar/config/new.c
index fae3ce941..dd6dbca9e 100644
--- a/tests-clar/config/new.c
+++ b/tests-clar/config/new.c
@@ -9,21 +9,17 @@
void test_config_new__write_new_config(void)
{
const char *out;
- struct git_config_file *file;
git_config *config;
- cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_git_mkfile(TEST_CONFIG, "");
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_set_string(config, "color.ui", "auto"));
cl_git_pass(git_config_set_string(config, "core.editor", "ed"));
git_config_free(config);
- cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_get_string(&out, config, "color.ui"));
cl_assert_equal_s(out, "auto");
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index f33bdd89e..c85826886 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -87,12 +87,20 @@ void test_config_read__lone_variable(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4")));
+ cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
+
cl_git_pass(git_config_get_string(&str, cfg, "some.section.variable"));
- cl_assert(str == NULL);
+ cl_assert_equal_s(str, "");
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
+ cl_git_pass(git_config_get_string(&str, cfg, "some.section.variableeq"));
+ cl_assert_equal_s(str, "");
+
+ cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
+ cl_assert(i == 0);
+
git_config_free(cfg);
}
@@ -186,36 +194,265 @@ void test_config_read__escaping_quotes(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
cl_git_pass(git_config_get_string(&str, cfg, "core.editor"));
- cl_assert(strcmp(str, "\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"") == 0);
+ cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", str);
+
+ git_config_free(cfg);
+}
+
+static int count_cfg_entries_and_compare_levels(
+ const git_config_entry *entry, void *payload)
+{
+ int *count = payload;
+
+ if (!strcmp(entry->value, "7") || !strcmp(entry->value, "17"))
+ cl_assert(entry->level == GIT_CONFIG_LEVEL_GLOBAL);
+ else
+ cl_assert(entry->level == GIT_CONFIG_LEVEL_SYSTEM);
+
+ (*count)++;
+ return 0;
+}
+
+static int cfg_callback_countdown(const git_config_entry *entry, void *payload)
+{
+ int *count = payload;
+ GIT_UNUSED(entry);
+ (*count)--;
+ if (*count == 0)
+ return -100;
+ return 0;
+}
+
+void test_config_read__foreach(void)
+{
+ git_config *cfg;
+ int count, ret;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ count = 0;
+ cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
+ cl_assert_equal_i(7, count);
+
+ count = 3;
+ cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count));
+ cl_assert_equal_i(GIT_EUSER, ret);
git_config_free(cfg);
}
-#if 0
+static int count_cfg_entries(const git_config_entry *entry, void *payload)
+{
+ int *count = payload;
+ GIT_UNUSED(entry);
+ (*count)++;
+ return 0;
+}
+
+void test_config_read__foreach_match(void)
+{
+ git_config *cfg;
+ int count;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
+
+ count = 0;
+ cl_git_pass(
+ git_config_foreach_match(cfg, "core.*", count_cfg_entries, &count));
+ cl_assert_equal_i(3, count);
+
+ count = 0;
+ cl_git_pass(
+ git_config_foreach_match(cfg, "remote\\.ab.*", count_cfg_entries, &count));
+ cl_assert_equal_i(2, count);
+
+ count = 0;
+ cl_git_pass(
+ git_config_foreach_match(cfg, ".*url$", count_cfg_entries, &count));
+ cl_assert_equal_i(2, count);
+
+ count = 0;
+ cl_git_pass(
+ git_config_foreach_match(cfg, ".*dummy.*", count_cfg_entries, &count));
+ cl_assert_equal_i(2, count);
+
+ count = 0;
+ cl_git_pass(
+ git_config_foreach_match(cfg, ".*nomatch.*", count_cfg_entries, &count));
+ cl_assert_equal_i(0, count);
+
+ git_config_free(cfg);
+}
-BEGIN_TEST(config10, "a repo's config overrides the global config")
- git_repository *repo;
+void test_config_read__whitespace_not_required_around_assignment(void)
+{
git_config *cfg;
- int32_t version;
+ const char *str;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "a.b"));
+ cl_assert_equal_s(str, "c");
+
+ cl_git_pass(git_config_get_string(&str, cfg, "d.e"));
+ cl_assert_equal_s(str, "f");
- cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- cl_git_pass(git_repository_config(&cfg, repo, GLOBAL_CONFIG, NULL));
- cl_git_pass(git_config_get_int32(cfg, "core.repositoryformatversion", &version));
- cl_assert(version == 0);
git_config_free(cfg);
- git_repository_free(repo);
-END_TEST
+}
-BEGIN_TEST(config11, "fall back to the global config")
- git_repository *repo;
+void test_config_read__read_git_config_entry(void)
+{
git_config *cfg;
- int32_t num;
+ const git_config_entry *entry;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+
+ cl_git_pass(git_config_get_entry(&entry, cfg, "core.dummy2"));
+ cl_assert_equal_s("core.dummy2", entry->name);
+ cl_assert_equal_s("42", entry->value);
+ cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level);
- cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- cl_git_pass(git_repository_config(&cfg, repo, GLOBAL_CONFIG, NULL));
- cl_git_pass(git_config_get_int32(cfg, "core.something", &num));
- cl_assert(num == 2);
git_config_free(cfg);
- git_repository_free(repo);
-END_TEST
-#endif
+}
+
+/*
+ * At the beginning of the test:
+ * - config9 has: core.dummy2=42
+ * - config15 has: core.dummy2=7
+ * - config16 has: core.dummy2=28
+ */
+void test_config_read__local_config_overrides_global_config_overrides_system_config(void)
+{
+ git_config *cfg;
+ int32_t i;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
+ cl_assert_equal_i(28, i);
+
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
+ cl_assert_equal_i(7, i);
+
+ git_config_free(cfg);
+}
+
+/*
+ * At the beginning of the test:
+ * - config9 has: core.global does not exist
+ * - config15 has: core.global=17
+ * - config16 has: core.global=29
+ *
+ * And also:
+ * - config9 has: core.system does not exist
+ * - config15 has: core.system does not exist
+ * - config16 has: core.system=11
+ */
+void test_config_read__fallback_from_local_to_global_and_from_global_to_system(void)
+{
+ git_config *cfg;
+ int32_t i;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.global"));
+ cl_assert_equal_i(17, i);
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.system"));
+ cl_assert_equal_i(11, i);
+
+ git_config_free(cfg);
+}
+
+/*
+ * At the beginning of the test, config18 has:
+ * int32global = 28
+ * int64global = 9223372036854775803
+ * boolglobal = true
+ * stringglobal = I'm a global config value!
+ *
+ * And config19 has:
+ * int32global = -1
+ * int64global = -2
+ * boolglobal = false
+ * stringglobal = don't find me!
+ *
+ */
+void test_config_read__simple_read_from_specific_level(void)
+{
+ git_config *cfg, *cfg_specific;
+ int i;
+ int64_t l, expected = +9223372036854775803;
+ const char *s;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+
+ cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+
+ cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global"));
+ cl_assert_equal_i(28, i);
+ cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global"));
+ cl_assert(l == expected);
+ cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
+ cl_assert_equal_b(true, i);
+ cl_git_pass(git_config_get_string(&s, cfg_specific, "core.stringglobal"));
+ cl_assert_equal_s("I'm a global config value!", s);
+
+ git_config_free(cfg_specific);
+ git_config_free(cfg);
+}
+
+static void clean_empty_config(void *unused)
+{
+ GIT_UNUSED(unused);
+ cl_fixture_cleanup("./empty");
+}
+
+void test_config_read__can_load_and_parse_an_empty_config_file(void)
+{
+ git_config *cfg;
+ int i;
+
+ cl_set_cleanup(&clean_empty_config, NULL);
+ cl_git_mkfile("./empty", "");
+ cl_git_pass(git_config_open_ondisk(&cfg, "./empty"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither"));
+
+ git_config_free(cfg);
+}
+
+void test_config_read__cannot_load_a_non_existing_config_file(void)
+{
+ git_config *cfg;
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_config_open_ondisk(&cfg, "./no.config"));
+}
diff --git a/tests-clar/config/refresh.c b/tests-clar/config/refresh.c
new file mode 100644
index 000000000..99d677f0e
--- /dev/null
+++ b/tests-clar/config/refresh.c
@@ -0,0 +1,67 @@
+#include "clar_libgit2.h"
+
+#define TEST_FILE "config.refresh"
+
+void test_config_refresh__initialize(void)
+{
+}
+
+void test_config_refresh__cleanup(void)
+{
+ cl_fixture_cleanup(TEST_FILE);
+}
+
+void test_config_refresh__update_value(void)
+{
+ git_config *cfg;
+ int32_t v;
+
+ cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n");
+
+ /* By freeing the config, we make sure we flush the values */
+ cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE));
+
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
+ cl_assert_equal_i(1, v);
+
+ cl_git_rewritefile(TEST_FILE, "[section]\n\tvalue = 10\n\n");
+
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
+ cl_assert_equal_i(1, v);
+
+ cl_git_pass(git_config_refresh(cfg));
+
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
+ cl_assert_equal_i(10, v);
+
+ git_config_free(cfg);
+}
+
+void test_config_refresh__delete_value(void)
+{
+ git_config *cfg;
+ int32_t v;
+
+ cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n");
+
+ /* By freeing the config, we make sure we flush the values */
+ cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE));
+
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
+ cl_assert_equal_i(1, v);
+ cl_git_fail(git_config_get_int32(&v, cfg, "section.newval"));
+
+ cl_git_rewritefile(TEST_FILE, "[section]\n\tnewval = 10\n\n");
+
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
+ cl_assert_equal_i(1, v);
+ cl_git_fail(git_config_get_int32(&v, cfg, "section.newval"));
+
+ cl_git_pass(git_config_refresh(cfg));
+
+ cl_git_fail(git_config_get_int32(&v, cfg, "section.value"));
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.newval"));
+ cl_assert_equal_i(10, v);
+
+ git_config_free(cfg);
+}
diff --git a/tests-clar/config/stress.c b/tests-clar/config/stress.c
index 3de1f7692..8cc64d23c 100644
--- a/tests-clar/config/stress.c
+++ b/tests-clar/config/stress.c
@@ -4,11 +4,13 @@
#include "fileops.h"
#include "posix.h"
+#define TEST_CONFIG "git-test-config"
+
void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- cl_git_pass(git_filebuf_open(&file, "git-test-config", 0));
+ cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0));
git_filebuf_printf(&file, "[color]\n\tui = auto\n");
git_filebuf_printf(&file, "[core]\n\teditor = \n");
@@ -18,19 +20,16 @@ void test_config_stress__initialize(void)
void test_config_stress__cleanup(void)
{
- p_unlink("git-test-config");
+ p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
const char *editor, *color;
- struct git_config_file *file;
git_config *config;
- cl_assert(git_path_exists("git-test-config"));
- cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_assert(git_path_exists(TEST_CONFIG));
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_get_string(&color, config, "color.ui"));
cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
@@ -40,22 +39,54 @@ void test_config_stress__dont_break_on_invalid_input(void)
void test_config_stress__comments(void)
{
- struct git_config_file *file;
git_config *config;
const char *str;
- cl_git_pass(git_config_file__ondisk(&file, cl_fixture("config/config12")));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
- cl_assert(!strcmp(str, "hello! \" ; ; ; "));
+ cl_assert_equal_s("hello! \" ; ; ; ", str);
cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
- cl_assert(!strcmp(str, "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#"));
+ cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
- cl_assert(!strcmp(str, "this is \ba phrase"));
+ cl_assert_equal_s("this is \ba phrase", str);
+
+ git_config_free(config);
+}
+
+void test_config_stress__escape_subsection_names(void)
+{
+ git_config *config;
+ const char *str;
+
+ cl_assert(git_path_exists("git-test-config"));
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
+
+ cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
+ git_config_free(config);
+
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
+
+ cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
+ cl_assert_equal_s("foo", str);
+ git_config_free(config);
+}
+
+void test_config_stress__trailing_backslash(void)
+{
+ git_config *config;
+ const char *str;
+ const char *path = "C:\\iam\\some\\windows\\path\\";
+
+ cl_assert(git_path_exists("git-test-config"));
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
+ cl_git_pass(git_config_set_string(config, "windows.path", path));
+ git_config_free(config);
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
+ cl_git_pass(git_config_get_string(&str, config, "windows.path"));
+ cl_assert_equal_s(path, str);
git_config_free(config);
}
diff --git a/tests-clar/config/validkeyname.c b/tests-clar/config/validkeyname.c
new file mode 100644
index 000000000..03c13d723
--- /dev/null
+++ b/tests-clar/config/validkeyname.c
@@ -0,0 +1,68 @@
+#include "clar_libgit2.h"
+
+#include "config.h"
+
+static git_config *cfg;
+static const char *value;
+
+void test_config_validkeyname__initialize(void)
+{
+ cl_fixture_sandbox("config/config10");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
+}
+
+void test_config_validkeyname__cleanup(void)
+{
+ git_config_free(cfg);
+ cfg = NULL;
+
+ cl_fixture_cleanup("config10");
+}
+
+static void assert_invalid_config_key_name(const char *name)
+{
+ cl_git_fail_with(git_config_get_string(&value, cfg, name),
+ GIT_EINVALIDSPEC);
+ cl_git_fail_with(git_config_set_string(cfg, name, "42"),
+ GIT_EINVALIDSPEC);
+ cl_git_fail_with(git_config_delete_entry(cfg, name),
+ GIT_EINVALIDSPEC);
+ cl_git_fail_with(git_config_get_multivar(cfg, name, "*", NULL, NULL),
+ GIT_EINVALIDSPEC);
+ cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"),
+ GIT_EINVALIDSPEC);
+}
+
+void test_config_validkeyname__accessing_requires_a_valid_name(void)
+{
+ assert_invalid_config_key_name("");
+ assert_invalid_config_key_name(".");
+ assert_invalid_config_key_name("..");
+ assert_invalid_config_key_name("core.");
+ assert_invalid_config_key_name("d#ff.dirstat.lines");
+ assert_invalid_config_key_name("diff.dirstat.lines#");
+ assert_invalid_config_key_name("dif\nf.dirstat.lines");
+ assert_invalid_config_key_name("dif.dir\nstat.lines");
+ assert_invalid_config_key_name("dif.dirstat.li\nes");
+}
+
+static void assert_invalid_config_section_name(git_repository *repo, const char *name)
+{
+ cl_git_fail_with(git_config_rename_section(repo, "branch.remoteless", name), GIT_EINVALIDSPEC);
+}
+
+void test_config_validkeyname__renaming_a_section_requires_a_valid_name(void)
+{
+ git_repository *repo;
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ assert_invalid_config_section_name(repo, "");
+ assert_invalid_config_section_name(repo, "bra\nch");
+ assert_invalid_config_section_name(repo, "branc#");
+ assert_invalid_config_section_name(repo, "bra\nch.duh");
+ assert_invalid_config_section_name(repo, "branc#.duh");
+
+ git_repository_free(repo);
+}
diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c
index f8774473e..d70612a97 100644
--- a/tests-clar/config/write.c
+++ b/tests-clar/config/write.c
@@ -3,11 +3,15 @@
void test_config_write__initialize(void)
{
cl_fixture_sandbox("config/config9");
+ cl_fixture_sandbox("config/config15");
+ cl_fixture_sandbox("config/config17");
}
void test_config_write__cleanup(void)
{
cl_fixture_cleanup("config9");
+ cl_fixture_cleanup("config15");
+ cl_fixture_cleanup("config17");
}
void test_config_write__replace_value(void)
@@ -58,7 +62,7 @@ void test_config_write__delete_value(void)
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_delete(cfg, "core.dummy"));
+ cl_git_pass(git_config_delete_entry(cfg, "core.dummy"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
@@ -67,6 +71,40 @@ void test_config_write__delete_value(void)
git_config_free(cfg);
}
+/*
+ * At the beginning of the test:
+ * - config9 has: core.dummy2=42
+ * - config15 has: core.dummy2=7
+ */
+void test_config_write__delete_value_at_specific_level(void)
+{
+ git_config *cfg, *cfg_specific;
+ int32_t i;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
+ cl_assert(i == 7);
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+
+ cl_git_pass(git_config_delete_entry(cfg_specific, "core.dummy2"));
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
+ cl_assert(git_config_get_int32(&i, cfg, "core.dummy2") == GIT_ENOTFOUND);
+ cl_git_pass(git_config_set_int32(cfg, "core.dummy2", 7));
+
+ git_config_free(cfg_specific);
+ git_config_free(cfg);
+}
+
void test_config_write__write_subsection(void)
{
git_config *cfg;
@@ -78,7 +116,7 @@ void test_config_write__write_subsection(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string(&str, cfg, "my.own.var"));
- cl_git_pass(strcmp(str, "works"));
+ cl_assert_equal_s("works", str);
git_config_free(cfg);
}
@@ -87,6 +125,120 @@ void test_config_write__delete_inexistent(void)
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_assert(git_config_delete(cfg, "core.imaginary") == GIT_ENOTFOUND);
+ cl_assert(git_config_delete_entry(cfg, "core.imaginary") == GIT_ENOTFOUND);
+ git_config_free(cfg);
+}
+
+void test_config_write__value_containing_quotes(void)
+{
+ git_config *cfg;
+ const char* str;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+ cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes"));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
+ cl_assert_equal_s(str, "this \"has\" quotes");
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
+ cl_assert_equal_s(str, "this \"has\" quotes");
+ git_config_free(cfg);
+
+ /* The code path for values that already exist is different, check that one as well */
+ cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+ cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes"));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
+ cl_assert_equal_s(str, "this also \"has\" quotes");
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
+ cl_assert_equal_s(str, "this also \"has\" quotes");
+ git_config_free(cfg);
+}
+
+void test_config_write__escape_value(void)
+{
+ git_config *cfg;
+ const char* str;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+ cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t"));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
+ cl_assert_equal_s(str, "this \"has\" quotes and \t");
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
+ cl_assert_equal_s(str, "this \"has\" quotes and \t");
+ git_config_free(cfg);
+}
+
+void test_config_write__add_value_at_specific_level(void)
+{
+ git_config *cfg, *cfg_specific;
+ int i;
+ int64_t l, expected = +9223372036854775803;
+ const char *s;
+
+ // open config15 as global level config file
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+
+ cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28));
+ cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected));
+ cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true));
+ cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!"));
+ git_config_free(cfg_specific);
+ git_config_free(cfg);
+
+ // open config15 as local level config file
+ cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global"));
+ cl_assert_equal_i(28, i);
+ cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global"));
+ cl_assert(l == expected);
+ cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
+ cl_assert_equal_b(true, i);
+ cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal"));
+ cl_assert_equal_s("I'm a global config value!", s);
+
git_config_free(cfg);
}
+
+void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void)
+{
+ git_config *cfg;
+ int i;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
+ cl_git_pass(git_config_set_int32(cfg, "core.newline", 7));
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.newline"));
+ cl_assert_equal_i(7, i);
+
+ git_config_free(cfg);
+}
+
+void test_config_write__can_set_a_value_to_NULL(void)
+{
+ git_repository *repository;
+ git_config *config;
+
+ repository = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_repository_config(&config, repository));
+ cl_git_fail(git_config_set_string(config, "a.b.c", NULL));
+ git_config_free(config);
+
+ cl_git_sandbox_cleanup();
+}
diff --git a/tests-clar/core/buffer.c b/tests-clar/core/buffer.c
index 6a718f459..3d8221e04 100644
--- a/tests-clar/core/buffer.c
+++ b/tests-clar/core/buffer.c
@@ -1,5 +1,8 @@
#include "clar_libgit2.h"
#include "buffer.h"
+#include "buf_text.h"
+#include "hashsig.h"
+#include "fileops.h"
#define TESTSTR "Have you seen that? Have you seeeen that??"
const char *test_string = TESTSTR;
@@ -456,6 +459,9 @@ void test_core_buffer__8(void)
git_buf_free(&a);
+ check_joinbuf_2(NULL, "", "");
+ check_joinbuf_2(NULL, "a", "a");
+ check_joinbuf_2(NULL, "/a", "/a");
check_joinbuf_2("", "", "");
check_joinbuf_2("", "a", "a");
check_joinbuf_2("", "/a", "/a");
@@ -576,38 +582,407 @@ void test_core_buffer__11(void)
t.strings = t1;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "");
t.strings = t2;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "some");
t.strings = t3;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "");
t.strings = t4;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "happ");
t.strings = t5;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "happ");
t.strings = t6;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "");
t.strings = t7;
t.count = 3;
- cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_git_pass(git_buf_text_common_prefix(&a, &t));
cl_assert_equal_s(a.ptr, "");
git_buf_free(&a);
}
+
+void test_core_buffer__rfind_variants(void)
+{
+ git_buf a = GIT_BUF_INIT;
+ ssize_t len;
+
+ cl_git_pass(git_buf_sets(&a, "/this/is/it/"));
+
+ len = (ssize_t)git_buf_len(&a);
+
+ cl_assert(git_buf_rfind(&a, '/') == len - 1);
+ cl_assert(git_buf_rfind_next(&a, '/') == len - 4);
+
+ cl_assert(git_buf_rfind(&a, 'i') == len - 3);
+ cl_assert(git_buf_rfind_next(&a, 'i') == len - 3);
+
+ cl_assert(git_buf_rfind(&a, 'h') == 2);
+ cl_assert(git_buf_rfind_next(&a, 'h') == 2);
+
+ cl_assert(git_buf_rfind(&a, 'q') == -1);
+ cl_assert(git_buf_rfind_next(&a, 'q') == -1);
+
+ git_buf_free(&a);
+}
+
+void test_core_buffer__puts_escaped(void)
+{
+ git_buf a = GIT_BUF_INIT;
+
+ git_buf_clear(&a);
+ cl_git_pass(git_buf_text_puts_escaped(&a, "this is a test", "", ""));
+ cl_assert_equal_s("this is a test", a.ptr);
+
+ git_buf_clear(&a);
+ cl_git_pass(git_buf_text_puts_escaped(&a, "this is a test", "t", "\\"));
+ cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
+
+ git_buf_clear(&a);
+ cl_git_pass(git_buf_text_puts_escaped(&a, "this is a test", "i ", "__"));
+ cl_assert_equal_s("th__is__ __is__ a__ test", a.ptr);
+
+ git_buf_clear(&a);
+ cl_git_pass(git_buf_text_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
+ cl_assert_equal_s("\\^match\\\\s\\*\\[A-Z\\]\\+\\.\\*", a.ptr);
+
+ git_buf_free(&a);
+}
+
+static void assert_unescape(char *expected, char *to_unescape) {
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_sets(&buf, to_unescape));
+ git_buf_text_unescape(&buf);
+ cl_assert_equal_s(expected, buf.ptr);
+ cl_assert_equal_sz(strlen(expected), buf.size);
+
+ git_buf_free(&buf);
+}
+
+void test_core_buffer__unescape(void)
+{
+ assert_unescape("Escaped\\", "Es\\ca\\ped\\");
+ assert_unescape("Es\\caped\\", "Es\\\\ca\\ped\\\\");
+ assert_unescape("\\", "\\");
+ assert_unescape("\\", "\\\\");
+ assert_unescape("", "");
+}
+
+void test_core_buffer__base64(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ /* t h i s
+ * 0x 74 68 69 73
+ * 0b 01110100 01101000 01101001 01110011
+ * 0b 011101 000110 100001 101001 011100 110000
+ * 0x 1d 06 21 29 1c 30
+ * d G h p c w
+ */
+ cl_git_pass(git_buf_put_base64(&buf, "this", 4));
+ cl_assert_equal_s("dGhpcw==", buf.ptr);
+
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_put_base64(&buf, "this!", 5));
+ cl_assert_equal_s("dGhpcyE=", buf.ptr);
+
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_put_base64(&buf, "this!\n", 6));
+ cl_assert_equal_s("dGhpcyEK", buf.ptr);
+
+ git_buf_free(&buf);
+}
+
+void test_core_buffer__classify_with_utf8(void)
+{
+ char *data0 = "Simple text\n";
+ size_t data0len = 12;
+ char *data1 = "Is that UTF-8 data I see…\nYep!\n";
+ size_t data1len = 31;
+ char *data2 = "Internal NUL!!!\000\n\nI see you!\n";
+ size_t data2len = 29;
+ git_buf b;
+
+ b.ptr = data0; b.size = b.asize = data0len;
+ cl_assert(!git_buf_text_is_binary(&b));
+ cl_assert(!git_buf_text_contains_nul(&b));
+
+ b.ptr = data1; b.size = b.asize = data1len;
+ cl_assert(git_buf_text_is_binary(&b));
+ cl_assert(!git_buf_text_contains_nul(&b));
+
+ b.ptr = data2; b.size = b.asize = data2len;
+ cl_assert(git_buf_text_is_binary(&b));
+ cl_assert(git_buf_text_contains_nul(&b));
+}
+
+#define SIMILARITY_TEST_DATA_1 \
+ "test data\nright here\ninline\ntada\nneeds more data\nlots of data\n" \
+ "is this enough?\nthere has to be enough data to fill the hash array!\n" \
+ "Apparently 191 bytes is the minimum amount of data needed.\nHere goes!\n" \
+ "Let's make sure we've got plenty to go with here.\n smile \n"
+
+void test_core_buffer__similarity_metric(void)
+{
+ git_hashsig *a, *b;
+ git_buf buf = GIT_BUF_INIT;
+ int sim;
+
+ /* in the first case, we compare data to itself and expect 100% match */
+
+ cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ cl_assert_equal_i(100, git_hashsig_compare(a, b));
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* if we change just a single byte, how much does that change magnify? */
+
+ cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_buf_sets(&buf,
+ "Test data\nright here\ninline\ntada\nneeds more data\nlots of data\n"
+ "is this enough?\nthere has to be enough data to fill the hash array!\n"
+ "Apparently 191 bytes is the minimum amount of data needed.\nHere goes!\n"
+ "Let's make sure we've got plenty to go with here.\n smile \n"));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ sim = git_hashsig_compare(a, b);
+
+ cl_assert(95 < sim && sim < 100); /* expect >95% similarity */
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* let's try comparing data to a superset of itself */
+
+ cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1
+ "and if I add some more, it should still be pretty similar, yes?\n"));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ sim = git_hashsig_compare(a, b);
+
+ cl_assert(70 < sim && sim < 80); /* expect in the 70-80% similarity range */
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* what if we keep about half the original data and add half new */
+
+ cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_buf_sets(&buf,
+ "test data\nright here\ninline\ntada\nneeds more data\nlots of data\n"
+ "is this enough?\nthere has to be enough data to fill the hash array!\n"
+ "okay, that's half the original\nwhat else can we add?\nmore data\n"
+ "one more line will complete this\nshort\nlines\ndon't\nmatter\n"));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ sim = git_hashsig_compare(a, b);
+
+ cl_assert(40 < sim && sim < 60); /* expect in the 40-60% similarity range */
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* lastly, let's check that we can hash file content as well */
+
+ cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ cl_git_pass(git_futils_mkdir("scratch", NULL, 0755, GIT_MKDIR_PATH));
+ cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1);
+ cl_git_pass(git_hashsig_create_fromfile(
+ &b, "scratch/testdata", GIT_HASHSIG_NORMAL));
+
+ cl_assert_equal_i(100, git_hashsig_compare(a, b));
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ git_buf_free(&buf);
+ git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES);
+}
+
+
+void test_core_buffer__similarity_metric_whitespace(void)
+{
+ git_hashsig *a, *b;
+ git_buf buf = GIT_BUF_INIT;
+ int sim, i, j;
+ git_hashsig_option_t opt;
+ const char *tabbed =
+ " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n"
+ " separator = sep[s];\n"
+ " expect = expect_values[s];\n"
+ "\n"
+ " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
+ " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
+ " git_buf_join(&buf, separator, a[i], b[j]);\n"
+ " cl_assert_equal_s(*expect, buf.ptr);\n"
+ " expect++;\n"
+ " }\n"
+ " }\n"
+ " }\n";
+ const char *spaced =
+ " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n"
+ " separator = sep[s];\n"
+ " expect = expect_values[s];\n"
+ "\n"
+ " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
+ " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
+ " git_buf_join(&buf, separator, a[i], b[j]);\n"
+ " cl_assert_equal_s(*expect, buf.ptr);\n"
+ " expect++;\n"
+ " }\n"
+ " }\n"
+ " }\n";
+ const char *crlf_spaced2 =
+ " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\r\n"
+ " separator = sep[s];\r\n"
+ " expect = expect_values[s];\r\n"
+ "\r\n"
+ " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n"
+ " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n"
+ " git_buf_join(&buf, separator, a[i], b[j]);\r\n"
+ " cl_assert_equal_s(*expect, buf.ptr);\r\n"
+ " expect++;\r\n"
+ " }\r\n"
+ " }\r\n"
+ " }\r\n";
+ const char *text[3] = { tabbed, spaced, crlf_spaced2 };
+
+ /* let's try variations of our own code with whitespace changes */
+
+ for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) {
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ cl_git_pass(git_buf_sets(&buf, text[i]));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt));
+
+ cl_git_pass(git_buf_sets(&buf, text[j]));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt));
+
+ sim = git_hashsig_compare(a, b);
+
+ if (opt == GIT_HASHSIG_NORMAL) {
+ if (i == j)
+ cl_assert_equal_i(100, sim);
+ else
+ cl_assert(sim < 30); /* expect pretty different */
+ } else {
+ cl_assert_equal_i(100, sim);
+ }
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+ }
+ }
+ }
+
+ git_buf_free(&buf);
+}
+
+#define check_buf(expected,buf) do { \
+ cl_assert_equal_s(expected, buf.ptr); \
+ cl_assert_equal_sz(strlen(expected), buf.size); } while (0)
+
+void test_core_buffer__lf_and_crlf_conversions(void)
+{
+ git_buf src = GIT_BUF_INIT, tgt = GIT_BUF_INIT;
+
+ /* LF source */
+
+ git_buf_sets(&src, "lf\nlf\nlf\nlf\n");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("lf\r\nlf\r\nlf\r\nlf\r\n", tgt);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_buf_text_crlf_to_lf(&tgt, &src));
+ /* no conversion needed if all LFs already */
+
+ git_buf_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("\r\nlf\r\nlf\r\nlf\r\nlf\r\nlf", tgt);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_buf_text_crlf_to_lf(&tgt, &src));
+ /* no conversion needed if all LFs already */
+
+ /* CRLF source */
+
+ git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt);
+ check_buf(src.ptr, tgt);
+
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt);
+
+ git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt);
+ check_buf(src.ptr, tgt);
+
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt);
+
+ /* CRLF in LF text */
+
+ git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt);
+
+ /* LF in CRLF text */
+
+ git_buf_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt);
+
+ /* bare CR test */
+
+ git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
+
+ git_buf_sets(&src, "\rcr\r");
+ cl_assert_equal_i(GIT_ENOTFOUND, git_buf_text_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf("\rcr\r", tgt);
+
+ git_buf_free(&src);
+ git_buf_free(&tgt);
+}
diff --git a/tests-clar/core/copy.c b/tests-clar/core/copy.c
new file mode 100644
index 000000000..c0c59c056
--- /dev/null
+++ b/tests-clar/core/copy.c
@@ -0,0 +1,126 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "path.h"
+#include "posix.h"
+
+void test_core_copy__file(void)
+{
+ struct stat st;
+ const char *content = "This is some stuff to copy\n";
+
+ cl_git_mkfile("copy_me", content);
+
+ cl_git_pass(git_futils_cp("copy_me", "copy_me_two", 0664));
+
+ cl_git_pass(git_path_lstat("copy_me_two", &st));
+ cl_assert(S_ISREG(st.st_mode));
+ cl_assert(strlen(content) == (size_t)st.st_size);
+
+ cl_git_pass(p_unlink("copy_me_two"));
+ cl_git_pass(p_unlink("copy_me"));
+}
+
+void test_core_copy__file_in_dir(void)
+{
+ struct stat st;
+ const char *content = "This is some other stuff to copy\n";
+
+ cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", NULL, 0775, GIT_MKDIR_PATH));
+ cl_git_mkfile("an_dir/in_a_dir/copy_me", content);
+ cl_assert(git_path_isdir("an_dir"));
+
+ cl_git_pass(git_futils_mkpath2file
+ ("an_dir/second_dir/and_more/copy_me_two", 0775));
+
+ cl_git_pass(git_futils_cp
+ ("an_dir/in_a_dir/copy_me",
+ "an_dir/second_dir/and_more/copy_me_two",
+ 0664));
+
+ cl_git_pass(git_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st));
+ cl_assert(S_ISREG(st.st_mode));
+ cl_assert(strlen(content) == (size_t)st.st_size);
+
+ cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_assert(!git_path_isdir("an_dir"));
+}
+
+void test_core_copy__tree(void)
+{
+ struct stat st;
+ const char *content = "File content\n";
+
+ cl_git_pass(git_futils_mkdir("src/b", NULL, 0775, GIT_MKDIR_PATH));
+ cl_git_pass(git_futils_mkdir("src/c/d", NULL, 0775, GIT_MKDIR_PATH));
+ cl_git_pass(git_futils_mkdir("src/c/e", NULL, 0775, GIT_MKDIR_PATH));
+
+ cl_git_mkfile("src/f1", content);
+ cl_git_mkfile("src/b/f2", content);
+ cl_git_mkfile("src/c/f3", content);
+ cl_git_mkfile("src/c/d/f4", content);
+ cl_git_mkfile("src/c/d/.f5", content);
+
+#ifndef GIT_WIN32
+ cl_assert(p_symlink("../../b/f2", "src/c/d/l1") == 0);
+#endif
+
+ cl_assert(git_path_isdir("src"));
+ cl_assert(git_path_isdir("src/b"));
+ cl_assert(git_path_isdir("src/c/d"));
+ cl_assert(git_path_isfile("src/c/d/f4"));
+
+ /* copy with no empty dirs, yes links, no dotfiles, no overwrite */
+
+ cl_git_pass(
+ git_futils_cp_r("src", "t1", GIT_CPDIR_COPY_SYMLINKS, 0) );
+
+ cl_assert(git_path_isdir("t1"));
+ cl_assert(git_path_isdir("t1/b"));
+ cl_assert(git_path_isdir("t1/c"));
+ cl_assert(git_path_isdir("t1/c/d"));
+ cl_assert(!git_path_isdir("t1/c/e"));
+
+ cl_assert(git_path_isfile("t1/f1"));
+ cl_assert(git_path_isfile("t1/b/f2"));
+ cl_assert(git_path_isfile("t1/c/f3"));
+ cl_assert(git_path_isfile("t1/c/d/f4"));
+ cl_assert(!git_path_isfile("t1/c/d/.f5"));
+
+ cl_git_pass(git_path_lstat("t1/c/f3", &st));
+ cl_assert(S_ISREG(st.st_mode));
+ cl_assert(strlen(content) == (size_t)st.st_size);
+
+#ifndef GIT_WIN32
+ cl_git_pass(git_path_lstat("t1/c/d/l1", &st));
+ cl_assert(S_ISLNK(st.st_mode));
+#endif
+
+ cl_git_pass(git_futils_rmdir_r("t1", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_assert(!git_path_isdir("t1"));
+
+ /* copy with empty dirs, no links, yes dotfiles, no overwrite */
+
+ cl_git_pass(
+ git_futils_cp_r("src", "t2", GIT_CPDIR_CREATE_EMPTY_DIRS | GIT_CPDIR_COPY_DOTFILES, 0) );
+
+ cl_assert(git_path_isdir("t2"));
+ cl_assert(git_path_isdir("t2/b"));
+ cl_assert(git_path_isdir("t2/c"));
+ cl_assert(git_path_isdir("t2/c/d"));
+ cl_assert(git_path_isdir("t2/c/e"));
+
+ cl_assert(git_path_isfile("t2/f1"));
+ cl_assert(git_path_isfile("t2/b/f2"));
+ cl_assert(git_path_isfile("t2/c/f3"));
+ cl_assert(git_path_isfile("t2/c/d/f4"));
+ cl_assert(git_path_isfile("t2/c/d/.f5"));
+
+#ifndef GIT_WIN32
+ cl_git_fail(git_path_lstat("t2/c/d/l1", &st));
+#endif
+
+ cl_git_pass(git_futils_rmdir_r("t2", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_assert(!git_path_isdir("t2"));
+
+ cl_git_pass(git_futils_rmdir_r("src", NULL, GIT_RMDIR_REMOVE_FILES));
+}
diff --git a/tests-clar/core/env.c b/tests-clar/core/env.c
new file mode 100644
index 000000000..0fa6472d7
--- /dev/null
+++ b/tests-clar/core/env.c
@@ -0,0 +1,303 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "path.h"
+
+#ifdef GIT_WIN32
+#define NUM_VARS 5
+static const char *env_vars[NUM_VARS] = {
+ "HOME", "HOMEDRIVE", "HOMEPATH", "USERPROFILE", "PROGRAMFILES"
+};
+#else
+#define NUM_VARS 1
+static const char *env_vars[NUM_VARS] = { "HOME" };
+#endif
+
+static char *env_save[NUM_VARS];
+
+static char *home_values[] = {
+ "fake_home",
+ "f\xc3\xa1ke_h\xc3\xb5me", /* all in latin-1 supplement */
+ "f\xc4\x80ke_\xc4\xa4ome", /* latin extended */
+ "f\xce\xb1\xce\xba\xce\xb5_h\xce\xbfm\xce\xad", /* having fun with greek */
+ "fa\xe0" "\xb8" "\x87" "e_\xe0" "\xb8" "\x99" "ome", /* thai characters */
+ "f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */
+ "\xe1\xb8\x9f\xe1\xba\xa2" "ke_ho" "\xe1" "\xb9" "\x81" "e", /* latin extended additional */
+ "\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */
+ NULL
+};
+
+void test_core_env__initialize(void)
+{
+ int i;
+ for (i = 0; i < NUM_VARS; ++i) {
+ const char *original = cl_getenv(env_vars[i]);
+#ifdef GIT_WIN32
+ env_save[i] = (char *)original;
+#else
+ env_save[i] = original ? git__strdup(original) : NULL;
+#endif
+ }
+}
+
+static void reset_global_search_path(void)
+{
+ cl_git_pass(git_futils_dirs_set(GIT_FUTILS_DIR_GLOBAL, NULL));
+}
+
+static void reset_system_search_path(void)
+{
+ cl_git_pass(git_futils_dirs_set(GIT_FUTILS_DIR_SYSTEM, NULL));
+}
+
+void test_core_env__cleanup(void)
+{
+ int i;
+ char **val;
+
+ for (i = 0; i < NUM_VARS; ++i) {
+ cl_setenv(env_vars[i], env_save[i]);
+ git__free(env_save[i]);
+ env_save[i] = NULL;
+ }
+
+ /* these will probably have already been cleaned up, but if a test
+ * fails, then it's probably good to try and clear out these dirs
+ */
+ for (val = home_values; *val != NULL; val++) {
+ if (**val != '\0')
+ (void)p_rmdir(*val);
+ }
+
+ /* reset search paths to default */
+ reset_global_search_path();
+ reset_system_search_path();
+}
+
+static void setenv_and_check(const char *name, const char *value)
+{
+ char *check;
+
+ cl_git_pass(cl_setenv(name, value));
+
+ check = cl_getenv(name);
+ cl_assert_equal_s(value, check);
+#ifdef GIT_WIN32
+ git__free(check);
+#endif
+}
+
+void test_core_env__0(void)
+{
+ git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ char testfile[16], tidx = '0';
+ char **val;
+ const char *testname = "testfile";
+ size_t testlen = strlen(testname);
+
+ strncpy(testfile, testname, sizeof(testfile));
+ cl_assert_equal_s(testname, testfile);
+
+ for (val = home_values; *val != NULL; val++) {
+
+ /* if we can't make the directory, let's just assume
+ * we are on a filesystem that doesn't support the
+ * characters in question and skip this test...
+ */
+ if (p_mkdir(*val, 0777) != 0) {
+ *val = ""; /* mark as not created */
+ continue;
+ }
+
+ cl_git_pass(git_path_prettify(&path, *val, NULL));
+
+ /* vary testfile name in each directory so accidentally leaving
+ * an environment variable set from a previous iteration won't
+ * accidentally make this test pass...
+ */
+ testfile[testlen] = tidx++;
+ cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_mkfile(path.ptr, "find me");
+ git_buf_rtruncate_at_char(&path, '/');
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+
+ setenv_and_check("HOME", path.ptr);
+ reset_global_search_path();
+
+ cl_git_pass(git_futils_find_global_file(&found, testfile));
+
+ cl_setenv("HOME", env_save[0]);
+ reset_global_search_path();
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+
+#ifdef GIT_WIN32
+ setenv_and_check("HOMEDRIVE", NULL);
+ setenv_and_check("HOMEPATH", NULL);
+ setenv_and_check("USERPROFILE", path.ptr);
+ reset_global_search_path();
+
+ cl_git_pass(git_futils_find_global_file(&found, testfile));
+
+ {
+ int root = git_path_root(path.ptr);
+ char old;
+
+ if (root >= 0) {
+ setenv_and_check("USERPROFILE", NULL);
+ reset_global_search_path();
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+
+ old = path.ptr[root];
+ path.ptr[root] = '\0';
+ setenv_and_check("HOMEDRIVE", path.ptr);
+ path.ptr[root] = old;
+ setenv_and_check("HOMEPATH", &path.ptr[root]);
+ reset_global_search_path();
+
+ cl_git_pass(git_futils_find_global_file(&found, testfile));
+ }
+ }
+#endif
+
+ (void)p_rmdir(*val);
+ }
+
+ git_buf_free(&path);
+ git_buf_free(&found);
+}
+
+
+void test_core_env__1(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&path, "nonexistentfile"));
+
+ cl_git_pass(cl_setenv("HOME", "doesnotexist"));
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("HOMEPATH", "doesnotexist"));
+ cl_git_pass(cl_setenv("USERPROFILE", "doesnotexist"));
+#endif
+ reset_global_search_path();
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&path, "nonexistentfile"));
+
+ cl_git_pass(cl_setenv("HOME", NULL));
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("HOMEPATH", NULL));
+ cl_git_pass(cl_setenv("USERPROFILE", NULL));
+#endif
+ reset_global_search_path();
+ reset_system_search_path();
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&path, "nonexistentfile"));
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_system_file(&path, "nonexistentfile"));
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("PROGRAMFILES", NULL));
+ reset_system_search_path();
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_system_file(&path, "nonexistentfile"));
+#endif
+
+ git_buf_free(&path);
+}
+
+static void check_global_searchpath(
+ const char *path, int position, const char *file, git_buf *temp)
+{
+ char out[GIT_PATH_MAX];
+
+ /* build and set new path */
+ if (position < 0)
+ cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
+ else if (position > 0)
+ cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
+ else
+ cl_git_pass(git_buf_sets(temp, path));
+
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, temp->ptr));
+
+ /* get path and make sure $PATH expansion worked */
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, out, sizeof(out)));
+
+ if (position < 0)
+ cl_assert(git__prefixcmp(out, path) == 0);
+ else if (position > 0)
+ cl_assert(git__suffixcmp(out, path) == 0);
+ else
+ cl_assert_equal_s(out, path);
+
+ /* find file using new path */
+ cl_git_pass(git_futils_find_global_file(temp, file));
+
+ /* reset path and confirm file not found */
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL));
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(temp, file));
+}
+
+void test_core_env__2(void)
+{
+ git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ char testfile[16], tidx = '0';
+ char **val;
+ const char *testname = "alternate";
+ size_t testlen = strlen(testname);
+
+ strncpy(testfile, testname, sizeof(testfile));
+ cl_assert_equal_s(testname, testfile);
+
+ for (val = home_values; *val != NULL; val++) {
+
+ /* if we can't make the directory, let's just assume
+ * we are on a filesystem that doesn't support the
+ * characters in question and skip this test...
+ */
+ if (p_mkdir(*val, 0777) != 0 && errno != EEXIST) {
+ *val = ""; /* mark as not created */
+ continue;
+ }
+
+ cl_git_pass(git_path_prettify(&path, *val, NULL));
+
+ /* vary testfile name so any sloppiness is resetting variables or
+ * deleting files won't accidentally make a test pass.
+ */
+ testfile[testlen] = tidx++;
+ cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_mkfile(path.ptr, "find me");
+ git_buf_rtruncate_at_char(&path, '/');
+
+ /* default should be NOTFOUND */
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+
+ /* try plain, append $PATH, and prepend $PATH */
+ check_global_searchpath(path.ptr, 0, testfile, &found);
+ check_global_searchpath(path.ptr, -1, testfile, &found);
+ check_global_searchpath(path.ptr, 1, testfile, &found);
+
+ /* cleanup */
+ cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ (void)p_unlink(path.ptr);
+ (void)p_rmdir(*val);
+ }
+
+ git_buf_free(&path);
+ git_buf_free(&found);
+}
diff --git a/tests-clar/core/errors.c b/tests-clar/core/errors.c
index 0be3e7aca..512a4134d 100644
--- a/tests-clar/core/errors.c
+++ b/tests-clar/core/errors.c
@@ -1,4 +1,31 @@
#include "clar_libgit2.h"
+
+void test_core_errors__public_api(void)
+{
+ char *str_in_error;
+
+ giterr_clear();
+ cl_assert(giterr_last() == NULL);
+
+ giterr_set_oom();
+
+ cl_assert(giterr_last() != NULL);
+ cl_assert(giterr_last()->klass == GITERR_NOMEMORY);
+ str_in_error = strstr(giterr_last()->message, "memory");
+ cl_assert(str_in_error != NULL);
+
+ giterr_clear();
+
+ giterr_set_str(GITERR_REPOSITORY, "This is a test");
+
+ cl_assert(giterr_last() != NULL);
+ str_in_error = strstr(giterr_last()->message, "This is a test");
+ cl_assert(str_in_error != NULL);
+
+ giterr_clear();
+ cl_assert(giterr_last() == NULL);
+}
+
#include "common.h"
#include "util.h"
#include "posix.h"
@@ -31,7 +58,7 @@ void test_core_errors__new_school(void)
do {
struct stat st;
memset(&st, 0, sizeof(st));
- assert(p_lstat("this_file_does_not_exist", &st) < 0);
+ cl_assert(p_lstat("this_file_does_not_exist", &st) < 0);
GIT_UNUSED(st);
} while (false);
giterr_set(GITERR_OS, "stat failed"); /* internal fn */
diff --git a/tests-clar/core/filebuf.c b/tests-clar/core/filebuf.c
index eab8a26eb..4451c01c7 100644
--- a/tests-clar/core/filebuf.c
+++ b/tests-clar/core/filebuf.c
@@ -8,7 +8,7 @@ void test_core_filebuf__0(void)
int fd;
char test[] = "test", testlock[] = "test.lock";
- fd = p_creat(testlock, 0744);
+ fd = p_creat(testlock, 0744); //-V536
cl_must_pass(fd);
cl_must_pass(p_close(fd));
@@ -27,7 +27,7 @@ void test_core_filebuf__1(void)
int fd;
char test[] = "test";
- fd = p_creat(test, 0666);
+ fd = p_creat(test, 0666); //-V536
cl_must_pass(fd);
cl_must_pass(p_write(fd, "libgit2 rocks\n", 14));
cl_must_pass(p_close(fd));
diff --git a/tests-clar/core/mkdir.c b/tests-clar/core/mkdir.c
new file mode 100644
index 000000000..1e50b4336
--- /dev/null
+++ b/tests-clar/core/mkdir.c
@@ -0,0 +1,182 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "path.h"
+#include "posix.h"
+
+static void cleanup_basic_dirs(void *ref)
+{
+ GIT_UNUSED(ref);
+ git_futils_rmdir_r("d0", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+ git_futils_rmdir_r("d1", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+ git_futils_rmdir_r("d2", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+ git_futils_rmdir_r("d3", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+ git_futils_rmdir_r("d4", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+}
+
+void test_core_mkdir__basic(void)
+{
+ cl_set_cleanup(cleanup_basic_dirs, NULL);
+
+ /* make a directory */
+ cl_assert(!git_path_isdir("d0"));
+ cl_git_pass(git_futils_mkdir("d0", NULL, 0755, 0));
+ cl_assert(git_path_isdir("d0"));
+
+ /* make a path */
+ cl_assert(!git_path_isdir("d1"));
+ cl_git_pass(git_futils_mkdir("d1/d1.1/d1.2", NULL, 0755, GIT_MKDIR_PATH));
+ cl_assert(git_path_isdir("d1"));
+ cl_assert(git_path_isdir("d1/d1.1"));
+ cl_assert(git_path_isdir("d1/d1.1/d1.2"));
+
+ /* make a dir exclusively */
+ cl_assert(!git_path_isdir("d2"));
+ cl_git_pass(git_futils_mkdir("d2", NULL, 0755, GIT_MKDIR_EXCL));
+ cl_assert(git_path_isdir("d2"));
+
+ /* make exclusive failure */
+ cl_git_fail(git_futils_mkdir("d2", NULL, 0755, GIT_MKDIR_EXCL));
+
+ /* make a path exclusively */
+ cl_assert(!git_path_isdir("d3"));
+ cl_git_pass(git_futils_mkdir("d3/d3.1/d3.2", NULL, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
+ cl_assert(git_path_isdir("d3"));
+ cl_assert(git_path_isdir("d3/d3.1/d3.2"));
+
+ /* make exclusive path failure */
+ cl_git_fail(git_futils_mkdir("d3/d3.1/d3.2", NULL, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
+ /* ??? Should EXCL only apply to the last item in the path? */
+
+ /* path with trailing slash? */
+ cl_assert(!git_path_isdir("d4"));
+ cl_git_pass(git_futils_mkdir("d4/d4.1/", NULL, 0755, GIT_MKDIR_PATH));
+ cl_assert(git_path_isdir("d4/d4.1"));
+}
+
+static void cleanup_basedir(void *ref)
+{
+ GIT_UNUSED(ref);
+ git_futils_rmdir_r("base", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+}
+
+void test_core_mkdir__with_base(void)
+{
+#define BASEDIR "base/dir/here"
+
+ cl_set_cleanup(cleanup_basedir, NULL);
+
+ cl_git_pass(git_futils_mkdir(BASEDIR, NULL, 0755, GIT_MKDIR_PATH));
+
+ cl_git_pass(git_futils_mkdir("a", BASEDIR, 0755, 0));
+ cl_assert(git_path_isdir(BASEDIR "/a"));
+
+ cl_git_pass(git_futils_mkdir("b/b1/b2", BASEDIR, 0755, GIT_MKDIR_PATH));
+ cl_assert(git_path_isdir(BASEDIR "/b/b1/b2"));
+
+ /* exclusive with existing base */
+ cl_git_pass(git_futils_mkdir("c/c1/c2", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
+
+ /* fail: exclusive with duplicated suffix */
+ cl_git_fail(git_futils_mkdir("c/c1/c3", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
+
+ /* fail: exclusive with any duplicated component */
+ cl_git_fail(git_futils_mkdir("c/cz/cz", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
+
+ /* success: exclusive without path */
+ cl_git_pass(git_futils_mkdir("c/c1/c3", BASEDIR, 0755, GIT_MKDIR_EXCL));
+
+ /* path with shorter base and existing dirs */
+ cl_git_pass(git_futils_mkdir("dir/here/d/", "base", 0755, GIT_MKDIR_PATH));
+ cl_assert(git_path_isdir("base/dir/here/d"));
+
+ /* fail: path with shorter base and existing dirs */
+ cl_git_fail(git_futils_mkdir("dir/here/e/", "base", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
+
+ /* fail: base with missing components */
+ cl_git_fail(git_futils_mkdir("f/", "base/missing", 0755, GIT_MKDIR_PATH));
+
+ /* success: shift missing component to path */
+ cl_git_pass(git_futils_mkdir("missing/f/", "base/", 0755, GIT_MKDIR_PATH));
+}
+
+static void cleanup_chmod_root(void *ref)
+{
+ mode_t *mode = ref;
+
+ if (*mode != 0) {
+ (void)p_umask(*mode);
+ git__free(mode);
+ }
+
+ git_futils_rmdir_r("r", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
+}
+
+static void check_mode(mode_t expected, mode_t actual)
+{
+#ifdef GIT_WIN32
+ /* chmod on Win32 doesn't support exec bit, not group/world bits */
+ cl_assert((expected & 0600) == (actual & 0777));
+#else
+ cl_assert(expected == (actual & 0777));
+#endif
+}
+
+void test_core_mkdir__chmods(void)
+{
+ struct stat st;
+ mode_t *old = git__malloc(sizeof(mode_t));
+ *old = p_umask(022);
+
+ cl_set_cleanup(cleanup_chmod_root, old);
+
+ cl_git_pass(git_futils_mkdir("r", NULL, 0777, 0));
+
+ cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH));
+
+ cl_git_pass(git_path_lstat("r/mode", &st));
+ check_mode(0755, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode/is", &st));
+ check_mode(0755, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode/is/important", &st));
+ check_mode(0755, st.st_mode);
+
+ cl_git_pass(git_futils_mkdir("mode2/is2/important2", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD));
+
+ cl_git_pass(git_path_lstat("r/mode2", &st));
+ check_mode(0755, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode2/is2", &st));
+ check_mode(0755, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode2/is2/important2", &st));
+ check_mode(0777, st.st_mode);
+
+ cl_git_pass(git_futils_mkdir("mode3/is3/important3", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH));
+
+ cl_git_pass(git_path_lstat("r/mode3", &st));
+ check_mode(0777, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode3/is3", &st));
+ check_mode(0777, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode3/is3/important3", &st));
+ check_mode(0777, st.st_mode);
+
+ /* test that we chmod existing dir */
+
+ cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD));
+
+ cl_git_pass(git_path_lstat("r/mode", &st));
+ check_mode(0755, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode/is", &st));
+ check_mode(0755, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode/is/important", &st));
+ check_mode(0777, st.st_mode);
+
+ /* test that we chmod even existing dirs if CHMOD_PATH is set */
+
+ cl_git_pass(git_futils_mkdir("mode2/is2/important2.1", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH));
+
+ cl_git_pass(git_path_lstat("r/mode2", &st));
+ check_mode(0777, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode2/is2", &st));
+ check_mode(0777, st.st_mode);
+ cl_git_pass(git_path_lstat("r/mode2/is2/important2.1", &st));
+ check_mode(0777, st.st_mode);
+}
diff --git a/tests-clar/core/oid.c b/tests-clar/core/oid.c
index c89713955..08791cce6 100644
--- a/tests-clar/core/oid.c
+++ b/tests-clar/core/oid.c
@@ -1,11 +1,17 @@
#include "clar_libgit2.h"
static git_oid id;
+static git_oid idp;
+static git_oid idm;
const char *str_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
+const char *str_oid_p = "ae90f12eea699729ed";
+const char *str_oid_m = "ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED";
void test_core_oid__initialize(void)
{
cl_git_pass(git_oid_fromstr(&id, str_oid));
+ cl_git_pass(git_oid_fromstrp(&idp, str_oid_p));
+ cl_git_fail(git_oid_fromstrp(&idm, str_oid_m));
}
void test_core_oid__streq(void)
@@ -15,4 +21,10 @@ void test_core_oid__streq(void)
cl_assert(git_oid_streq(&id, "deadbeef") == -1);
cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == -1);
+
+ cl_assert(git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000") == 0);
+ cl_assert(git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
+
+ cl_assert(git_oid_streq(&idp, "deadbeef") == -1);
+ cl_assert(git_oid_streq(&idp, "I'm not an oid.... :)") == -1);
}
diff --git a/tests-clar/core/opts.c b/tests-clar/core/opts.c
new file mode 100644
index 000000000..907339d51
--- /dev/null
+++ b/tests-clar/core/opts.c
@@ -0,0 +1,30 @@
+#include "clar_libgit2.h"
+#include "cache.h"
+
+void test_core_opts__readwrite(void)
+{
+ size_t old_val = 0;
+ size_t new_val = 0;
+
+ git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &old_val);
+ git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, (size_t)1234);
+ git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &new_val);
+
+ cl_assert(new_val == 1234);
+
+ git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, old_val);
+ git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &new_val);
+
+ cl_assert(new_val == old_val);
+
+ git_libgit2_opts(GIT_OPT_GET_ODB_CACHE_SIZE, &old_val);
+
+ cl_assert(old_val == GIT_DEFAULT_CACHE_SIZE);
+
+ git_libgit2_opts(GIT_OPT_SET_ODB_CACHE_SIZE, (size_t)GIT_DEFAULT_CACHE_SIZE*2);
+ git_libgit2_opts(GIT_OPT_GET_ODB_CACHE_SIZE, &new_val);
+
+ cl_assert(new_val == (GIT_DEFAULT_CACHE_SIZE*2));
+
+ git_libgit2_opts(GIT_OPT_GET_ODB_CACHE_SIZE, &old_val);
+}
diff --git a/tests-clar/core/path.c b/tests-clar/core/path.c
index d826612ac..407770baa 100644
--- a/tests-clar/core/path.c
+++ b/tests-clar/core/path.c
@@ -87,6 +87,15 @@ void test_core_path__00_dirname(void)
check_dirname(".git/", ".");
check_dirname(REP16("/abc"), REP15("/abc"));
+
+#ifdef GIT_WIN32
+ check_dirname("C:/path/", "C:/");
+ check_dirname("C:/path", "C:/");
+ check_dirname("//computername/path/", "//computername/");
+ check_dirname("//computername/path", "//computername/");
+ check_dirname("//computername/sub/path/", "//computername/sub");
+ check_dirname("//computername/sub/path", "//computername/sub");
+#endif
}
/* get the base name of a path */
@@ -315,7 +324,7 @@ static void check_fromurl(const char *expected_result, const char *input, int sh
git_buf_free(&buf);
}
-#ifdef _MSC_VER
+#ifdef GIT_WIN32
#define ABS_PATH_MARKER ""
#else
#define ABS_PATH_MARKER "/"
@@ -418,3 +427,54 @@ void test_core_path__13_cannot_prettify_a_non_existing_file(void)
git_buf_free(&p);
}
+
+void test_core_path__14_apply_relative(void)
+{
+ git_buf p = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_sets(&p, "/this/is/a/base"));
+
+ cl_git_pass(git_path_apply_relative(&p, "../test"));
+ cl_assert_equal_s("/this/is/a/test", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "../../the/./end"));
+ cl_assert_equal_s("/this/is/the/end", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "./of/this/../the/string"));
+ cl_assert_equal_s("/this/is/the/end/of/the/string", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "../../../../../.."));
+ cl_assert_equal_s("/this/", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "../../../../../"));
+ cl_assert_equal_s("/", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "../../../../.."));
+ cl_assert_equal_s("/", p.ptr);
+
+
+ cl_git_pass(git_buf_sets(&p, "d:/another/test"));
+
+ cl_git_pass(git_path_apply_relative(&p, "../../../../.."));
+ cl_assert_equal_s("d:/", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "from/here/to/../and/./back/."));
+ cl_assert_equal_s("d:/from/here/and/back/", p.ptr);
+
+
+ cl_git_pass(git_buf_sets(&p, "https://my.url.com/test.git"));
+
+ cl_git_pass(git_path_apply_relative(&p, "../another.git"));
+ cl_assert_equal_s("https://my.url.com/another.git", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "../full/path/url.patch"));
+ cl_assert_equal_s("https://my.url.com/full/path/url.patch", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, ".."));
+ cl_assert_equal_s("https://my.url.com/full/path/", p.ptr);
+
+ cl_git_pass(git_path_apply_relative(&p, "../../../../../"));
+ cl_assert_equal_s("https://", p.ptr);
+
+ git_buf_free(&p);
+}
diff --git a/tests-clar/core/pool.c b/tests-clar/core/pool.c
index 5ed97366f..c42bb6da0 100644
--- a/tests-clar/core/pool.c
+++ b/tests-clar/core/pool.c
@@ -83,3 +83,53 @@ void test_core_pool__2(void)
git_pool_clear(&p);
}
+
+void test_core_pool__free_list(void)
+{
+ int i;
+ git_pool p;
+ void *ptr, *ptrs[50];
+
+ cl_git_pass(git_pool_init(&p, 100, 100));
+
+ for (i = 0; i < 10; ++i) {
+ ptr = git_pool_malloc(&p, 1);
+ cl_assert(ptr != NULL);
+ }
+ cl_assert_equal_i(10, (int)p.items);
+
+ for (i = 0; i < 50; ++i) {
+ ptrs[i] = git_pool_malloc(&p, 1);
+ cl_assert(ptrs[i] != NULL);
+ }
+ cl_assert_equal_i(60, (int)p.items);
+
+ git_pool_free(&p, ptr);
+ cl_assert_equal_i(60, (int)p.items);
+
+ git_pool_free_array(&p, 50, ptrs);
+ cl_assert_equal_i(60, (int)p.items);
+
+ for (i = 0; i < 50; ++i) {
+ ptrs[i] = git_pool_malloc(&p, 1);
+ cl_assert(ptrs[i] != NULL);
+ }
+ cl_assert_equal_i(60, (int)p.items);
+
+ for (i = 0; i < 111; ++i) {
+ ptr = git_pool_malloc(&p, 1);
+ cl_assert(ptr != NULL);
+ }
+ cl_assert_equal_i(170, (int)p.items);
+
+ git_pool_free_array(&p, 50, ptrs);
+ cl_assert_equal_i(170, (int)p.items);
+
+ for (i = 0; i < 50; ++i) {
+ ptrs[i] = git_pool_malloc(&p, 1);
+ cl_assert(ptrs[i] != NULL);
+ }
+ cl_assert_equal_i(170, (int)p.items);
+
+ git_pool_clear(&p);
+}
diff --git a/tests-clar/core/rmdir.c b/tests-clar/core/rmdir.c
index 530f1f908..f0b0bfa42 100644
--- a/tests-clar/core/rmdir.c
+++ b/tests-clar/core/rmdir.c
@@ -30,7 +30,7 @@ void test_core_rmdir__initialize(void)
/* make sure empty dir can be deleted recusively */
void test_core_rmdir__delete_recursive(void)
{
- cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
+ cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
}
/* make sure non-empty dir cannot be deleted recusively */
@@ -42,15 +42,15 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
cl_git_mkfile(git_buf_cstr(&file), "dummy");
- cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
+ cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
cl_must_pass(p_unlink(file.ptr));
- cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
+ cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
git_buf_free(&file);
}
-void test_core_rmdir__can_skip__non_empty_dir(void)
+void test_core_rmdir__can_skip_non_empty_dir(void)
{
git_buf file = GIT_BUF_INIT;
@@ -58,11 +58,41 @@ void test_core_rmdir__can_skip__non_empty_dir(void)
cl_git_mkfile(git_buf_cstr(&file), "dummy");
- cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_ONLY_EMPTY_DIRS));
+ cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY));
cl_assert(git_path_exists(git_buf_cstr(&file)) == true);
- cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(git_path_exists(empty_tmp_dir) == false);
git_buf_free(&file);
}
+
+void test_core_rmdir__can_remove_empty_parents(void)
+{
+ git_buf file = GIT_BUF_INIT;
+
+ cl_git_pass(
+ git_buf_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
+ cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_assert(git_path_isfile(git_buf_cstr(&file)));
+
+ cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir,
+ GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS));
+
+ cl_assert(!git_path_exists(git_buf_cstr(&file)));
+
+ git_buf_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
+ cl_assert(!git_path_exists(git_buf_cstr(&file)));
+
+ git_buf_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
+ cl_assert(!git_path_exists(git_buf_cstr(&file)));
+
+ git_buf_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
+ cl_assert(git_path_exists(git_buf_cstr(&file)));
+
+ cl_assert(git_path_exists(empty_tmp_dir) == true);
+
+ git_buf_free(&file);
+
+ cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
+}
diff --git a/tests-clar/core/stat.c b/tests-clar/core/stat.c
new file mode 100644
index 000000000..2e4abfb79
--- /dev/null
+++ b/tests-clar/core/stat.c
@@ -0,0 +1,97 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "path.h"
+#include "posix.h"
+
+void test_core_stat__initialize(void)
+{
+ cl_git_pass(git_futils_mkdir("root/d1/d2", NULL, 0755, GIT_MKDIR_PATH));
+ cl_git_mkfile("root/file", "whatever\n");
+ cl_git_mkfile("root/d1/file", "whatever\n");
+}
+
+void test_core_stat__cleanup(void)
+{
+ git_futils_rmdir_r("root", NULL, GIT_RMDIR_REMOVE_FILES);
+}
+
+#define cl_assert_error(val) \
+ do { err = errno; cl_assert_equal_i((val), err); } while (0)
+
+void test_core_stat__0(void)
+{
+ struct stat st;
+ int err;
+
+ cl_assert_equal_i(0, p_lstat("root", &st));
+ cl_assert(S_ISDIR(st.st_mode));
+ cl_assert_error(0);
+
+ cl_assert_equal_i(0, p_lstat("root/", &st));
+ cl_assert(S_ISDIR(st.st_mode));
+ cl_assert_error(0);
+
+ cl_assert_equal_i(0, p_lstat("root/file", &st));
+ cl_assert(S_ISREG(st.st_mode));
+ cl_assert_error(0);
+
+ cl_assert_equal_i(0, p_lstat("root/d1", &st));
+ cl_assert(S_ISDIR(st.st_mode));
+ cl_assert_error(0);
+
+ cl_assert_equal_i(0, p_lstat("root/d1/", &st));
+ cl_assert(S_ISDIR(st.st_mode));
+ cl_assert_error(0);
+
+ cl_assert_equal_i(0, p_lstat("root/d1/file", &st));
+ cl_assert(S_ISREG(st.st_mode));
+ cl_assert_error(0);
+
+ cl_assert(p_lstat("root/missing", &st) < 0);
+ cl_assert_error(ENOENT);
+
+ cl_assert(p_lstat("root/missing/but/could/be/created", &st) < 0);
+ cl_assert_error(ENOENT);
+
+ cl_assert(p_lstat_posixly("root/missing/but/could/be/created", &st) < 0);
+ cl_assert_error(ENOENT);
+
+ cl_assert(p_lstat("root/d1/missing", &st) < 0);
+ cl_assert_error(ENOENT);
+
+ cl_assert(p_lstat("root/d1/missing/deeper/path", &st) < 0);
+ cl_assert_error(ENOENT);
+
+ cl_assert(p_lstat_posixly("root/d1/missing/deeper/path", &st) < 0);
+ cl_assert_error(ENOENT);
+
+ cl_assert(p_lstat_posixly("root/d1/file/deeper/path", &st) < 0);
+ cl_assert_error(ENOTDIR);
+
+ cl_assert(p_lstat("root/file/invalid", &st) < 0);
+#ifdef GIT_WIN32
+ cl_assert_error(ENOENT);
+#else
+ cl_assert_error(ENOTDIR);
+#endif
+
+ cl_assert(p_lstat_posixly("root/file/invalid", &st) < 0);
+ cl_assert_error(ENOTDIR);
+
+ cl_assert(p_lstat("root/file/invalid/deeper_path", &st) < 0);
+#ifdef GIT_WIN32
+ cl_assert_error(ENOENT);
+#else
+ cl_assert_error(ENOTDIR);
+#endif
+
+ cl_assert(p_lstat_posixly("root/file/invalid/deeper_path", &st) < 0);
+ cl_assert_error(ENOTDIR);
+
+ cl_assert(p_lstat_posixly("root/d1/file/extra", &st) < 0);
+ cl_assert_error(ENOTDIR);
+
+ cl_assert(p_lstat_posixly("root/d1/file/further/invalid/items", &st) < 0);
+ cl_assert_error(ENOTDIR);
+}
+
diff --git a/tests-clar/core/vector.c b/tests-clar/core/vector.c
index ef3d6c36d..c9e43a149 100644
--- a/tests-clar/core/vector.c
+++ b/tests-clar/core/vector.c
@@ -189,3 +189,87 @@ void test_core_vector__5(void)
git_vector_free(&x);
}
+
+static int remove_ones(const git_vector *v, size_t idx)
+{
+ return (git_vector_get(v, idx) == (void *)0x001);
+}
+
+/* Test removal based on callback */
+void test_core_vector__remove_matching(void)
+{
+ git_vector x;
+ size_t i;
+ void *compare;
+
+ git_vector_init(&x, 1, NULL);
+ git_vector_insert(&x, (void*) 0x001);
+
+ cl_assert(x.length == 1);
+ git_vector_remove_matching(&x, remove_ones);
+ cl_assert(x.length == 0);
+
+ git_vector_insert(&x, (void*) 0x001);
+ git_vector_insert(&x, (void*) 0x001);
+ git_vector_insert(&x, (void*) 0x001);
+
+ cl_assert(x.length == 3);
+ git_vector_remove_matching(&x, remove_ones);
+ cl_assert(x.length == 0);
+
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x001);
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x001);
+
+ cl_assert(x.length == 4);
+ git_vector_remove_matching(&x, remove_ones);
+ cl_assert(x.length == 2);
+
+ git_vector_foreach(&x, i, compare) {
+ cl_assert(compare != (void *)0x001);
+ }
+
+ git_vector_clear(&x);
+
+ git_vector_insert(&x, (void*) 0x001);
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x001);
+
+ cl_assert(x.length == 4);
+ git_vector_remove_matching(&x, remove_ones);
+ cl_assert(x.length == 2);
+
+ git_vector_foreach(&x, i, compare) {
+ cl_assert(compare != (void *)0x001);
+ }
+
+ git_vector_clear(&x);
+
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x001);
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x001);
+
+ cl_assert(x.length == 4);
+ git_vector_remove_matching(&x, remove_ones);
+ cl_assert(x.length == 2);
+
+ git_vector_foreach(&x, i, compare) {
+ cl_assert(compare != (void *)0x001);
+ }
+
+ git_vector_clear(&x);
+
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x003);
+ git_vector_insert(&x, (void*) 0x002);
+ git_vector_insert(&x, (void*) 0x003);
+
+ cl_assert(x.length == 4);
+ git_vector_remove_matching(&x, remove_ones);
+ cl_assert(x.length == 4);
+
+ git_vector_free(&x);
+}
diff --git a/tests-clar/date/date.c b/tests-clar/date/date.c
new file mode 100644
index 000000000..88881d1e1
--- /dev/null
+++ b/tests-clar/date/date.c
@@ -0,0 +1,15 @@
+#include "clar_libgit2.h"
+
+#include "util.h"
+
+void test_date_date__overflow(void)
+{
+#ifdef __LP64__
+ git_time_t d2038, d2039;
+
+ /* This is expected to fail on a 32-bit machine. */
+ cl_git_pass(git__date_parse(&d2038, "2038-1-1"));
+ cl_git_pass(git__date_parse(&d2039, "2039-1-1"));
+ cl_assert(d2038 < d2039);
+#endif
+}
diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c
index 6d7ad41d6..2ac8dbc51 100644
--- a/tests-clar/diff/blob.c
+++ b/tests-clar/diff/blob.c
@@ -12,15 +12,15 @@ void test_diff_blob__initialize(void)
g_repo = cl_git_sandbox_init("attr");
- memset(&opts, 0, sizeof(opts));
+ GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION);
opts.context_lines = 1;
- opts.interhunk_lines = 1;
+ opts.interhunk_lines = 0;
memset(&expected, 0, sizeof(expected));
/* tests/resources/attr/root_test4.txt */
- cl_git_pass(git_oid_fromstrn(&oid, "fe773770c5a6", 12));
- cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 6));
+ cl_git_pass(git_oid_fromstrn(&oid, "a0f7217a", 8));
+ cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 4));
/* alien.png */
cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8));
@@ -30,7 +30,10 @@ void test_diff_blob__initialize(void)
void test_diff_blob__cleanup(void)
{
git_blob_free(d);
+ d = NULL;
+
git_blob_free(alien);
+ alien = NULL;
cl_git_sandbox_cleanup();
}
@@ -54,62 +57,63 @@ void test_diff_blob__can_compare_text_blobs(void)
/* Doing the equivalent of a `git diff -U1` on these files */
+ /* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_diff_blobs(
- a, b, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ a, b, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_mods == 1);
- cl_assert(expected.at_least_one_of_them_is_binary == false);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected.files_binary);
- cl_assert(expected.hunks == 1);
- cl_assert(expected.lines == 6);
- cl_assert(expected.line_ctxt == 1);
- cl_assert(expected.line_adds == 5);
- cl_assert(expected.line_dels == 0);
+ cl_assert_equal_i(1, expected.hunks);
+ cl_assert_equal_i(6, expected.lines);
+ cl_assert_equal_i(1, expected.line_ctxt);
+ cl_assert_equal_i(5, expected.line_adds);
+ cl_assert_equal_i(0, expected.line_dels);
+ /* diff on tests/resources/attr/root_test2 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- b, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ b, c, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_mods == 1);
- cl_assert(expected.at_least_one_of_them_is_binary == false);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected.files_binary);
- cl_assert(expected.hunks == 1);
- cl_assert(expected.lines == 15);
- cl_assert(expected.line_ctxt == 3);
- cl_assert(expected.line_adds == 9);
- cl_assert(expected.line_dels == 3);
+ cl_assert_equal_i(1, expected.hunks);
+ cl_assert_equal_i(15, expected.lines);
+ cl_assert_equal_i(3, expected.line_ctxt);
+ cl_assert_equal_i(9, expected.line_adds);
+ cl_assert_equal_i(3, expected.line_dels);
+ /* diff on tests/resources/attr/root_test3 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- a, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ a, c, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_mods == 1);
- cl_assert(expected.at_least_one_of_them_is_binary == false);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected.files_binary);
- cl_assert(expected.hunks == 1);
- cl_assert(expected.lines == 13);
- cl_assert(expected.line_ctxt == 0);
- cl_assert(expected.line_adds == 12);
- cl_assert(expected.line_dels == 1);
-
- opts.context_lines = 1;
+ cl_assert_equal_i(1, expected.hunks);
+ cl_assert_equal_i(13, expected.lines);
+ cl_assert_equal_i(0, expected.line_ctxt);
+ cl_assert_equal_i(12, expected.line_adds);
+ cl_assert_equal_i(1, expected.line_dels);
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- c, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ c, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_mods == 1);
- cl_assert(expected.at_least_one_of_them_is_binary == false);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected.files_binary);
- cl_assert(expected.hunks == 2);
- cl_assert(expected.lines == 14);
- cl_assert(expected.line_ctxt == 4);
- cl_assert(expected.line_adds == 6);
- cl_assert(expected.line_dels == 4);
+ cl_assert_equal_i(2, expected.hunks);
+ cl_assert_equal_i(14, expected.lines);
+ cl_assert_equal_i(4, expected.line_ctxt);
+ cl_assert_equal_i(6, expected.line_adds);
+ cl_assert_equal_i(4, expected.line_dels);
git_blob_free(a);
git_blob_free(b);
@@ -121,97 +125,95 @@ void test_diff_blob__can_compare_against_null_blobs(void)
git_blob *e = NULL;
cl_git_pass(git_diff_blobs(
- d, e, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ d, e, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_dels == 1);
- cl_assert(expected.at_least_one_of_them_is_binary == false);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(0, expected.files_binary);
- cl_assert(expected.hunks == 1);
- cl_assert(expected.hunk_old_lines == 14);
- cl_assert(expected.lines == 14);
- cl_assert(expected.line_dels == 14);
+ cl_assert_equal_i(1, expected.hunks);
+ cl_assert_equal_i(14, expected.hunk_old_lines);
+ cl_assert_equal_i(14, expected.lines);
+ cl_assert_equal_i(14, expected.line_dels);
opts.flags |= GIT_DIFF_REVERSE;
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- d, e, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ d, e, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_adds == 1);
- cl_assert(expected.at_least_one_of_them_is_binary == false);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expected.files_binary);
- cl_assert(expected.hunks == 1);
- cl_assert(expected.hunk_new_lines == 14);
- cl_assert(expected.lines == 14);
- cl_assert(expected.line_adds == 14);
+ cl_assert_equal_i(1, expected.hunks);
+ cl_assert_equal_i(14, expected.hunk_new_lines);
+ cl_assert_equal_i(14, expected.lines);
+ cl_assert_equal_i(14, expected.line_adds);
opts.flags ^= GIT_DIFF_REVERSE;
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- alien, NULL, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ alien, NULL, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.at_least_one_of_them_is_binary == true);
-
- cl_assert(expected.files == 1);
- cl_assert(expected.file_dels == 1);
- cl_assert(expected.hunks == 0);
- cl_assert(expected.lines == 0);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.files_binary);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(0, expected.hunks);
+ cl_assert_equal_i(0, expected.lines);
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- NULL, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
-
- cl_assert(expected.at_least_one_of_them_is_binary == true);
+ NULL, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.files == 1);
- cl_assert(expected.file_adds == 1);
- cl_assert(expected.hunks == 0);
- cl_assert(expected.lines == 0);
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.files_binary);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expected.hunks);
+ cl_assert_equal_i(0, expected.lines);
}
-static void assert_identical_blobs_comparison(diff_expects expected)
+static void assert_identical_blobs_comparison(diff_expects *expected)
{
- cl_assert(expected.files == 1);
- cl_assert(expected.file_unmodified == 1);
- cl_assert(expected.hunks == 0);
- cl_assert(expected.lines == 0);
+ cl_assert_equal_i(1, expected->files);
+ cl_assert_equal_i(1, expected->file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(0, expected->hunks);
+ cl_assert_equal_i(0, expected->lines);
}
void test_diff_blob__can_compare_identical_blobs(void)
{
cl_git_pass(git_diff_blobs(
- d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.at_least_one_of_them_is_binary == false);
- assert_identical_blobs_comparison(expected);
+ cl_assert_equal_i(0, expected.files_binary);
+ assert_identical_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- NULL, NULL, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ NULL, NULL, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.at_least_one_of_them_is_binary == false);
- assert_identical_blobs_comparison(expected);
+ cl_assert_equal_i(0, expected.files_binary);
+ cl_assert_equal_i(0, expected.files); /* NULLs mean no callbacks, period */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- alien, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ alien, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- cl_assert(expected.at_least_one_of_them_is_binary == true);
- assert_identical_blobs_comparison(expected);
+ cl_assert(expected.files_binary > 0);
+ assert_identical_blobs_comparison(&expected);
}
-static void assert_binary_blobs_comparison(diff_expects expected)
+static void assert_binary_blobs_comparison(diff_expects *expected)
{
- cl_assert(expected.at_least_one_of_them_is_binary == true);
+ cl_assert(expected->files_binary > 0);
- cl_assert(expected.files == 1);
- cl_assert(expected.file_mods == 1);
- cl_assert(expected.hunks == 0);
- cl_assert(expected.lines == 0);
+ cl_assert_equal_i(1, expected->files);
+ cl_assert_equal_i(1, expected->file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected->hunks);
+ cl_assert_equal_i(0, expected->lines);
}
void test_diff_blob__can_compare_two_binary_blobs(void)
@@ -224,16 +226,16 @@ void test_diff_blob__can_compare_two_binary_blobs(void)
cl_git_pass(git_blob_lookup_prefix(&heart, g_repo, &h_oid, 4));
cl_git_pass(git_diff_blobs(
- alien, heart, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ alien, heart, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- assert_binary_blobs_comparison(expected);
+ assert_binary_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- heart, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ heart, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
- assert_binary_blobs_comparison(expected);
+ assert_binary_blobs_comparison(&expected);
git_blob_free(heart);
}
@@ -241,14 +243,289 @@ void test_diff_blob__can_compare_two_binary_blobs(void)
void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void)
{
cl_git_pass(git_diff_blobs(
- alien, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ alien, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ assert_binary_blobs_comparison(&expected);
+
+ memset(&expected, 0, sizeof(expected));
+
+ cl_git_pass(git_diff_blobs(
+ d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ assert_binary_blobs_comparison(&expected);
+}
+
+/*
+ * $ git diff fe773770 a0f7217
+ * diff --git a/fe773770 b/a0f7217
+ * index fe77377..a0f7217 100644
+ * --- a/fe773770
+ * +++ b/a0f7217
+ * @@ -1,6 +1,6 @@
+ * Here is some stuff at the start
+ *
+ * -This should go in one hunk
+ * +This should go in one hunk (first)
+ *
+ * Some additional lines
+ *
+ * @@ -8,7 +8,7 @@ Down here below the other lines
+ *
+ * With even more at the end
+ *
+ * -Followed by a second hunk of stuff
+ * +Followed by a second hunk of stuff (second)
+ *
+ * That happens down here
+ */
+void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
+{
+ git_blob *old_d;
+ git_oid old_d_oid;
+
+ opts.context_lines = 3;
+
+ /* tests/resources/attr/root_test1 from commit f5b0af1 */
+ cl_git_pass(git_oid_fromstrn(&old_d_oid, "fe773770", 8));
+ cl_git_pass(git_blob_lookup_prefix(&old_d, g_repo, &old_d_oid, 4));
+
+ /* Test with default inter-hunk-context (not set) => default is 0 */
+ cl_git_pass(git_diff_blobs(
+ old_d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ cl_assert_equal_i(2, expected.hunks);
+
+ /* Test with inter-hunk-context explicitly set to 0 */
+ opts.interhunk_lines = 0;
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blobs(
+ old_d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ cl_assert_equal_i(2, expected.hunks);
+
+ /* Test with inter-hunk-context explicitly set to 1 */
+ opts.interhunk_lines = 1;
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blobs(
+ old_d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ cl_assert_equal_i(1, expected.hunks);
+
+ git_blob_free(old_d);
+}
+
+void test_diff_blob__checks_options_version_too_low(void)
+{
+ const git_error *err;
+
+ opts.version = 0;
+ cl_git_fail(git_diff_blobs(
+ d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+}
+
+void test_diff_blob__checks_options_version_too_high(void)
+{
+ const git_error *err;
+
+ opts.version = 1024;
+ cl_git_fail(git_diff_blobs(
+ d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+}
+
+void test_diff_blob__can_correctly_detect_a_binary_blob_as_binary(void)
+{
+ /* alien.png */
+ cl_assert_equal_i(true, git_blob_is_binary(alien));
+}
+
+void test_diff_blob__can_correctly_detect_a_textual_blob_as_non_binary(void)
+{
+ /* tests/resources/attr/root_test4.txt */
+ cl_assert_equal_i(false, git_blob_is_binary(d));
+}
+
+/*
+ * git_diff_blob_to_buffer tests
+ */
+
+static void assert_changed_single_one_line_file(
+ diff_expects *expected, git_delta_t mod)
+{
+ cl_assert_equal_i(1, expected->files);
+ cl_assert_equal_i(1, expected->file_status[mod]);
+ cl_assert_equal_i(1, expected->hunks);
+ cl_assert_equal_i(1, expected->lines);
+
+ if (mod == GIT_DELTA_ADDED)
+ cl_assert_equal_i(1, expected->line_adds);
+ else if (mod == GIT_DELTA_DELETED)
+ cl_assert_equal_i(1, expected->line_dels);
+}
+
+void test_diff_blob__can_compare_blob_to_buffer(void)
+{
+ git_blob *a;
+ git_oid a_oid;
+ const char *a_content = "Hello from the root\n";
+ const char *b_content = "Hello from the root\n\nSome additional lines\n\nDown here below\n\n";
+
+ /* tests/resources/attr/root_test1 */
+ cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8));
+ cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
+
+ /* diff from blob a to content of b */
+ cl_git_pass(git_diff_blob_to_buffer(
+ a, b_content, strlen(b_content),
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ cl_assert_equal_i(1, expected.files);
+ cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected.files_binary);
+ cl_assert_equal_i(1, expected.hunks);
+ cl_assert_equal_i(6, expected.lines);
+ cl_assert_equal_i(1, expected.line_ctxt);
+ cl_assert_equal_i(5, expected.line_adds);
+ cl_assert_equal_i(0, expected.line_dels);
+
+ /* diff from blob a to content of a */
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ a, a_content, strlen(a_content),
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ assert_identical_blobs_comparison(&expected);
+
+ /* diff from NULL blob to content of a */
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ NULL, a_content, strlen(a_content),
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ assert_changed_single_one_line_file(&expected, GIT_DELTA_ADDED);
+
+ /* diff from blob a to NULL buffer */
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ a, NULL, 0,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ assert_changed_single_one_line_file(&expected, GIT_DELTA_DELETED);
+
+ /* diff with reverse */
+ opts.flags ^= GIT_DIFF_REVERSE;
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ a, NULL, 0,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+
+ assert_changed_single_one_line_file(&expected, GIT_DELTA_ADDED);
+
+ git_blob_free(a);
+}
+
+
+static void assert_one_modified_with_lines(diff_expects *expected, int lines)
+{
+ cl_assert_equal_i(1, expected->files);
+ cl_assert_equal_i(1, expected->file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expected->files_binary);
+ cl_assert_equal_i(lines, expected->lines);
+}
+
+void test_diff_blob__binary_data_comparisons(void)
+{
+ git_blob *bin, *nonbin;
+ git_oid oid;
+ const char *nonbin_content = "Hello from the root\n";
+ size_t nonbin_len = 20;
+ const char *bin_content = "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n";
+ size_t bin_len = 33;
+
+ cl_git_pass(git_oid_fromstrn(&oid, "45141a79", 8));
+ cl_git_pass(git_blob_lookup_prefix(&nonbin, g_repo, &oid, 4));
+
+ cl_git_pass(git_oid_fromstrn(&oid, "b435cd56", 8));
+ cl_git_pass(git_blob_lookup_prefix(&bin, g_repo, &oid, 4));
+
+ /* non-binary to reference content */
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ nonbin, nonbin_content, nonbin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_identical_blobs_comparison(&expected);
+ cl_assert_equal_i(0, expected.files_binary);
+
+ /* binary to reference content */
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ bin, bin_content, bin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_identical_blobs_comparison(&expected);
+
+ cl_assert_equal_i(1, expected.files_binary);
+
+ /* non-binary to binary content */
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ nonbin, bin_content, bin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_binary_blobs_comparison(&expected);
+
+ /* binary to non-binary content */
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ bin, nonbin_content, nonbin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_binary_blobs_comparison(&expected);
+
+ /* non-binary to binary blob */
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blobs(
+ bin, nonbin, &opts,
+ diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_binary_blobs_comparison(&expected);
- assert_binary_blobs_comparison(expected);
+ /*
+ * repeat with FORCE_TEXT
+ */
+
+ opts.flags |= GIT_DIFF_FORCE_TEXT;
+
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ bin, bin_content, bin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_identical_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ nonbin, bin_content, bin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified_with_lines(&expected, 4);
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blob_to_buffer(
+ bin, nonbin_content, nonbin_len,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified_with_lines(&expected, 4);
+
+ memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
- d, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ bin, nonbin, &opts,
+ diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified_with_lines(&expected, 4);
- assert_binary_blobs_comparison(expected);
+ /* cleanup */
+ git_blob_free(bin);
+ git_blob_free(nonbin);
}
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c
index 8587be9b1..19c005e2e 100644
--- a/tests-clar/diff/diff_helpers.c
+++ b/tests-clar/diff/diff_helpers.c
@@ -5,7 +5,7 @@ git_tree *resolve_commit_oid_to_tree(
git_repository *repo,
const char *partial_oid)
{
- unsigned int len = (unsigned int)strlen(partial_oid);
+ size_t len = strlen(partial_oid);
git_oid oid;
git_object *obj = NULL;
git_tree *tree = NULL;
@@ -21,38 +21,45 @@ git_tree *resolve_commit_oid_to_tree(
return tree;
}
-int diff_file_fn(
- void *cb_data,
- git_diff_delta *delta,
- float progress)
+int diff_file_cb(
+ const git_diff_delta *delta,
+ float progress,
+ void *payload)
{
- diff_expects *e = cb_data;
+ diff_expects *e = payload;
GIT_UNUSED(progress);
- e-> at_least_one_of_them_is_binary = delta->binary;
-
e->files++;
- switch (delta->status) {
- case GIT_DELTA_ADDED: e->file_adds++; break;
- case GIT_DELTA_DELETED: e->file_dels++; break;
- case GIT_DELTA_MODIFIED: e->file_mods++; break;
- case GIT_DELTA_IGNORED: e->file_ignored++; break;
- case GIT_DELTA_UNTRACKED: e->file_untracked++; break;
- case GIT_DELTA_UNMODIFIED: e->file_unmodified++; break;
- default: break;
- }
+
+ if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
+ e->files_binary++;
+
+ cl_assert(delta->status <= GIT_DELTA_TYPECHANGE);
+
+ e->file_status[delta->status] += 1;
+
return 0;
}
-int diff_hunk_fn(
- void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+int diff_print_file_cb(
+ const git_diff_delta *delta,
+ float progress,
+ void *payload)
+{
+ fprintf(stderr, "%c %s\n",
+ git_diff_status_char(delta->status), delta->old_file.path);
+ return diff_file_cb(delta, progress, payload);
+}
+
+int diff_hunk_cb(
+ const git_diff_delta *delta,
+ const git_diff_range *range,
const char *header,
- size_t header_len)
+ size_t header_len,
+ void *payload)
{
- diff_expects *e = cb_data;
+ diff_expects *e = payload;
GIT_UNUSED(delta);
GIT_UNUSED(header);
@@ -64,15 +71,15 @@ int diff_hunk_fn(
return 0;
}
-int diff_line_fn(
- void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+int diff_line_cb(
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *content,
- size_t content_len)
+ size_t content_len,
+ void *payload)
{
- diff_expects *e = cb_data;
+ diff_expects *e = payload;
GIT_UNUSED(delta);
GIT_UNUSED(range);
@@ -85,11 +92,17 @@ int diff_line_fn(
e->line_ctxt++;
break;
case GIT_DIFF_LINE_ADDITION:
+ e->line_adds++;
+ break;
case GIT_DIFF_LINE_ADD_EOFNL:
+ /* technically not a line add, but we'll count it as such */
e->line_adds++;
break;
case GIT_DIFF_LINE_DELETION:
+ e->line_dels++;
+ break;
case GIT_DIFF_LINE_DEL_EOFNL:
+ /* technically not a line delete, but we'll count it as such */
e->line_dels++;
break;
default:
@@ -97,3 +110,103 @@ int diff_line_fn(
}
return 0;
}
+
+int diff_foreach_via_iterator(
+ git_diff_list *diff,
+ git_diff_file_cb file_cb,
+ git_diff_hunk_cb hunk_cb,
+ git_diff_data_cb line_cb,
+ void *data)
+{
+ size_t d, num_d = git_diff_num_deltas(diff);
+
+ for (d = 0; d < num_d; ++d) {
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+ size_t h, num_h;
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+ cl_assert(delta);
+
+ /* call file_cb for this file */
+ if (file_cb != NULL && file_cb(delta, (float)d / num_d, data) != 0) {
+ git_diff_patch_free(patch);
+ goto abort;
+ }
+
+ /* if there are no changes, then the patch will be NULL */
+ if (!patch) {
+ cl_assert(delta->status == GIT_DELTA_UNMODIFIED ||
+ (delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
+ continue;
+ }
+
+ if (!hunk_cb && !line_cb) {
+ git_diff_patch_free(patch);
+ continue;
+ }
+
+ num_h = git_diff_patch_num_hunks(patch);
+
+ for (h = 0; h < num_h; h++) {
+ const git_diff_range *range;
+ const char *hdr;
+ size_t hdr_len, l, num_l;
+
+ cl_git_pass(git_diff_patch_get_hunk(
+ &range, &hdr, &hdr_len, &num_l, patch, h));
+
+ if (hunk_cb && hunk_cb(delta, range, hdr, hdr_len, data) != 0) {
+ git_diff_patch_free(patch);
+ goto abort;
+ }
+
+ for (l = 0; l < num_l; ++l) {
+ char origin;
+ const char *line;
+ size_t line_len;
+ int old_lineno, new_lineno;
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &line, &line_len, &old_lineno, &new_lineno,
+ patch, h, l));
+
+ if (line_cb &&
+ line_cb(delta, range, origin, line, line_len, data) != 0) {
+ git_diff_patch_free(patch);
+ goto abort;
+ }
+ }
+ }
+
+ git_diff_patch_free(patch);
+ }
+
+ return 0;
+
+abort:
+ giterr_clear();
+ return GIT_EUSER;
+}
+
+static int diff_print_cb(
+ const git_diff_delta *delta,
+ const git_diff_range *range,
+ char line_origin, /**< GIT_DIFF_LINE_... value from above */
+ const char *content,
+ size_t content_len,
+ void *payload)
+{
+ GIT_UNUSED(payload);
+ GIT_UNUSED(delta);
+ GIT_UNUSED(range);
+ GIT_UNUSED(line_origin);
+ GIT_UNUSED(content_len);
+ fputs(content, (FILE *)payload);
+ return 0;
+}
+
+void diff_print(FILE *fp, git_diff_list *diff)
+{
+ cl_git_pass(git_diff_print_patch(diff, diff_print_cb, fp ? fp : stderr));
+}
diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h
index 0aaa6c111..674fd8e19 100644
--- a/tests-clar/diff/diff_helpers.h
+++ b/tests-clar/diff/diff_helpers.h
@@ -6,12 +6,9 @@ extern git_tree *resolve_commit_oid_to_tree(
typedef struct {
int files;
- int file_adds;
- int file_dels;
- int file_mods;
- int file_ignored;
- int file_untracked;
- int file_unmodified;
+ int files_binary;
+
+ int file_status[10]; /* indexed by git_delta_t value */
int hunks;
int hunk_new_lines;
@@ -21,27 +18,44 @@ typedef struct {
int line_ctxt;
int line_adds;
int line_dels;
-
- bool at_least_one_of_them_is_binary;
} diff_expects;
-extern int diff_file_fn(
- void *cb_data,
- git_diff_delta *delta,
- float progress);
-
-extern int diff_hunk_fn(
- void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+typedef struct {
+ const char *path;
+ const char *matched_pathspec;
+} notify_expected;
+
+extern int diff_file_cb(
+ const git_diff_delta *delta,
+ float progress,
+ void *cb_data);
+
+extern int diff_print_file_cb(
+ const git_diff_delta *delta,
+ float progress,
+ void *cb_data);
+
+extern int diff_hunk_cb(
+ const git_diff_delta *delta,
+ const git_diff_range *range,
const char *header,
- size_t header_len);
+ size_t header_len,
+ void *cb_data);
-extern int diff_line_fn(
- void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+extern int diff_line_cb(
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *content,
- size_t content_len);
+ size_t content_len,
+ void *cb_data);
+
+extern int diff_foreach_via_iterator(
+ git_diff_list *diff,
+ git_diff_file_cb file_cb,
+ git_diff_hunk_cb hunk_cb,
+ git_diff_data_cb line_cb,
+ void *data);
+
+extern void diff_print(FILE *fp, git_diff_list *diff);
diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c
new file mode 100644
index 000000000..932d720f2
--- /dev/null
+++ b/tests-clar/diff/diffiter.c
@@ -0,0 +1,465 @@
+#include "clar_libgit2.h"
+#include "diff_helpers.h"
+
+void test_diff_diffiter__initialize(void)
+{
+}
+
+void test_diff_diffiter__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_diff_diffiter__create(void)
+{
+ git_repository *repo = cl_git_sandbox_init("attr");
+ git_diff_list *diff;
+ size_t d, num_d;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
+
+ num_d = git_diff_num_deltas(diff);
+ for (d = 0; d < num_d; ++d) {
+ const git_diff_delta *delta;
+ cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
+ }
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_diffiter__iterate_files(void)
+{
+ git_repository *repo = cl_git_sandbox_init("attr");
+ git_diff_list *diff;
+ size_t d, num_d;
+ int count = 0;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
+
+ num_d = git_diff_num_deltas(diff);
+ cl_assert_equal_i(6, (int)num_d);
+
+ for (d = 0; d < num_d; ++d) {
+ const git_diff_delta *delta;
+ cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
+ cl_assert(delta != NULL);
+ count++;
+ }
+ cl_assert_equal_i(6, count);
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_diffiter__iterate_files_2(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_list *diff;
+ size_t d, num_d;
+ int count = 0;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
+
+ num_d = git_diff_num_deltas(diff);
+ cl_assert_equal_i(8, (int)num_d);
+
+ for (d = 0; d < num_d; ++d) {
+ const git_diff_delta *delta;
+ cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
+ cl_assert(delta != NULL);
+ count++;
+ }
+ cl_assert_equal_i(8, count);
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_diffiter__iterate_files_and_hunks(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ size_t d, num_d;
+ int file_count = 0, hunk_count = 0;
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+
+ num_d = git_diff_num_deltas(diff);
+
+ for (d = 0; d < num_d; ++d) {
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+ size_t h, num_h;
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+
+ cl_assert(delta);
+ cl_assert(patch);
+
+ file_count++;
+
+ num_h = git_diff_patch_num_hunks(patch);
+
+ for (h = 0; h < num_h; h++) {
+ const git_diff_range *range;
+ const char *header;
+ size_t header_len, num_l;
+
+ cl_git_pass(git_diff_patch_get_hunk(
+ &range, &header, &header_len, &num_l, patch, h));
+
+ cl_assert(range);
+ cl_assert(header);
+
+ hunk_count++;
+ }
+
+ git_diff_patch_free(patch);
+ }
+
+ cl_assert_equal_i(13, file_count);
+ cl_assert_equal_i(8, hunk_count);
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_diffiter__max_size_threshold(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ int file_count = 0, binary_count = 0, hunk_count = 0;
+ size_t d, num_d;
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+ num_d = git_diff_num_deltas(diff);
+
+ for (d = 0; d < num_d; ++d) {
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+ cl_assert(delta);
+ cl_assert(patch);
+
+ file_count++;
+ hunk_count += (int)git_diff_patch_num_hunks(patch);
+
+ assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
+ binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
+
+ git_diff_patch_free(patch);
+ }
+
+ cl_assert_equal_i(13, file_count);
+ cl_assert_equal_i(0, binary_count);
+ cl_assert_equal_i(8, hunk_count);
+
+ git_diff_list_free(diff);
+
+ /* try again with low file size threshold */
+
+ file_count = binary_count = hunk_count = 0;
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+ opts.max_size = 50; /* treat anything over 50 bytes as binary! */
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+ num_d = git_diff_num_deltas(diff);
+
+ for (d = 0; d < num_d; ++d) {
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+
+ file_count++;
+ hunk_count += (int)git_diff_patch_num_hunks(patch);
+
+ assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
+ binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
+
+ git_diff_patch_free(patch);
+ }
+
+ cl_assert_equal_i(13, file_count);
+ /* Three files are over the 50 byte threshold:
+ * - staged_changes_file_deleted
+ * - staged_changes_modified_file
+ * - staged_new_file_modified_file
+ */
+ cl_assert_equal_i(3, binary_count);
+ cl_assert_equal_i(5, hunk_count);
+
+ git_diff_list_free(diff);
+}
+
+
+void test_diff_diffiter__iterate_all(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp = {0};
+ size_t d, num_d;
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+
+ num_d = git_diff_num_deltas(diff);
+ for (d = 0; d < num_d; ++d) {
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+ size_t h, num_h;
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+ cl_assert(patch && delta);
+ exp.files++;
+
+ num_h = git_diff_patch_num_hunks(patch);
+ for (h = 0; h < num_h; h++) {
+ const git_diff_range *range;
+ const char *header;
+ size_t header_len, l, num_l;
+
+ cl_git_pass(git_diff_patch_get_hunk(
+ &range, &header, &header_len, &num_l, patch, h));
+ cl_assert(range && header);
+ exp.hunks++;
+
+ for (l = 0; l < num_l; ++l) {
+ char origin;
+ const char *content;
+ size_t content_len;
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &content, &content_len, NULL, NULL, patch, h, l));
+ cl_assert(content);
+ exp.lines++;
+ }
+ }
+
+ git_diff_patch_free(patch);
+ }
+
+ cl_assert_equal_i(13, exp.files);
+ cl_assert_equal_i(8, exp.hunks);
+ cl_assert_equal_i(14, exp.lines);
+
+ git_diff_list_free(diff);
+}
+
+static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp)
+{
+ size_t h, num_h = git_diff_patch_num_hunks(patch), num_l;
+
+ exp->files++;
+ exp->hunks += (int)num_h;
+
+ /* let's iterate in reverse, just because we can! */
+ for (h = 1, num_l = 0; h <= num_h; ++h)
+ num_l += git_diff_patch_num_lines_in_hunk(patch, num_h - h);
+
+ exp->lines += (int)num_l;
+}
+
+#define PATCH_CACHE 5
+
+void test_diff_diffiter__iterate_randomly_while_saving_state(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp = {0};
+ git_diff_patch *patches[PATCH_CACHE];
+ size_t p, d, num_d;
+
+ memset(patches, 0, sizeof(patches));
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+
+ num_d = git_diff_num_deltas(diff);
+
+ /* To make sure that references counts work for diff and patch objects,
+ * this generates patches and randomly caches them. Only when the patch
+ * is removed from the cache are hunks and lines counted. At the end,
+ * there are still patches in the cache, so free the diff and try to
+ * process remaining patches after the diff is freed.
+ */
+
+ srand(121212);
+ p = rand() % PATCH_CACHE;
+
+ for (d = 0; d < num_d; ++d) {
+ /* take old patch */
+ git_diff_patch *patch = patches[p];
+ patches[p] = NULL;
+
+ /* cache new patch */
+ cl_git_pass(git_diff_get_patch(&patches[p], NULL, diff, d));
+ cl_assert(patches[p] != NULL);
+
+ /* process old patch if non-NULL */
+ if (patch != NULL) {
+ iterate_over_patch(patch, &exp);
+ git_diff_patch_free(patch);
+ }
+
+ p = rand() % PATCH_CACHE;
+ }
+
+ /* free diff list now - refcounts should keep things safe */
+ git_diff_list_free(diff);
+
+ /* process remaining unprocessed patches */
+ for (p = 0; p < PATCH_CACHE; p++) {
+ git_diff_patch *patch = patches[p];
+
+ if (patch != NULL) {
+ iterate_over_patch(patch, &exp);
+ git_diff_patch_free(patch);
+ }
+ }
+
+ /* hopefully it all still added up right */
+ cl_assert_equal_i(13, exp.files);
+ cl_assert_equal_i(8, exp.hunks);
+ cl_assert_equal_i(14, exp.lines);
+}
+
+/* This output is taken directly from `git diff` on the status test data */
+static const char *expected_patch_text[8] = {
+ /* 0 */
+ "diff --git a/file_deleted b/file_deleted\n"
+ "deleted file mode 100644\n"
+ "index 5452d32..0000000\n"
+ "--- a/file_deleted\n"
+ "+++ /dev/null\n"
+ "@@ -1 +0,0 @@\n"
+ "-file_deleted\n",
+ /* 1 */
+ "diff --git a/modified_file b/modified_file\n"
+ "index 452e424..0a53963 100644\n"
+ "--- a/modified_file\n"
+ "+++ b/modified_file\n"
+ "@@ -1 +1,2 @@\n"
+ " modified_file\n"
+ "+modified_file\n",
+ /* 2 */
+ "diff --git a/staged_changes_file_deleted b/staged_changes_file_deleted\n"
+ "deleted file mode 100644\n"
+ "index a6be623..0000000\n"
+ "--- a/staged_changes_file_deleted\n"
+ "+++ /dev/null\n"
+ "@@ -1,2 +0,0 @@\n"
+ "-staged_changes_file_deleted\n"
+ "-staged_changes_file_deleted\n",
+ /* 3 */
+ "diff --git a/staged_changes_modified_file b/staged_changes_modified_file\n"
+ "index 906ee77..011c344 100644\n"
+ "--- a/staged_changes_modified_file\n"
+ "+++ b/staged_changes_modified_file\n"
+ "@@ -1,2 +1,3 @@\n"
+ " staged_changes_modified_file\n"
+ " staged_changes_modified_file\n"
+ "+staged_changes_modified_file\n",
+ /* 4 */
+ "diff --git a/staged_new_file_deleted_file b/staged_new_file_deleted_file\n"
+ "deleted file mode 100644\n"
+ "index 90b8c29..0000000\n"
+ "--- a/staged_new_file_deleted_file\n"
+ "+++ /dev/null\n"
+ "@@ -1 +0,0 @@\n"
+ "-staged_new_file_deleted_file\n",
+ /* 5 */
+ "diff --git a/staged_new_file_modified_file b/staged_new_file_modified_file\n"
+ "index ed06290..8b090c0 100644\n"
+ "--- a/staged_new_file_modified_file\n"
+ "+++ b/staged_new_file_modified_file\n"
+ "@@ -1 +1,2 @@\n"
+ " staged_new_file_modified_file\n"
+ "+staged_new_file_modified_file\n",
+ /* 6 */
+ "diff --git a/subdir/deleted_file b/subdir/deleted_file\n"
+ "deleted file mode 100644\n"
+ "index 1888c80..0000000\n"
+ "--- a/subdir/deleted_file\n"
+ "+++ /dev/null\n"
+ "@@ -1 +0,0 @@\n"
+ "-subdir/deleted_file\n",
+ /* 7 */
+ "diff --git a/subdir/modified_file b/subdir/modified_file\n"
+ "index a619198..57274b7 100644\n"
+ "--- a/subdir/modified_file\n"
+ "+++ b/subdir/modified_file\n"
+ "@@ -1 +1,2 @@\n"
+ " subdir/modified_file\n"
+ "+subdir/modified_file\n"
+};
+
+void test_diff_diffiter__iterate_and_generate_patch_text(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_list *diff;
+ size_t d, num_d;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
+
+ num_d = git_diff_num_deltas(diff);
+ cl_assert_equal_i(8, (int)num_d);
+
+ for (d = 0; d < num_d; ++d) {
+ git_diff_patch *patch;
+ char *text;
+
+ cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
+ cl_assert(patch != NULL);
+
+ cl_git_pass(git_diff_patch_to_str(&text, patch));
+
+ cl_assert_equal_s(expected_patch_text[d], text);
+
+ git__free(text);
+ git_diff_patch_free(patch);
+ }
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_diffiter__checks_options_version(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ const git_error *err;
+
+ opts.version = 0;
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_fail(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ giterr_clear();
+ opts.version = 1024;
+ cl_git_fail(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+}
+
diff --git a/tests-clar/diff/index.c b/tests-clar/diff/index.c
index 171815df5..e1c617dae 100644
--- a/tests-clar/diff/index.c
+++ b/tests-clar/diff/index.c
@@ -20,7 +20,7 @@ void test_diff_index__0(void)
const char *b_commit = "0017bd4ab1ec3"; /* the start */
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
- git_diff_options opts = {0};
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
diff_expects exp;
@@ -32,10 +32,10 @@ void test_diff_index__0(void)
memset(&exp, 0, sizeof(exp));
- cl_git_pass(git_diff_index_to_tree(g_repo, &opts, a, &diff));
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
/* to generate these values:
* - cd to tests/resources/status,
@@ -44,26 +44,26 @@ void test_diff_index__0(void)
* - git diff -U1 --cached 26a125ee1bf
* - mv .git .gitted
*/
- cl_assert(exp.files == 8);
- cl_assert(exp.file_adds == 3);
- cl_assert(exp.file_dels == 2);
- cl_assert(exp.file_mods == 3);
+ cl_assert_equal_i(8, exp.files);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert(exp.hunks == 8);
+ cl_assert_equal_i(8, exp.hunks);
- cl_assert(exp.lines == 11);
- cl_assert(exp.line_ctxt == 3);
- cl_assert(exp.line_adds == 6);
- cl_assert(exp.line_dels == 2);
+ cl_assert_equal_i(11, exp.lines);
+ cl_assert_equal_i(3, exp.line_ctxt);
+ cl_assert_equal_i(6, exp.line_adds);
+ cl_assert_equal_i(2, exp.line_dels);
git_diff_list_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
- cl_git_pass(git_diff_index_to_tree(g_repo, &opts, b, &diff));
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, b, NULL, &opts));
cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
/* to generate these values:
* - cd to tests/resources/status,
@@ -72,17 +72,17 @@ void test_diff_index__0(void)
* - git diff -U1 --cached 0017bd4ab1ec3
* - mv .git .gitted
*/
- cl_assert(exp.files == 12);
- cl_assert(exp.file_adds == 7);
- cl_assert(exp.file_dels == 2);
- cl_assert(exp.file_mods == 3);
+ cl_assert_equal_i(12, exp.files);
+ cl_assert_equal_i(7, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert(exp.hunks == 12);
+ cl_assert_equal_i(12, exp.hunks);
- cl_assert(exp.lines == 16);
- cl_assert(exp.line_ctxt == 3);
- cl_assert(exp.line_adds == 11);
- cl_assert(exp.line_dels == 2);
+ cl_assert_equal_i(16, exp.lines);
+ cl_assert_equal_i(3, exp.line_ctxt);
+ cl_assert_equal_i(11, exp.line_adds);
+ cl_assert_equal_i(2, exp.line_dels);
git_diff_list_free(diff);
diff = NULL;
@@ -90,3 +90,78 @@ void test_diff_index__0(void)
git_tree_free(a);
git_tree_free(b);
}
+
+static int diff_stop_after_2_files(
+ const git_diff_delta *delta,
+ float progress,
+ void *payload)
+{
+ diff_expects *e = payload;
+
+ GIT_UNUSED(progress);
+ GIT_UNUSED(delta);
+
+ e->files++;
+
+ return (e->files == 2);
+}
+
+void test_diff_index__1(void)
+{
+ /* grabbed a couple of commit oids from the history of the attr repo */
+ const char *a_commit = "26a125ee1bf"; /* the current HEAD */
+ const char *b_commit = "0017bd4ab1ec3"; /* the start */
+ git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
+ git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+
+ cl_assert(a);
+ cl_assert(b);
+
+ opts.context_lines = 1;
+ opts.interhunk_lines = 1;
+
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
+
+ cl_assert_equal_i(
+ GIT_EUSER,
+ git_diff_foreach(diff, diff_stop_after_2_files, NULL, NULL, &exp)
+ );
+
+ cl_assert_equal_i(2, exp.files);
+
+ git_diff_list_free(diff);
+ diff = NULL;
+
+ git_tree_free(a);
+ git_tree_free(b);
+}
+
+void test_diff_index__checks_options_version(void)
+{
+ const char *a_commit = "26a125ee1bf";
+ git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ const git_error *err;
+
+ opts.version = 0;
+ cl_git_fail(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+ cl_assert_equal_p(diff, NULL);
+
+ giterr_clear();
+ opts.version = 1024;
+ cl_git_fail(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+ cl_assert_equal_p(diff, NULL);
+
+ git_tree_free(a);
+}
+
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index be29bea66..15b10465a 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "iterator.h"
+#include "tree.h"
void test_diff_iterator__initialize(void)
{
@@ -30,25 +31,36 @@ static void tree_iterator_test(
git_tree *t;
git_iterator *i;
const git_index_entry *entry;
- int count = 0;
+ int count = 0, count_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
- cl_git_pass(git_iterator_for_tree_range(&i, repo, t, start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_for_tree(
+ &i, t, GIT_ITERATOR_DONT_IGNORE_CASE, start, end));
+ /* test loop */
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count], entry->path);
-
count++;
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
- cl_git_pass(git_iterator_advance(i, &entry));
+ /* test reset */
+ cl_git_pass(git_iterator_reset(i, NULL, NULL));
+ cl_git_pass(git_iterator_current(&entry, i));
+ while (entry != NULL) {
+ if (expected_values != NULL)
+ cl_assert_equal_s(expected_values[count_post_reset], entry->path);
+ count_post_reset++;
+ cl_git_pass(git_iterator_advance(&entry, i));
}
git_iterator_free(i);
- cl_assert(expected_count == count);
+ cl_assert_equal_i(expected_count, count);
+ cl_assert_equal_i(count, count_post_reset);
git_tree_free(t);
}
@@ -237,6 +249,104 @@ void test_diff_iterator__tree_range_empty_2(void)
NULL, ".aaa_empty_before", 0, NULL);
}
+static void check_tree_entry(
+ git_iterator *i,
+ const char *oid,
+ const char *oid_p,
+ const char *oid_pp,
+ const char *oid_ppp)
+{
+ const git_index_entry *ie;
+ const git_tree_entry *te;
+ const git_tree *tree;
+ git_buf path = GIT_BUF_INIT;
+
+ cl_git_pass(git_iterator_current_tree_entry(&te, i));
+ cl_assert(te);
+ cl_assert(git_oid_streq(&te->oid, oid) == 0);
+
+ cl_git_pass(git_iterator_current(&ie, i));
+ cl_git_pass(git_buf_sets(&path, ie->path));
+
+ if (oid_p) {
+ git_buf_rtruncate_at_char(&path, '/');
+ cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr));
+ cl_assert(tree);
+ cl_assert(git_oid_streq(git_tree_id(tree), oid_p) == 0);
+ }
+
+ if (oid_pp) {
+ git_buf_rtruncate_at_char(&path, '/');
+ cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr));
+ cl_assert(tree);
+ cl_assert(git_oid_streq(git_tree_id(tree), oid_pp) == 0);
+ }
+
+ if (oid_ppp) {
+ git_buf_rtruncate_at_char(&path, '/');
+ cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr));
+ cl_assert(tree);
+ cl_assert(git_oid_streq(git_tree_id(tree), oid_ppp) == 0);
+ }
+
+ git_buf_free(&path);
+}
+
+void test_diff_iterator__tree_special_functions(void)
+{
+ git_tree *t;
+ git_iterator *i;
+ const git_index_entry *entry;
+ git_repository *repo = cl_git_sandbox_init("attr");
+ int cases = 0;
+ const char *rootoid = "ce39a97a7fb1fa90bcf5e711249c1e507476ae0e";
+
+ t = resolve_commit_oid_to_tree(
+ repo, "24fa9a9fc4e202313e24b648087495441dab432b");
+ cl_assert(t != NULL);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, t, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ while (entry != NULL) {
+ if (strcmp(entry->path, "sub/file") == 0) {
+ cases++;
+ check_tree_entry(
+ i, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
+ "ecb97df2a174987475ac816e3847fc8e9f6c596b",
+ rootoid, NULL);
+ }
+ else if (strcmp(entry->path, "sub/sub/subsub.txt") == 0) {
+ cases++;
+ check_tree_entry(
+ i, "9e5bdc47d6a80f2be0ea3049ad74231b94609242",
+ "4e49ba8c5b6c32ff28cd9dcb60be34df50fcc485",
+ "ecb97df2a174987475ac816e3847fc8e9f6c596b", rootoid);
+ }
+ else if (strcmp(entry->path, "subdir/.gitattributes") == 0) {
+ cases++;
+ check_tree_entry(
+ i, "99eae476896f4907224978b88e5ecaa6c5bb67a9",
+ "9fb40b6675dde60b5697afceae91b66d908c02d9",
+ rootoid, NULL);
+ }
+ else if (strcmp(entry->path, "subdir2/subdir2_test1") == 0) {
+ cases++;
+ check_tree_entry(
+ i, "dccada462d3df8ac6de596fb8c896aba9344f941",
+ "2929de282ce999e95183aedac6451d3384559c4b",
+ rootoid, NULL);
+ }
+
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
+
+ cl_assert_equal_i(4, cases);
+ git_iterator_free(i);
+ git_tree_free(t);
+}
+
/* -- INDEX ITERATOR TESTS -- */
static void index_iterator_test(
@@ -247,13 +357,15 @@ static void index_iterator_test(
const char **expected_names,
const char **expected_oids)
{
+ git_index *index;
git_iterator *i;
const git_index_entry *entry;
int count = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
- cl_git_pass(git_iterator_for_index_range(&i, repo, start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (expected_names != NULL)
@@ -266,10 +378,11 @@ static void index_iterator_test(
}
count++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
git_iterator_free(i);
+ git_index_free(index);
cl_assert_equal_i(expected_count, count);
}
@@ -312,7 +425,7 @@ static const char *expected_index_oids_0[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
- "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+ "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
@@ -343,7 +456,7 @@ static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
- "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+ "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
};
void test_diff_iterator__index_range(void)
@@ -422,17 +535,18 @@ static void workdir_iterator_test(
{
git_iterator *i;
const git_index_entry *entry;
- int count = 0, count_all = 0;
+ int count = 0, count_all = 0, count_all_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
- cl_git_pass(git_iterator_for_workdir_range(&i, repo, start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_for_workdir(
+ &i, repo, GIT_ITERATOR_DONT_AUTOEXPAND, start, end));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
int ignored = git_iterator_current_is_ignored(i);
if (S_ISDIR(entry->mode)) {
- cl_git_pass(git_iterator_advance_into_directory(i, &entry));
+ cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
@@ -446,18 +560,34 @@ static void workdir_iterator_test(
count++;
count_all++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
+
+ cl_git_pass(git_iterator_reset(i, NULL, NULL));
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ while (entry != NULL) {
+ if (S_ISDIR(entry->mode)) {
+ cl_git_pass(git_iterator_advance_into(&entry, i));
+ continue;
+ }
+ if (expected_names != NULL)
+ cl_assert_equal_s(
+ expected_names[count_all_post_reset], entry->path);
+ count_all_post_reset++;
+ cl_git_pass(git_iterator_advance(&entry, i));
}
git_iterator_free(i);
- cl_assert(count == expected_count);
- cl_assert(count_all == expected_count + expected_ignores);
+ cl_assert_equal_i(expected_count, count);
+ cl_assert_equal_i(expected_count + expected_ignores, count_all);
+ cl_assert_equal_i(count_all, count_all_post_reset);
}
void test_diff_iterator__workdir_0(void)
{
- workdir_iterator_test("attr", NULL, NULL, 25, 2, NULL, "ign");
+ workdir_iterator_test("attr", NULL, NULL, 27, 1, NULL, "ign");
}
static const char *status_paths[] = {
@@ -474,13 +604,14 @@ static const char *status_paths[] = {
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
+ "\xe8\xbf\x99",
NULL
};
void test_diff_iterator__workdir_1(void)
{
workdir_iterator_test(
- "status", NULL, NULL, 12, 1, status_paths, "ignored_file");
+ "status", NULL, NULL, 13, 1, status_paths, "ignored_file");
}
static const char *status_paths_range_0[] = {
@@ -527,13 +658,14 @@ static const char *status_paths_range_4[] = {
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
+ "\xe8\xbf\x99",
NULL
};
void test_diff_iterator__workdir_1_ranged_4(void)
{
workdir_iterator_test(
- "status", "subdir/", NULL, 3, 0, status_paths_range_4, NULL);
+ "status", "subdir/", NULL, 4, 0, status_paths_range_4, NULL);
}
static const char *status_paths_range_5[] = {
@@ -551,7 +683,7 @@ void test_diff_iterator__workdir_1_ranged_5(void)
void test_diff_iterator__workdir_1_ranged_empty_0(void)
{
workdir_iterator_test(
- "status", "z_does_not_exist", NULL,
+ "status", "\xff_does_not_exist", NULL,
0, 0, NULL, NULL);
}
@@ -568,3 +700,226 @@ void test_diff_iterator__workdir_1_ranged_empty_2(void)
"status", NULL, "aaaa_empty_before",
0, 0, NULL, NULL);
}
+
+void test_diff_iterator__workdir_builtin_ignores(void)
+{
+ git_repository *repo = cl_git_sandbox_init("attr");
+ git_iterator *i;
+ const git_index_entry *entry;
+ int idx;
+ static struct {
+ const char *path;
+ bool ignored;
+ } expected[] = {
+ { "dir/", true },
+ { "file", false },
+ { "ign", true },
+ { "macro_bad", false },
+ { "macro_test", false },
+ { "root_test1", false },
+ { "root_test2", false },
+ { "root_test3", false },
+ { "root_test4.txt", false },
+ { "sub", false },
+ { "sub/.gitattributes", false },
+ { "sub/abc", false },
+ { "sub/dir/", true },
+ { "sub/file", false },
+ { "sub/ign/", true },
+ { "sub/sub", false },
+ { "sub/sub/.gitattributes", false },
+ { "sub/sub/dir", false }, /* file is not actually a dir */
+ { "sub/sub/file", false },
+ { NULL, false }
+ };
+
+ cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
+ cl_git_mkfile("attr/sub/.git", "whatever");
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, repo, GIT_ITERATOR_DONT_AUTOEXPAND, "dir", "sub/sub/file"));
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ for (idx = 0; entry != NULL; ++idx) {
+ int ignored = git_iterator_current_is_ignored(i);
+
+ cl_assert_equal_s(expected[idx].path, entry->path);
+ cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
+
+ if (!ignored &&
+ (entry->mode == GIT_FILEMODE_TREE ||
+ entry->mode == GIT_FILEMODE_COMMIT))
+ {
+ /* it is possible to advance "into" a submodule */
+ cl_git_pass(git_iterator_advance_into(&entry, i));
+ } else
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
+
+ cl_assert(expected[idx].path == NULL);
+
+ git_iterator_free(i);
+}
+
+static void check_wd_first_through_third_range(
+ git_repository *repo, const char *start, const char *end)
+{
+ git_iterator *i;
+ const git_index_entry *entry;
+ int idx;
+ static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, repo, GIT_ITERATOR_IGNORE_CASE, start, end));
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ for (idx = 0; entry != NULL; ++idx) {
+ cl_assert_equal_s(expected[idx], entry->path);
+
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
+
+ cl_assert(expected[idx] == NULL);
+
+ git_iterator_free(i);
+}
+
+void test_diff_iterator__workdir_handles_icase_range(void)
+{
+ git_repository *repo;
+
+ repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
+
+ cl_git_mkfile("empty_standard_repo/before", "whatever\n");
+ cl_git_mkfile("empty_standard_repo/FIRST", "whatever\n");
+ cl_git_mkfile("empty_standard_repo/second", "whatever\n");
+ cl_git_mkfile("empty_standard_repo/THIRD", "whatever\n");
+ cl_git_mkfile("empty_standard_repo/zafter", "whatever\n");
+ cl_git_mkfile("empty_standard_repo/Zlast", "whatever\n");
+
+ check_wd_first_through_third_range(repo, "first", "third");
+ check_wd_first_through_third_range(repo, "FIRST", "THIRD");
+ check_wd_first_through_third_range(repo, "first", "THIRD");
+ check_wd_first_through_third_range(repo, "FIRST", "third");
+ check_wd_first_through_third_range(repo, "FirSt", "tHiRd");
+}
+
+static void check_tree_range(
+ git_repository *repo,
+ const char *start,
+ const char *end,
+ bool ignore_case,
+ int expected_count)
+{
+ git_tree *head;
+ git_iterator *i;
+ const git_index_entry *entry;
+ int count;
+
+ cl_git_pass(git_repository_head_tree(&head, repo));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head,
+ ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE,
+ start, end));
+
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ for (count = 0; entry != NULL; ) {
+ ++count;
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
+
+ cl_assert_equal_i(expected_count, count);
+
+ git_iterator_free(i);
+ git_tree_free(head);
+}
+
+void test_diff_iterator__tree_handles_icase_range(void)
+{
+ git_repository *repo;
+
+ repo = cl_git_sandbox_init("testrepo");
+
+ check_tree_range(repo, "B", "C", false, 0);
+ check_tree_range(repo, "B", "C", true, 1);
+ check_tree_range(repo, "b", "c", false, 1);
+ check_tree_range(repo, "b", "c", true, 1);
+
+ check_tree_range(repo, "a", "z", false, 3);
+ check_tree_range(repo, "a", "z", true, 4);
+ check_tree_range(repo, "A", "Z", false, 1);
+ check_tree_range(repo, "A", "Z", true, 4);
+ check_tree_range(repo, "a", "Z", false, 0);
+ check_tree_range(repo, "a", "Z", true, 4);
+ check_tree_range(repo, "A", "z", false, 4);
+ check_tree_range(repo, "A", "z", true, 4);
+
+ check_tree_range(repo, "new.txt", "new.txt", true, 1);
+ check_tree_range(repo, "new.txt", "new.txt", false, 1);
+ check_tree_range(repo, "README", "README", true, 1);
+ check_tree_range(repo, "README", "README", false, 1);
+}
+
+static void check_index_range(
+ git_repository *repo,
+ const char *start,
+ const char *end,
+ bool ignore_case,
+ int expected_count)
+{
+ git_index *index;
+ git_iterator *i;
+ const git_index_entry *entry;
+ int count, caps;
+ bool is_ignoring_case;
+
+ cl_git_pass(git_repository_index(&index, repo));
+
+ caps = git_index_caps(index);
+ is_ignoring_case = ((caps & GIT_INDEXCAP_IGNORE_CASE) != 0);
+
+ if (ignore_case != is_ignoring_case)
+ cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));
+
+ cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));
+
+ cl_assert(git_iterator_ignore_case(i) == ignore_case);
+
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ for (count = 0; entry != NULL; ) {
+ ++count;
+ cl_git_pass(git_iterator_advance(&entry, i));
+ }
+
+ cl_assert_equal_i(expected_count, count);
+
+ git_iterator_free(i);
+ git_index_free(index);
+}
+
+void test_diff_iterator__index_handles_icase_range(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_tree *head;
+
+ repo = cl_git_sandbox_init("testrepo");
+
+ /* reset index to match HEAD */
+ cl_git_pass(git_repository_head_tree(&head, repo));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_read_tree(index, head));
+ cl_git_pass(git_index_write(index));
+ git_tree_free(head);
+ git_index_free(index);
+
+ /* do some ranged iterator checks toggling case sensitivity */
+ check_index_range(repo, "B", "C", false, 0);
+ check_index_range(repo, "B", "C", true, 1);
+ check_index_range(repo, "a", "z", false, 3);
+ check_index_range(repo, "a", "z", true, 4);
+}
diff --git a/tests-clar/diff/notify.c b/tests-clar/diff/notify.c
new file mode 100644
index 000000000..433b4a9c1
--- /dev/null
+++ b/tests-clar/diff/notify.c
@@ -0,0 +1,228 @@
+#include "clar_libgit2.h"
+#include "diff_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+void test_diff_notify__initialize(void)
+{
+}
+
+void test_diff_notify__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static int assert_called_notifications(
+ const git_diff_list *diff_so_far,
+ const git_diff_delta *delta_to_add,
+ const char *matched_pathspec,
+ void *payload)
+{
+ bool found = false;
+ notify_expected *exp = (notify_expected*)payload;
+ notify_expected *e;;
+
+ GIT_UNUSED(diff_so_far);
+
+ for (e = exp; e->path != NULL; e++) {
+ if (strcmp(e->path, delta_to_add->new_file.path))
+ continue;
+
+ cl_assert_equal_s(e->matched_pathspec, matched_pathspec);
+
+ found = true;
+ break;
+ }
+
+ cl_assert(found);
+ return 0;
+}
+
+static void test_notify(
+ char **searched_pathspecs,
+ int pathspecs_count,
+ notify_expected *expected_matched_pathspecs,
+ int expected_diffed_files_count)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+ opts.notify_cb = assert_called_notifications;
+ opts.pathspec.strings = searched_pathspecs;
+ opts.pathspec.count = pathspecs_count;
+
+ opts.notify_payload = expected_matched_pathspecs;
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_git_pass(git_diff_foreach(diff, diff_file_cb, NULL, NULL, &exp));
+
+ cl_assert_equal_i(expected_diffed_files_count, exp.files);
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_notify__notify_single_pathspec(void)
+{
+ char *searched_pathspecs[] = {
+ "*_deleted",
+ };
+ notify_expected expected_matched_pathspecs[] = {
+ { "file_deleted", "*_deleted" },
+ { "staged_changes_file_deleted", "*_deleted" },
+ { NULL, NULL }
+ };
+
+ test_notify(searched_pathspecs, 1, expected_matched_pathspecs, 2);
+}
+
+void test_diff_notify__notify_multiple_pathspec(void)
+{
+ char *searched_pathspecs[] = {
+ "staged_changes_cant_find_me",
+ "subdir/modified_cant_find_me",
+ "subdir/*",
+ "staged*"
+ };
+ notify_expected expected_matched_pathspecs[] = {
+ { "staged_changes_file_deleted", "staged*" },
+ { "staged_changes_modified_file", "staged*" },
+ { "staged_delete_modified_file", "staged*" },
+ { "staged_new_file_deleted_file", "staged*" },
+ { "staged_new_file_modified_file", "staged*" },
+ { "subdir/deleted_file", "subdir/*" },
+ { "subdir/modified_file", "subdir/*" },
+ { "subdir/new_file", "subdir/*" },
+ { NULL, NULL }
+ };
+
+ test_notify(searched_pathspecs, 4, expected_matched_pathspecs, 8);
+}
+
+void test_diff_notify__notify_catchall_with_empty_pathspecs(void)
+{
+ char *searched_pathspecs[] = {
+ "",
+ ""
+ };
+ notify_expected expected_matched_pathspecs[] = {
+ { "file_deleted", NULL },
+ { "ignored_file", NULL },
+ { "modified_file", NULL },
+ { "new_file", NULL },
+ { "\xe8\xbf\x99", NULL },
+ { "staged_changes_file_deleted", NULL },
+ { "staged_changes_modified_file", NULL },
+ { "staged_delete_modified_file", NULL },
+ { "staged_new_file_deleted_file", NULL },
+ { "staged_new_file_modified_file", NULL },
+ { "subdir/deleted_file", NULL },
+ { "subdir/modified_file", NULL },
+ { "subdir/new_file", NULL },
+ { NULL, NULL }
+ };
+
+ test_notify(searched_pathspecs, 1, expected_matched_pathspecs, 13);
+}
+
+void test_diff_notify__notify_catchall(void)
+{
+ char *searched_pathspecs[] = {
+ "*",
+ };
+ notify_expected expected_matched_pathspecs[] = {
+ { "file_deleted", "*" },
+ { "ignored_file", "*" },
+ { "modified_file", "*" },
+ { "new_file", "*" },
+ { "\xe8\xbf\x99", "*" },
+ { "staged_changes_file_deleted", "*" },
+ { "staged_changes_modified_file", "*" },
+ { "staged_delete_modified_file", "*" },
+ { "staged_new_file_deleted_file", "*" },
+ { "staged_new_file_modified_file", "*" },
+ { "subdir/deleted_file", "*" },
+ { "subdir/modified_file", "*" },
+ { "subdir/new_file", "*" },
+ { NULL, NULL }
+ };
+
+ test_notify(searched_pathspecs, 1, expected_matched_pathspecs, 13);
+}
+
+static int abort_diff(
+ const git_diff_list *diff_so_far,
+ const git_diff_delta *delta_to_add,
+ const char *matched_pathspec,
+ void *payload)
+{
+ GIT_UNUSED(diff_so_far);
+ GIT_UNUSED(delta_to_add);
+ GIT_UNUSED(matched_pathspec);
+ GIT_UNUSED(payload);
+
+ return -42;
+}
+
+void test_diff_notify__notify_cb_can_abort_diff(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ char *pathspec = NULL;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+ opts.notify_cb = abort_diff;
+ opts.pathspec.strings = &pathspec;
+ opts.pathspec.count = 1;
+
+ pathspec = "file_deleted";
+ cl_git_fail(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ pathspec = "staged_changes_modified_file";
+ cl_git_fail(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+}
+
+static int filter_all(
+ const git_diff_list *diff_so_far,
+ const git_diff_delta *delta_to_add,
+ const char *matched_pathspec,
+ void *payload)
+{
+ GIT_UNUSED(diff_so_far);
+ GIT_UNUSED(delta_to_add);
+ GIT_UNUSED(matched_pathspec);
+ GIT_UNUSED(payload);
+
+ return 42;
+}
+
+void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ char *pathspec = NULL;
+ diff_expects exp;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+ opts.notify_cb = filter_all;
+ opts.pathspec.strings = &pathspec;
+ opts.pathspec.count = 1;
+
+ pathspec = "*_deleted";
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_git_pass(git_diff_foreach(diff, diff_file_cb, NULL, NULL, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+
+ git_diff_list_free(diff);
+}
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index 05e748667..4d17da468 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -1,11 +1,12 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
+#include "repository.h"
+#include "buf_text.h"
static git_repository *g_repo = NULL;
void test_diff_patch__initialize(void)
{
- g_repo = cl_git_sandbox_init("status");
}
void test_diff_patch__cleanup(void)
@@ -22,14 +23,14 @@ void test_diff_patch__cleanup(void)
#define EXPECTED_HUNK "@@ -1,2 +0,0 @@\n"
static int check_removal_cb(
- void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *formatted_output,
- size_t output_len)
+ size_t output_len,
+ void *payload)
{
- GIT_UNUSED(cb_data);
+ GIT_UNUSED(payload);
GIT_UNUSED(output_len);
switch (line_origin) {
@@ -85,15 +86,230 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
git_tree *one, *another;
git_diff_list *diff;
+ g_repo = cl_git_sandbox_init("status");
+
one = resolve_commit_oid_to_tree(g_repo, one_sha);
another = resolve_commit_oid_to_tree(g_repo, another_sha);
- cl_git_pass(git_diff_tree_to_tree(g_repo, NULL, one, another, &diff));
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
- cl_git_pass(git_diff_print_patch(diff, NULL, check_removal_cb));
+ cl_git_pass(git_diff_print_patch(diff, check_removal_cb, NULL));
git_diff_list_free(diff);
git_tree_free(another);
git_tree_free(one);
}
+
+void test_diff_patch__to_string(void)
+{
+ const char *one_sha = "26a125e";
+ const char *another_sha = "735b6a2";
+ git_tree *one, *another;
+ git_diff_list *diff;
+ git_diff_patch *patch;
+ char *text;
+ const char *expected = "diff --git a/subdir.txt b/subdir.txt\ndeleted file mode 100644\nindex e8ee89e..0000000\n--- a/subdir.txt\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-Is it a bird?\n-Is it a plane?\n";
+
+ g_repo = cl_git_sandbox_init("status");
+
+ one = resolve_commit_oid_to_tree(g_repo, one_sha);
+ another = resolve_commit_oid_to_tree(g_repo, another_sha);
+
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
+
+ cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
+
+ cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
+
+ cl_git_pass(git_diff_patch_to_str(&text, patch));
+
+ cl_assert_equal_s(expected, text);
+
+ git__free(text);
+ git_diff_patch_free(patch);
+ git_diff_list_free(diff);
+ git_tree_free(another);
+ git_tree_free(one);
+}
+
+void test_diff_patch__hunks_have_correct_line_numbers(void)
+{
+ git_config *cfg;
+ git_tree *head;
+ git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff;
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+ const git_diff_range *range;
+ const char *hdr, *text;
+ size_t hdrlen, hunklen, textlen;
+ char origin;
+ int oldno, newno;
+ const char *new_content = "The Song of Seven Cities\n------------------------\n\nI WAS Lord of Cities very sumptuously builded.\nSeven roaring Cities paid me tribute from afar.\nIvory their outposts were--the guardrooms of them gilded,\nAnd garrisoned with Amazons invincible in war.\n\nThis is some new text;\nNot as good as the old text;\nBut here it is.\n\nSo they warred and trafficked only yesterday, my Cities.\nTo-day there is no mark or mound of where my Cities stood.\nFor the River rose at midnight and it washed away my Cities.\nThey are evened with Atlantis and the towns before the Flood.\n\nRain on rain-gorged channels raised the water-levels round them,\nFreshet backed on freshet swelled and swept their world from sight,\nTill the emboldened floods linked arms and, flashing forward, drowned them--\nDrowned my Seven Cities and their peoples in one night!\n\nLow among the alders lie their derelict foundations,\nThe beams wherein they trusted and the plinths whereon they built--\nMy rulers and their treasure and their unborn populations,\nDead, destroyed, aborted, and defiled with mud and silt!\n\nAnother replacement;\nBreaking up the poem;\nGenerating some hunks.\n\nTo the sound of trumpets shall their seed restore my Cities\nWealthy and well-weaponed, that once more may I behold\nAll the world go softly when it walks before my Cities,\nAnd the horses and the chariots fleeing from them as of old!\n\n -- Rudyard Kipling\n";
+
+ g_repo = cl_git_sandbox_init("renames");
+
+ cl_git_pass(git_config_new(&cfg));
+ git_repository_set_config(g_repo, cfg);
+
+ cl_git_rewritefile("renames/songof7cities.txt", new_content);
+
+ cl_git_pass(git_repository_head_tree(&head, g_repo));
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, head, &opt));
+
+ cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
+
+ cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
+ cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(patch));
+
+ /* check hunk 0 */
+
+ cl_git_pass(
+ git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
+
+ cl_assert_equal_i(18, (int)hunklen);
+
+ cl_assert_equal_i(6, (int)range->old_start);
+ cl_assert_equal_i(15, (int)range->old_lines);
+ cl_assert_equal_i(6, (int)range->new_start);
+ cl_assert_equal_i(9, (int)range->new_lines);
+
+ cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &text, &textlen, &oldno, &newno, patch, 0, 0));
+ cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
+ cl_assert(strncmp("Ivory their outposts were--the guardrooms of them gilded,\n", text, textlen) == 0);
+ cl_assert_equal_i(6, oldno);
+ cl_assert_equal_i(6, newno);
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
+ cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
+ cl_assert(strncmp("All the world went softly when it walked before my Cities--\n", text, textlen) == 0);
+ cl_assert_equal_i(9, oldno);
+ cl_assert_equal_i(-1, newno);
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &text, &textlen, &oldno, &newno, patch, 0, 12));
+ cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
+ cl_assert(strncmp("This is some new text;\n", text, textlen) == 0);
+ cl_assert_equal_i(-1, oldno);
+ cl_assert_equal_i(9, newno);
+
+ /* check hunk 1 */
+
+ cl_git_pass(
+ git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 1));
+
+ cl_assert_equal_i(18, (int)hunklen);
+
+ cl_assert_equal_i(31, (int)range->old_start);
+ cl_assert_equal_i(15, (int)range->old_lines);
+ cl_assert_equal_i(25, (int)range->new_start);
+ cl_assert_equal_i(9, (int)range->new_lines);
+
+ cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 1));
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &text, &textlen, &oldno, &newno, patch, 1, 0));
+ cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
+ cl_assert(strncmp("My rulers and their treasure and their unborn populations,\n", text, textlen) == 0);
+ cl_assert_equal_i(31, oldno);
+ cl_assert_equal_i(25, newno);
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &text, &textlen, &oldno, &newno, patch, 1, 3));
+ cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
+ cl_assert(strncmp("The Daughters of the Palace whom they cherished in my Cities,\n", text, textlen) == 0);
+ cl_assert_equal_i(34, oldno);
+ cl_assert_equal_i(-1, newno);
+
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &text, &textlen, &oldno, &newno, patch, 1, 12));
+ cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
+ cl_assert(strncmp("Another replacement;\n", text, textlen) == 0);
+ cl_assert_equal_i(-1, oldno);
+ cl_assert_equal_i(28, newno);
+
+ git_diff_patch_free(patch);
+ git_diff_list_free(diff);
+ git_tree_free(head);
+ git_config_free(cfg);
+}
+
+static void check_single_patch_stats(
+ git_repository *repo, size_t hunks, size_t adds, size_t dels)
+{
+ git_diff_list *diff;
+ git_diff_patch *patch;
+ const git_diff_delta *delta;
+ size_t actual_adds, actual_dels;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
+
+ cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
+
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
+ cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
+
+ cl_assert_equal_i((int)hunks, (int)git_diff_patch_num_hunks(patch));
+
+ cl_git_pass(
+ git_diff_patch_line_stats(NULL, &actual_adds, &actual_dels, patch));
+
+ cl_assert_equal_sz(adds, actual_adds);
+ cl_assert_equal_sz(dels, actual_dels);
+
+ git_diff_patch_free(patch);
+ git_diff_list_free(diff);
+}
+
+void test_diff_patch__line_counts_with_eofnl(void)
+{
+ git_config *cfg;
+ git_buf content = GIT_BUF_INIT;
+ const char *end;
+ git_index *index;
+
+ g_repo = cl_git_sandbox_init("renames");
+
+ cl_git_pass(git_config_new(&cfg));
+ git_repository_set_config(g_repo, cfg);
+
+ cl_git_pass(git_futils_readbuffer(&content, "renames/songof7cities.txt"));
+
+ /* remove first line */
+
+ end = git_buf_cstr(&content) + git_buf_find(&content, '\n') + 1;
+ git_buf_consume(&content, end);
+ cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
+
+ check_single_patch_stats(g_repo, 1, 0, 1);
+
+ /* remove trailing whitespace */
+
+ git_buf_rtrim(&content);
+ cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
+
+ check_single_patch_stats(g_repo, 2, 1, 2);
+
+ /* add trailing whitespace */
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_add_bypath(index, "songof7cities.txt"));
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
+
+ cl_git_pass(git_buf_putc(&content, '\n'));
+ cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
+
+ check_single_patch_stats(g_repo, 1, 1, 1);
+
+ git_buf_free(&content);
+ git_config_free(cfg);
+}
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
new file mode 100644
index 000000000..5a8af93bb
--- /dev/null
+++ b/tests-clar/diff/rename.c
@@ -0,0 +1,393 @@
+#include "clar_libgit2.h"
+#include "diff_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+void test_diff_rename__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("renames");
+}
+
+void test_diff_rename__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+/*
+ * Renames repo has:
+ *
+ * commit 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 -
+ * serving.txt (25 lines)
+ * sevencities.txt (50 lines)
+ * commit 2bc7f351d20b53f1c72c16c4b036e491c478c49a -
+ * serving.txt -> sixserving.txt (rename, no change, 100% match)
+ * sevencities.txt -> sevencities.txt (no change)
+ * sevencities.txt -> songofseven.txt (copy, no change, 100% match)
+ * commit 1c068dee5790ef1580cfc4cd670915b48d790084
+ * songofseven.txt -> songofseven.txt (major rewrite, <20% match - split)
+ * sixserving.txt -> sixserving.txt (indentation change)
+ * sixserving.txt -> ikeepsix.txt (copy, add title, >80% match)
+ * sevencities.txt (no change)
+ * commit 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
+ * songofseven.txt -> untimely.txt (rename, convert to crlf)
+ * ikeepsix.txt -> ikeepsix.txt (reorder sections in file)
+ * sixserving.txt -> sixserving.txt (whitespace change - not just indent)
+ * sevencities.txt -> songof7cities.txt (rename, small text changes)
+ */
+
+void test_diff_rename__match_oid(void)
+{
+ const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
+ const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
+ git_tree *old_tree, *new_tree;
+ git_diff_list *diff;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
+ diff_expects exp;
+
+ old_tree = resolve_commit_oid_to_tree(g_repo, old_sha);
+ new_tree = resolve_commit_oid_to_tree(g_repo, new_sha);
+
+ /* Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
+ * --find-copies-harder during rename transformion...
+ */
+ diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
+
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ /* git diff --no-renames \
+ * 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
+ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a
+ */
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+
+ /* git diff 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
+ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a
+ */
+ cl_git_pass(git_diff_find_similar(diff, NULL));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(3, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
+
+ git_diff_list_free(diff);
+
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ /* git diff --find-copies-harder \
+ * 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
+ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a
+ */
+ opts.flags = GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(3, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
+
+ git_diff_list_free(diff);
+
+ git_tree_free(old_tree);
+ git_tree_free(new_tree);
+}
+
+void test_diff_rename__checks_options_version(void)
+{
+ const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
+ const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
+ git_tree *old_tree, *new_tree;
+ git_diff_list *diff;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
+ const git_error *err;
+
+ old_tree = resolve_commit_oid_to_tree(g_repo, old_sha);
+ new_tree = resolve_commit_oid_to_tree(g_repo, new_sha);
+ diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ opts.version = 0;
+ cl_git_fail(git_diff_find_similar(diff, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ giterr_clear();
+ opts.version = 1024;
+ cl_git_fail(git_diff_find_similar(diff, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ git_diff_list_free(diff);
+ git_tree_free(old_tree);
+ git_tree_free(new_tree);
+}
+
+void test_diff_rename__not_exact_match(void)
+{
+ const char *sha0 = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
+ const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
+ const char *sha2 = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
+ git_tree *old_tree, *new_tree;
+ git_diff_list *diff;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
+ diff_expects exp;
+
+ /* == Changes =====================================================
+ * songofseven.txt -> songofseven.txt (major rewrite, <20% match - split)
+ * sixserving.txt -> sixserving.txt (indentation change)
+ * sixserving.txt -> ikeepsix.txt (copy, add title, >80% match)
+ * sevencities.txt (no change)
+ */
+
+ old_tree = resolve_commit_oid_to_tree(g_repo, sha0);
+ new_tree = resolve_commit_oid_to_tree(g_repo, sha1);
+
+ /* Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
+ * --find-copies-harder during rename transformion...
+ */
+ diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
+
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ /* git diff --no-renames \
+ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084
+ */
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+
+ /* git diff -M 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084
+ *
+ * must not pass NULL for opts because it will pick up environment
+ * values for "diff.renames" and test won't be consistent.
+ */
+ opts.flags = GIT_DIFF_FIND_RENAMES;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+
+ git_diff_list_free(diff);
+
+ /* git diff -M -C \
+ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084
+ */
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ opts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
+
+ git_diff_list_free(diff);
+
+ /* git diff -M -C --find-copies-harder --break-rewrites \
+ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084
+ */
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ opts.flags = GIT_DIFF_FIND_ALL;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(5, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
+
+ git_diff_list_free(diff);
+
+ /* == Changes =====================================================
+ * songofseven.txt -> untimely.txt (rename, convert to crlf)
+ * ikeepsix.txt -> ikeepsix.txt (reorder sections in file)
+ * sixserving.txt -> sixserving.txt (whitespace - not just indent)
+ * sevencities.txt -> songof7cities.txt (rename, small text changes)
+ */
+
+ git_tree_free(old_tree);
+ old_tree = new_tree;
+ new_tree = resolve_commit_oid_to_tree(g_repo, sha2);
+
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ /* git diff --no-renames \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084 \
+ * 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
+ */
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(6, exp.files);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+ git_diff_list_free(diff);
+
+ /* git diff -M -C \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084 \
+ * 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
+ */
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ opts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
+
+ git_diff_list_free(diff);
+
+ /* git diff -M -C --find-copies-harder --break-rewrites \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084 \
+ * 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
+ * with libgit2 default similarity comparison...
+ */
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ opts.flags = GIT_DIFF_FIND_ALL;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ /* the default match algorithm is going to find the internal
+ * whitespace differences in the lines of sixserving.txt to be
+ * significant enough that this will decide to split it into
+ * an ADD and a DELETE
+ */
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(5, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
+
+ git_diff_list_free(diff);
+
+ /* git diff -M -C --find-copies-harder --break-rewrites \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084 \
+ * 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
+ * with ignore_space whitespace comparision
+ */
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
+ opts.flags = GIT_DIFF_FIND_ALL | GIT_DIFF_FIND_IGNORE_WHITESPACE;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ /* Ignoring whitespace, this should no longer split sixserver.txt */
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
+
+ git_diff_list_free(diff);
+
+ git_tree_free(old_tree);
+ git_tree_free(new_tree);
+}
+
+void test_diff_rename__handles_small_files(void)
+{
+ const char *tree_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
+ git_index *index;
+ git_tree *tree;
+ git_diff_list *diff;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ tree = resolve_commit_oid_to_tree(g_repo, tree_sha);
+
+ cl_git_rewritefile("renames/songof7cities.txt", "single line\n");
+ cl_git_pass(git_index_add_bypath(index, "songof7cities.txt"));
+
+ cl_git_rewritefile("renames/untimely.txt", "untimely\n");
+ cl_git_pass(git_index_add_bypath(index, "untimely.txt"));
+
+ /* Tests that we can invoke find_similar on small files
+ * and that the GIT_EBUFS (too small) error code is not
+ * propagated to the caller.
+ */
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, tree, index, &diffopts));
+
+ opts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES | GIT_DIFF_FIND_AND_BREAK_REWRITES;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ git_diff_list_free(diff);
+ git_tree_free(tree);
+ git_index_free(index);
+}
+
+void test_diff_rename__working_directory_changes(void)
+{
+ /* let's rewrite some files in the working directory on demand */
+
+ /* and with / without CRLF changes */
+}
diff --git a/tests-clar/diff/submodules.c b/tests-clar/diff/submodules.c
new file mode 100644
index 000000000..f152af46f
--- /dev/null
+++ b/tests-clar/diff/submodules.c
@@ -0,0 +1,168 @@
+#include "clar_libgit2.h"
+#include "repository.h"
+#include "../submodule/submodule_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+static void setup_submodules(void)
+{
+ g_repo = cl_git_sandbox_init("submodules");
+ cl_fixture_sandbox("testrepo.git");
+ rewrite_gitmodules(git_repository_workdir(g_repo));
+ p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git");
+}
+
+static void setup_submodules2(void)
+{
+ g_repo = cl_git_sandbox_init("submod2");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+
+ rewrite_gitmodules(git_repository_workdir(g_repo));
+ p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+ p_rename("submod2/not/.gitted", "submod2/not/.git");
+}
+
+void test_diff_submodules__initialize(void)
+{
+}
+
+void test_diff_submodules__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+
+ cl_fixture_cleanup("testrepo.git");
+ cl_fixture_cleanup("submod2_target");
+}
+
+static void check_diff_patches(git_diff_list *diff, const char **expected)
+{
+ const git_diff_delta *delta;
+ git_diff_patch *patch = NULL;
+ size_t d, num_d = git_diff_num_deltas(diff);
+ char *patch_text;
+
+ for (d = 0; d < num_d; ++d, git_diff_patch_free(patch)) {
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+
+ if (delta->status == GIT_DELTA_UNMODIFIED)
+ continue;
+
+ if (expected[d] && !strcmp(expected[d], "<SKIP>"))
+ continue;
+ if (expected[d] && !strcmp(expected[d], "<END>"))
+ cl_assert(0);
+
+ cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
+
+ cl_assert_equal_s(expected[d], patch_text);
+ git__free(patch_text);
+ }
+
+ cl_assert(expected[d] && !strcmp(expected[d], "<END>"));
+}
+
+void test_diff_submodules__unmodified_submodule(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ static const char *expected[] = {
+ "<SKIP>", /* .gitmodules */
+ NULL, /* added */
+ NULL, /* ignored */
+ "diff --git a/modified b/modified\nindex 092bfb9..452216e 100644\n--- a/modified\n+++ b/modified\n@@ -1 +1,2 @@\n-yo\n+changed\n+\n", /* modified */
+ NULL, /* testrepo.git */
+ NULL, /* unmodified */
+ NULL, /* untracked */
+ "<END>"
+ };
+
+ setup_submodules();
+
+ opts.flags = GIT_DIFF_INCLUDE_IGNORED |
+ GIT_DIFF_INCLUDE_UNTRACKED |
+ GIT_DIFF_INCLUDE_UNMODIFIED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ check_diff_patches(diff, expected);
+ git_diff_list_free(diff);
+}
+
+void test_diff_submodules__dirty_submodule(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ static const char *expected[] = {
+ "<SKIP>", /* .gitmodules */
+ NULL, /* added */
+ NULL, /* ignored */
+ "diff --git a/modified b/modified\nindex 092bfb9..452216e 100644\n--- a/modified\n+++ b/modified\n@@ -1 +1,2 @@\n-yo\n+changed\n+\n", /* modified */
+ "diff --git a/testrepo b/testrepo\nindex a65fedf..a65fedf 160000\n--- a/testrepo\n+++ b/testrepo\n@@ -1 +1 @@\n-Subproject commit a65fedf39aefe402d3bb6e24df4d4f5fe4547750\n+Subproject commit a65fedf39aefe402d3bb6e24df4d4f5fe4547750-dirty\n", /* testrepo.git */
+ NULL, /* unmodified */
+ NULL, /* untracked */
+ "<END>"
+ };
+
+ setup_submodules();
+
+ cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
+ cl_git_mkfile("submodules/testrepo/all_new.txt", "never seen before");
+
+ opts.flags = GIT_DIFF_INCLUDE_IGNORED |
+ GIT_DIFF_INCLUDE_UNTRACKED |
+ GIT_DIFF_INCLUDE_UNMODIFIED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ check_diff_patches(diff, expected);
+ git_diff_list_free(diff);
+}
+
+void test_diff_submodules__submod2_index_to_wd(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ static const char *expected[] = {
+ "<SKIP>", /* .gitmodules */
+ NULL, /* not-submodule */
+ NULL, /* not */
+ "diff --git a/sm_changed_file b/sm_changed_file\nindex 4800958..4800958 160000\n--- a/sm_changed_file\n+++ b/sm_changed_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_file */
+ "diff --git a/sm_changed_head b/sm_changed_head\nindex 4800958..3d9386c 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n", /* sm_changed_head */
+ "diff --git a/sm_changed_index b/sm_changed_index\nindex 4800958..4800958 160000\n--- a/sm_changed_index\n+++ b/sm_changed_index\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_index */
+ "diff --git a/sm_changed_untracked_file b/sm_changed_untracked_file\nindex 4800958..4800958 160000\n--- a/sm_changed_untracked_file\n+++ b/sm_changed_untracked_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_untracked_file */
+ "diff --git a/sm_missing_commits b/sm_missing_commits\nindex 4800958..5e49635 160000\n--- a/sm_missing_commits\n+++ b/sm_missing_commits\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 5e4963595a9774b90524d35a807169049de8ccad\n", /* sm_missing_commits */
+ "<END>"
+ };
+
+ setup_submodules2();
+
+ opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ check_diff_patches(diff, expected);
+ git_diff_list_free(diff);
+}
+
+void test_diff_submodules__submod2_head_to_index(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_tree *head;
+ git_diff_list *diff = NULL;
+ static const char *expected[] = {
+ "<SKIP>", /* .gitmodules */
+ "diff --git a/sm_added_and_uncommited b/sm_added_and_uncommited\nnew file mode 160000\nindex 0000000..4800958\n--- /dev/null\n+++ b/sm_added_and_uncommited\n@@ -0,0 +1 @@\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n", /* sm_added_and_uncommited */
+ "<END>"
+ };
+
+ setup_submodules2();
+
+ cl_git_pass(git_repository_head_tree(&head, g_repo));
+
+ opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, head, NULL, &opts));
+ check_diff_patches(diff, expected);
+ git_diff_list_free(diff);
+
+ git_tree_free(head);
+}
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index b932fa10e..850feefde 100644
--- a/tests-clar/diff/tree.c
+++ b/tests-clar/diff/tree.c
@@ -2,14 +2,32 @@
#include "diff_helpers.h"
static git_repository *g_repo = NULL;
+static git_diff_options opts;
+static git_diff_list *diff;
+static git_tree *a, *b;
+static diff_expects expect;
void test_diff_tree__initialize(void)
{
+ GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION);
+ /* The default context lines is set by _INIT which we can't use here */
+ opts.context_lines = 3;
+
+ memset(&expect, 0, sizeof(expect));
+
+ diff = NULL;
+ a = NULL;
+ b = NULL;
}
void test_diff_tree__cleanup(void)
{
+ git_diff_list_free(diff);
+ git_tree_free(a);
+ git_tree_free(b);
+
cl_git_sandbox_cleanup();
+
}
void test_diff_tree__0(void)
@@ -18,10 +36,7 @@ void test_diff_tree__0(void)
const char *a_commit = "605812a";
const char *b_commit = "370fe9ec22";
const char *c_commit = "f5b0af1fb4f5c";
- git_tree *a, *b, *c;
- git_diff_options opts = {0};
- git_diff_list *diff = NULL;
- diff_expects exp;
+ git_tree *c;
g_repo = cl_git_sandbox_init("attr");
@@ -32,51 +47,46 @@ void test_diff_tree__0(void)
opts.context_lines = 1;
opts.interhunk_lines = 1;
- memset(&exp, 0, sizeof(exp));
- cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff));
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
- cl_assert(exp.files == 5);
- cl_assert(exp.file_adds == 2);
- cl_assert(exp.file_dels == 1);
- cl_assert(exp.file_mods == 2);
+ cl_assert_equal_i(5, expect.files);
+ cl_assert_equal_i(2, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(2, expect.file_status[GIT_DELTA_MODIFIED]);
- cl_assert(exp.hunks == 5);
+ cl_assert_equal_i(5, expect.hunks);
- cl_assert(exp.lines == 7 + 24 + 1 + 6 + 6);
- cl_assert(exp.line_ctxt == 1);
- cl_assert(exp.line_adds == 24 + 1 + 5 + 5);
- cl_assert(exp.line_dels == 7 + 1);
+ cl_assert_equal_i(7 + 24 + 1 + 6 + 6, expect.lines);
+ cl_assert_equal_i(1, expect.line_ctxt);
+ cl_assert_equal_i(24 + 1 + 5 + 5, expect.line_adds);
+ cl_assert_equal_i(7 + 1, expect.line_dels);
git_diff_list_free(diff);
diff = NULL;
- memset(&exp, 0, sizeof(exp));
+ memset(&expect, 0, sizeof(expect));
- cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, c, b, &diff));
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, b, &opts));
cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
-
- cl_assert(exp.files == 2);
- cl_assert(exp.file_adds == 0);
- cl_assert(exp.file_dels == 0);
- cl_assert(exp.file_mods == 2);
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
- cl_assert(exp.hunks == 2);
+ cl_assert_equal_i(2, expect.files);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(2, expect.file_status[GIT_DELTA_MODIFIED]);
- cl_assert(exp.lines == 8 + 15);
- cl_assert(exp.line_ctxt == 1);
- cl_assert(exp.line_adds == 1);
- cl_assert(exp.line_dels == 7 + 14);
+ cl_assert_equal_i(2, expect.hunks);
- git_diff_list_free(diff);
+ cl_assert_equal_i(8 + 15, expect.lines);
+ cl_assert_equal_i(1, expect.line_ctxt);
+ cl_assert_equal_i(1, expect.line_adds);
+ cl_assert_equal_i(7 + 14, expect.line_dels);
- git_tree_free(a);
- git_tree_free(b);
git_tree_free(c);
}
@@ -87,46 +97,47 @@ void test_diff_tree__options(void)
const char *b_commit = "605812ab7fe421fdd";
const char *c_commit = "f5b0af1fb4f5";
const char *d_commit = "a97cc019851";
- git_tree *a, *b, *c, *d;
- git_diff_options opts = {0};
- git_diff_list *diff = NULL;
+ git_tree *c, *d;
diff_expects actual;
int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 };
git_diff_options test_options[] = {
/* a vs b tests */
- { GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} },
- { GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
- { GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} },
- { GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} },
/* c vs d tests */
- { GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
- { GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} },
- { GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} },
- { GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} },
- { GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} },
+ { 1, GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} },
};
+
/* to generate these values:
* - cd to tests/resources/attr,
* - mv .gitted .git
* - git diff [options] 6bab5c79cd5140d0 605812ab7fe421fdd
* - mv .git .gitted
*/
+#define EXPECT_STATUS_ADM(ADDS,DELS,MODS) { 0, ADDS, DELS, MODS, 0, 0, 0, 0, 0 }
+
diff_expects test_expects[] = {
/* a vs b tests */
- { 5, 3, 0, 2, 0, 0, 0, 4, 0, 0, 51, 2, 46, 3 },
- { 5, 3, 0, 2, 0, 0, 0, 4, 0, 0, 53, 4, 46, 3 },
- { 5, 0, 3, 2, 0, 0, 0, 4, 0, 0, 52, 3, 3, 46 },
- { 5, 3, 0, 2, 0, 0, 0, 5, 0, 0, 54, 3, 48, 3 },
+ { 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 4, 0, 0, 51, 2, 46, 3 },
+ { 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 4, 0, 0, 53, 4, 46, 3 },
+ { 5, 0, EXPECT_STATUS_ADM(0, 3, 2), 4, 0, 0, 52, 3, 3, 46 },
+ { 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 5, 0, 0, 54, 3, 47, 4 },
/* c vs d tests */
- { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 22, 9, 10, 3 },
- { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 19, 12, 7, 0 },
- { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 11, 8, 1 },
- { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 11, 8, 1 },
- { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 18, 11, 0, 7 },
+ { 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 22, 9, 10, 3 },
+ { 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 19, 12, 7, 0 },
+ { 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 20, 11, 8, 1 },
+ { 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 20, 11, 8, 1 },
+ { 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 18, 11, 0, 7 },
{ 0 },
};
diff_expects *expected;
- int i;
+ int i, j;
g_repo = cl_git_sandbox_init("attr");
@@ -140,18 +151,17 @@ void test_diff_tree__options(void)
opts = test_options[i];
if (test_ab_or_cd[i] == 0)
- cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff));
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
else
- cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, c, d, &diff));
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, d, &opts));
cl_git_pass(git_diff_foreach(
- diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &actual));
expected = &test_expects[i];
cl_assert_equal_i(actual.files, expected->files);
- cl_assert_equal_i(actual.file_adds, expected->file_adds);
- cl_assert_equal_i(actual.file_dels, expected->file_dels);
- cl_assert_equal_i(actual.file_mods, expected->file_mods);
+ for (j = GIT_DELTA_UNMODIFIED; j <= GIT_DELTA_TYPECHANGE; ++j)
+ cl_assert_equal_i(expected->file_status[j], actual.file_status[j]);
cl_assert_equal_i(actual.hunks, expected->hunks);
cl_assert_equal_i(actual.lines, expected->lines);
cl_assert_equal_i(actual.line_ctxt, expected->line_ctxt);
@@ -162,8 +172,6 @@ void test_diff_tree__options(void)
diff = NULL;
}
- git_tree_free(a);
- git_tree_free(b);
git_tree_free(c);
git_tree_free(d);
}
@@ -172,10 +180,6 @@ void test_diff_tree__bare(void)
{
const char *a_commit = "8496071c1b46c85";
const char *b_commit = "be3563ae3f79";
- git_tree *a, *b;
- git_diff_options opts = {0};
- git_diff_list *diff = NULL;
- diff_expects exp;
g_repo = cl_git_sandbox_init("testrepo.git");
@@ -185,26 +189,268 @@ void test_diff_tree__bare(void)
opts.context_lines = 1;
opts.interhunk_lines = 1;
- memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
- cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, a, b, &diff));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
+
+ cl_assert_equal_i(3, expect.files);
+ cl_assert_equal_i(2, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_MODIFIED]);
+
+ cl_assert_equal_i(3, expect.hunks);
+
+ cl_assert_equal_i(4, expect.lines);
+ cl_assert_equal_i(0, expect.line_ctxt);
+ cl_assert_equal_i(3, expect.line_adds);
+ cl_assert_equal_i(1, expect.line_dels);
+}
+
+void test_diff_tree__merge(void)
+{
+ /* grabbed a couple of commit oids from the history of the attr repo */
+ const char *a_commit = "605812a";
+ const char *b_commit = "370fe9ec22";
+ const char *c_commit = "f5b0af1fb4f5c";
+ git_tree *c;
+ git_diff_list *diff1 = NULL, *diff2 = NULL;
+
+ g_repo = cl_git_sandbox_init("attr");
+
+ cl_assert((a = resolve_commit_oid_to_tree(g_repo, a_commit)) != NULL);
+ cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL);
+ cl_assert((c = resolve_commit_oid_to_tree(g_repo, c_commit)) != NULL);
+
+ cl_git_pass(git_diff_tree_to_tree(&diff1, g_repo, a, b, NULL));
+
+ cl_git_pass(git_diff_tree_to_tree(&diff2, g_repo, c, b, NULL));
+
+ git_tree_free(c);
+
+ cl_git_pass(git_diff_merge(diff1, diff2));
+
+ git_diff_list_free(diff2);
cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
- cl_assert(exp.files == 3);
- cl_assert(exp.file_adds == 2);
- cl_assert(exp.file_dels == 0);
- cl_assert(exp.file_mods == 1);
+ cl_assert_equal_i(6, expect.files);
+ cl_assert_equal_i(2, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(3, expect.file_status[GIT_DELTA_MODIFIED]);
- cl_assert(exp.hunks == 3);
+ cl_assert_equal_i(6, expect.hunks);
- cl_assert(exp.lines == 4);
- cl_assert(exp.line_ctxt == 0);
- cl_assert(exp.line_adds == 3);
- cl_assert(exp.line_dels == 1);
+ cl_assert_equal_i(59, expect.lines);
+ cl_assert_equal_i(1, expect.line_ctxt);
+ cl_assert_equal_i(36, expect.line_adds);
+ cl_assert_equal_i(22, expect.line_dels);
- git_diff_list_free(diff);
- git_tree_free(a);
- git_tree_free(b);
+ git_diff_list_free(diff1);
+}
+
+void test_diff_tree__larger_hunks(void)
+{
+ const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
+ const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
+ size_t d, num_d, h, num_h, l, num_l, header_len, line_len;
+ const git_diff_delta *delta;
+ git_diff_patch *patch;
+ const git_diff_range *range;
+ const char *header, *line;
+ char origin;
+
+ g_repo = cl_git_sandbox_init("diff");
+
+ cl_assert((a = resolve_commit_oid_to_tree(g_repo, a_commit)) != NULL);
+ cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL);
+
+ opts.context_lines = 1;
+ opts.interhunk_lines = 0;
+
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
+
+ num_d = git_diff_num_deltas(diff);
+ for (d = 0; d < num_d; ++d) {
+ cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+ cl_assert(patch && delta);
+
+ num_h = git_diff_patch_num_hunks(patch);
+ for (h = 0; h < num_h; h++) {
+ cl_git_pass(git_diff_patch_get_hunk(
+ &range, &header, &header_len, &num_l, patch, h));
+
+ for (l = 0; l < num_l; ++l) {
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &line, &line_len, NULL, NULL, patch, h, l));
+ cl_assert(line);
+ }
+
+ cl_git_fail(git_diff_patch_get_line_in_hunk(
+ &origin, &line, &line_len, NULL, NULL, patch, h, num_l));
+ }
+
+ cl_git_fail(git_diff_patch_get_hunk(
+ &range, &header, &header_len, &num_l, patch, num_h));
+
+ git_diff_patch_free(patch);
+ }
+
+ cl_git_fail(git_diff_get_patch(&patch, &delta, diff, num_d));
+
+ cl_assert_equal_i(2, (int)num_d);
+}
+
+void test_diff_tree__checks_options_version(void)
+{
+ const char *a_commit = "8496071c1b46c85";
+ const char *b_commit = "be3563ae3f79";
+ const git_error *err;
+
+ g_repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_assert((a = resolve_commit_oid_to_tree(g_repo, a_commit)) != NULL);
+ cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL);
+
+ opts.version = 0;
+ cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ giterr_clear();
+ opts.version = 1024;
+ cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
+ err = giterr_last();
+}
+
+void process_tree_to_tree_diffing(
+ const char *old_commit,
+ const char *new_commit)
+{
+ g_repo = cl_git_sandbox_init("unsymlinked.git");
+
+ cl_assert((a = resolve_commit_oid_to_tree(g_repo, old_commit)) != NULL);
+ cl_assert((b = resolve_commit_oid_to_tree(g_repo, new_commit)) != NULL);
+
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, NULL, NULL, &expect));
+}
+
+void test_diff_tree__symlink_blob_mode_changed_to_regular_file(void)
+{
+ /*
+ * $ git diff 7fccd7..806999
+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
+ * deleted file mode 120000
+ * index 19bf568..0000000
+ * --- a/include/Nu/Nu.h
+ * +++ /dev/null
+ * @@ -1 +0,0 @@
+ * -../../objc/Nu.h
+ * \ No newline at end of file
+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
+ * new file mode 100644
+ * index 0000000..f9e6561
+ * --- /dev/null
+ * +++ b/include/Nu/Nu.h
+ * @@ -0,0 +1 @@
+ * +awesome content
+ * diff --git a/objc/Nu.h b/objc/Nu.h
+ * deleted file mode 100644
+ * index f9e6561..0000000
+ * --- a/objc/Nu.h
+ * +++ /dev/null
+ * @@ -1 +0,0 @@
+ * -awesome content
+ */
+
+ process_tree_to_tree_diffing("7fccd7", "806999");
+
+ cl_assert_equal_i(3, expect.files);
+ cl_assert_equal_i(2, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_TYPECHANGE]);
+}
+
+void test_diff_tree__symlink_blob_mode_changed_to_regular_file_as_typechange(void)
+{
+ /*
+ * $ git diff 7fccd7..a8595c
+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
+ * deleted file mode 120000
+ * index 19bf568..0000000
+ * --- a/include/Nu/Nu.h
+ * +++ /dev/null
+ * @@ -1 +0,0 @@
+ * -../../objc/Nu.h
+ * \ No newline at end of file
+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
+ * new file mode 100755
+ * index 0000000..f9e6561
+ * --- /dev/null
+ * +++ b/include/Nu/Nu.h
+ * @@ -0,0 +1 @@
+ * +awesome content
+ * diff --git a/objc/Nu.h b/objc/Nu.h
+ * deleted file mode 100644
+ * index f9e6561..0000000
+ * --- a/objc/Nu.h
+ * +++ /dev/null
+ * @@ -1 +0,0 @@
+ * -awesome content
+ */
+
+ opts.flags = GIT_DIFF_INCLUDE_TYPECHANGE;
+ process_tree_to_tree_diffing("7fccd7", "a8595c");
+
+ cl_assert_equal_i(2, expect.files);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_TYPECHANGE]);
+}
+
+void test_diff_tree__regular_blob_mode_changed_to_executable_file(void)
+{
+ /*
+ * $ git diff 806999..a8595c
+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
+ * old mode 100644
+ * new mode 100755
+ */
+
+ process_tree_to_tree_diffing("806999", "a8595c");
+
+ cl_assert_equal_i(1, expect.files);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_TYPECHANGE]);
+}
+
+void test_diff_tree__issue_1397(void)
+{
+ /* this test shows that it is not needed */
+
+ g_repo = cl_git_sandbox_init("issue_1397");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ cl_assert((a = resolve_commit_oid_to_tree(g_repo, "8a7ef04")) != NULL);
+ cl_assert((b = resolve_commit_oid_to_tree(g_repo, "7f483a7")) != NULL);
+
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
+
+ cl_assert_equal_i(1, expect.files);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, expect.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, expect.file_status[GIT_DELTA_TYPECHANGE]);
}
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 1ea1af86a..9d92d8d60 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -1,11 +1,11 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
+#include "repository.h"
static git_repository *g_repo = NULL;
void test_diff_workdir__initialize(void)
{
- g_repo = cl_git_sandbox_init("status");
}
void test_diff_workdir__cleanup(void)
@@ -15,41 +15,50 @@ void test_diff_workdir__cleanup(void)
void test_diff_workdir__to_index(void)
{
- git_diff_options opts = {0};
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
diff_expects exp;
+ int use_iterator;
+
+ g_repo = cl_git_sandbox_init("status");
opts.context_lines = 3;
opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
- memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff));
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
- cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
-
- /* to generate these values:
- * - cd to tests/resources/status,
- * - mv .gitted .git
- * - git diff --name-status
- * - git diff
- * - mv .git .gitted
- */
- cl_assert_equal_i(12, exp.files);
- cl_assert_equal_i(0, exp.file_adds);
- cl_assert_equal_i(4, exp.file_dels);
- cl_assert_equal_i(4, exp.file_mods);
- cl_assert_equal_i(1, exp.file_ignored);
- cl_assert_equal_i(3, exp.file_untracked);
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ /* to generate these values:
+ * - cd to tests/resources/status,
+ * - mv .gitted .git
+ * - git diff --name-status
+ * - git diff
+ * - mv .git .gitted
+ */
+ cl_assert_equal_i(13, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
- cl_assert_equal_i(8, exp.hunks);
+ cl_assert_equal_i(8, exp.hunks);
- cl_assert_equal_i(14, exp.lines);
- cl_assert_equal_i(5, exp.line_ctxt);
- cl_assert_equal_i(4, exp.line_adds);
- cl_assert_equal_i(5, exp.line_dels);
+ cl_assert_equal_i(14, exp.lines);
+ cl_assert_equal_i(5, exp.line_ctxt);
+ cl_assert_equal_i(4, exp.line_adds);
+ cl_assert_equal_i(5, exp.line_dels);
+ }
git_diff_list_free(diff);
}
@@ -59,20 +68,23 @@ void test_diff_workdir__to_tree(void)
/* grabbed a couple of commit oids from the history of the attr repo */
const char *a_commit = "26a125ee1bf"; /* the current HEAD */
const char *b_commit = "0017bd4ab1ec3"; /* the start */
- git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
- git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
- git_diff_options opts = {0};
+ git_tree *a, *b;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff_list *diff2 = NULL;
diff_expects exp;
+ int use_iterator;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ a = resolve_commit_oid_to_tree(g_repo, a_commit);
+ b = resolve_commit_oid_to_tree(g_repo, b_commit);
opts.context_lines = 3;
opts.interhunk_lines = 1;
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
- memset(&exp, 0, sizeof(exp));
-
- /* You can't really generate the equivalent of git_diff_workdir_to_tree()
+ /* You can't really generate the equivalent of git_diff_tree_to_workdir()
* using C git. It really wants to interpose the index into the diff.
*
* To validate the following results with command line git, I ran the
@@ -82,17 +94,25 @@ void test_diff_workdir__to_tree(void)
* The results are documented at the bottom of this file in the
* long comment entitled "PREPARATION OF TEST DATA".
*/
- cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff));
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
- cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- cl_assert(exp.files == 13);
- cl_assert(exp.file_adds == 0);
- cl_assert(exp.file_dels == 4);
- cl_assert(exp.file_mods == 4);
- cl_assert(exp.file_ignored == 1);
- cl_assert(exp.file_untracked == 4);
+ cl_assert_equal_i(14, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(5, exp.file_status[GIT_DELTA_UNTRACKED]);
+ }
/* Since there is no git diff equivalent, let's just assume that the
* text diffs produced by git_diff_foreach are accurate here. We will
@@ -107,27 +127,35 @@ void test_diff_workdir__to_tree(void)
* a workdir to tree diff (even though it is not really). This is what
* you would get from "git diff --name-status 26a125ee1bf"
*/
- cl_git_pass(git_diff_index_to_tree(g_repo, &opts, a, &diff));
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff2));
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
- cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- cl_assert(exp.files == 14);
- cl_assert(exp.file_adds == 2);
- cl_assert(exp.file_dels == 5);
- cl_assert(exp.file_mods == 4);
- cl_assert(exp.file_ignored == 1);
- cl_assert(exp.file_untracked == 2);
+ cl_assert_equal_i(15, exp.files);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(5, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
- cl_assert(exp.hunks == 11);
+ cl_assert_equal_i(11, exp.hunks);
- cl_assert(exp.lines == 17);
- cl_assert(exp.line_ctxt == 4);
- cl_assert(exp.line_adds == 8);
- cl_assert(exp.line_dels == 5);
+ cl_assert_equal_i(17, exp.lines);
+ cl_assert_equal_i(4, exp.line_ctxt);
+ cl_assert_equal_i(8, exp.line_adds);
+ cl_assert_equal_i(5, exp.line_dels);
+ }
git_diff_list_free(diff);
diff = NULL;
@@ -136,27 +164,35 @@ void test_diff_workdir__to_tree(void)
/* Again, emulating "git diff <sha>" for testing purposes using
* "git diff --name-status 0017bd4ab1ec3" instead.
*/
- cl_git_pass(git_diff_index_to_tree(g_repo, &opts, b, &diff));
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff2));
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, b, NULL, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
- cl_git_pass(git_diff_foreach(
- diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- cl_assert(exp.files == 15);
- cl_assert(exp.file_adds == 5);
- cl_assert(exp.file_dels == 4);
- cl_assert(exp.file_mods == 3);
- cl_assert(exp.file_ignored == 1);
- cl_assert(exp.file_untracked == 2);
+ cl_assert_equal_i(16, exp.files);
+ cl_assert_equal_i(5, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
- cl_assert(exp.hunks == 12);
+ cl_assert_equal_i(12, exp.hunks);
- cl_assert(exp.lines == 19);
- cl_assert(exp.line_ctxt == 3);
- cl_assert(exp.line_adds == 12);
- cl_assert(exp.line_dels == 4);
+ cl_assert_equal_i(19, exp.lines);
+ cl_assert_equal_i(3, exp.line_ctxt);
+ cl_assert_equal_i(12, exp.line_adds);
+ cl_assert_equal_i(4, exp.line_dels);
+ }
git_diff_list_free(diff);
@@ -166,10 +202,13 @@ void test_diff_workdir__to_tree(void)
void test_diff_workdir__to_index_with_pathspec(void)
{
- git_diff_options opts = {0};
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
diff_expects exp;
char *pathspec = NULL;
+ int use_iterator;
+
+ g_repo = cl_git_sandbox_init("status");
opts.context_lines = 3;
opts.interhunk_lines = 1;
@@ -177,69 +216,396 @@ void test_diff_workdir__to_index_with_pathspec(void)
opts.pathspec.strings = &pathspec;
opts.pathspec.count = 1;
- memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff));
- cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
- cl_assert_equal_i(12, exp.files);
- cl_assert_equal_i(0, exp.file_adds);
- cl_assert_equal_i(4, exp.file_dels);
- cl_assert_equal_i(4, exp.file_mods);
- cl_assert_equal_i(1, exp.file_ignored);
- cl_assert_equal_i(3, exp.file_untracked);
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, NULL, NULL, &exp));
+ else
+ cl_git_pass(git_diff_foreach(diff, diff_file_cb, NULL, NULL, &exp));
+
+ cl_assert_equal_i(13, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
+ }
git_diff_list_free(diff);
- memset(&exp, 0, sizeof(exp));
pathspec = "modified_file";
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff));
- cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- cl_assert_equal_i(1, exp.files);
- cl_assert_equal_i(0, exp.file_adds);
- cl_assert_equal_i(0, exp.file_dels);
- cl_assert_equal_i(1, exp.file_mods);
- cl_assert_equal_i(0, exp.file_ignored);
- cl_assert_equal_i(0, exp.file_untracked);
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, NULL, NULL, &exp));
+ else
+ cl_git_pass(git_diff_foreach(diff, diff_file_cb, NULL, NULL, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
+ }
git_diff_list_free(diff);
- memset(&exp, 0, sizeof(exp));
pathspec = "subdir";
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff));
- cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- cl_assert_equal_i(3, exp.files);
- cl_assert_equal_i(0, exp.file_adds);
- cl_assert_equal_i(1, exp.file_dels);
- cl_assert_equal_i(1, exp.file_mods);
- cl_assert_equal_i(0, exp.file_ignored);
- cl_assert_equal_i(1, exp.file_untracked);
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, NULL, NULL, &exp));
+ else
+ cl_git_pass(git_diff_foreach(diff, diff_file_cb, NULL, NULL, &exp));
+
+ cl_assert_equal_i(3, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
+ }
git_diff_list_free(diff);
- memset(&exp, 0, sizeof(exp));
pathspec = "*_deleted";
- cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff));
- cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, NULL, NULL, &exp));
+ else
+ cl_git_pass(git_diff_foreach(diff, diff_file_cb, NULL, NULL, &exp));
- cl_assert_equal_i(2, exp.files);
- cl_assert_equal_i(0, exp.file_adds);
- cl_assert_equal_i(2, exp.file_dels);
- cl_assert_equal_i(0, exp.file_mods);
- cl_assert_equal_i(0, exp.file_ignored);
- cl_assert_equal_i(0, exp.file_untracked);
+ cl_assert_equal_i(2, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
+ }
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_workdir__filemode_changes(void)
+{
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+ int use_iterator;
+
+ if (!cl_is_chmod_supported())
+ return;
+
+ g_repo = cl_git_sandbox_init("issue_592");
+
+ cl_repo_set_bool(g_repo, "core.filemode", true);
+
+ /* test once with no mods */
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.hunks);
+ }
+
+ git_diff_list_free(diff);
+
+ /* chmod file and test again */
+
+ cl_assert(cl_toggle_filemode("issue_592/a.txt"));
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.hunks);
+ }
+
+ git_diff_list_free(diff);
+
+ cl_assert(cl_toggle_filemode("issue_592/a.txt"));
+}
+
+void test_diff_workdir__filemode_changes_with_filemode_false(void)
+{
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+
+ if (!cl_is_chmod_supported())
+ return;
+
+ g_repo = cl_git_sandbox_init("issue_592");
+
+ cl_repo_set_bool(g_repo, "core.filemode", false);
+
+ /* test once with no mods */
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.hunks);
+
+ git_diff_list_free(diff);
+
+ /* chmod file and test again */
+
+ cl_assert(cl_toggle_filemode("issue_592/a.txt"));
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.hunks);
+
+ git_diff_list_free(diff);
+
+ cl_assert(cl_toggle_filemode("issue_592/a.txt"));
+}
+
+void test_diff_workdir__head_index_and_workdir_all_differ(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff_i2t = NULL, *diff_w2i = NULL;
+ diff_expects exp;
+ char *pathspec = "staged_changes_modified_file";
+ git_tree *tree;
+ int use_iterator;
+
+ /* For this file,
+ * - head->index diff has 1 line of context, 1 line of diff
+ * - index->workdir diff has 2 lines of context, 1 line of diff
+ * but
+ * - head->workdir diff has 1 line of context, 2 lines of diff
+ * Let's make sure the right one is returned from each fn.
+ */
+
+ g_repo = cl_git_sandbox_init("status");
+
+ tree = resolve_commit_oid_to_tree(g_repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
+
+ opts.pathspec.strings = &pathspec;
+ opts.pathspec.count = 1;
+
+ cl_git_pass(git_diff_tree_to_index(&diff_i2t, g_repo, tree, NULL, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff_w2i, g_repo, NULL, &opts));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff_i2t, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff_i2t, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.hunks);
+ cl_assert_equal_i(2, exp.lines);
+ cl_assert_equal_i(1, exp.line_ctxt);
+ cl_assert_equal_i(1, exp.line_adds);
+ cl_assert_equal_i(0, exp.line_dels);
+ }
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff_w2i, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff_w2i, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.hunks);
+ cl_assert_equal_i(3, exp.lines);
+ cl_assert_equal_i(2, exp.line_ctxt);
+ cl_assert_equal_i(1, exp.line_adds);
+ cl_assert_equal_i(0, exp.line_dels);
+ }
+
+ cl_git_pass(git_diff_merge(diff_i2t, diff_w2i));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff_i2t, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff_i2t, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.hunks);
+ cl_assert_equal_i(3, exp.lines);
+ cl_assert_equal_i(1, exp.line_ctxt);
+ cl_assert_equal_i(2, exp.line_adds);
+ cl_assert_equal_i(0, exp.line_dels);
+ }
+
+ git_diff_list_free(diff_i2t);
+ git_diff_list_free(diff_w2i);
+
+ git_tree_free(tree);
+}
+
+void test_diff_workdir__eof_newline_changes(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+ char *pathspec = "current_file";
+ int use_iterator;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ opts.pathspec.strings = &pathspec;
+ opts.pathspec.count = 1;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
+ cl_assert_equal_i(0, exp.line_ctxt);
+ cl_assert_equal_i(0, exp.line_adds);
+ cl_assert_equal_i(0, exp.line_dels);
+ }
+
+ git_diff_list_free(diff);
+
+ cl_git_append2file("status/current_file", "\n");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.hunks);
+ cl_assert_equal_i(2, exp.lines);
+ cl_assert_equal_i(1, exp.line_ctxt);
+ cl_assert_equal_i(1, exp.line_adds);
+ cl_assert_equal_i(0, exp.line_dels);
+ }
+
+ git_diff_list_free(diff);
+
+ cl_git_rewritefile("status/current_file", "current_file");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
+ memset(&exp, 0, sizeof(exp));
+
+ if (use_iterator)
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ else
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.hunks);
+ cl_assert_equal_i(3, exp.lines);
+ cl_assert_equal_i(0, exp.line_ctxt);
+ cl_assert_equal_i(1, exp.line_adds);
+ cl_assert_equal_i(2, exp.line_dels);
+ }
git_diff_list_free(diff);
}
/* PREPARATION OF TEST DATA
*
- * Since there is no command line equivalent of git_diff_workdir_to_tree,
+ * Since there is no command line equivalent of git_diff_tree_to_workdir,
* it was a bit of a pain to confirm that I was getting the expected
* results in the first part of this tests. Here is what I ended up
* doing to set my expectation for the file counts and results:
@@ -299,3 +665,370 @@ void test_diff_workdir__to_index_with_pathspec(void)
*
* Expect 13 files, 0 ADD, 4 DEL, 4 MOD, 1 IGN, 4 UNTR
*/
+
+
+void test_diff_workdir__larger_hunks(void)
+{
+ const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
+ const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
+ git_tree *a, *b;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ size_t i, d, num_d, h, num_h, l, num_l, header_len, line_len;
+
+ g_repo = cl_git_sandbox_init("diff");
+
+ cl_assert((a = resolve_commit_oid_to_tree(g_repo, a_commit)) != NULL);
+ cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL);
+
+ opts.context_lines = 1;
+ opts.interhunk_lines = 0;
+
+ for (i = 0; i <= 2; ++i) {
+ git_diff_list *diff = NULL;
+ git_diff_patch *patch;
+ const git_diff_range *range;
+ const char *header, *line;
+ char origin;
+
+ /* okay, this is a bit silly, but oh well */
+ switch (i) {
+ case 0:
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ break;
+ case 1:
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
+ break;
+ case 2:
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, b, &opts));
+ break;
+ }
+
+ num_d = git_diff_num_deltas(diff);
+ cl_assert_equal_i(2, (int)num_d);
+
+ for (d = 0; d < num_d; ++d) {
+ cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
+ cl_assert(patch);
+
+ num_h = git_diff_patch_num_hunks(patch);
+ for (h = 0; h < num_h; h++) {
+ cl_git_pass(git_diff_patch_get_hunk(
+ &range, &header, &header_len, &num_l, patch, h));
+
+ for (l = 0; l < num_l; ++l) {
+ cl_git_pass(git_diff_patch_get_line_in_hunk(
+ &origin, &line, &line_len, NULL, NULL, patch, h, l));
+ cl_assert(line);
+ }
+
+ /* confirm fail after the last item */
+ cl_git_fail(git_diff_patch_get_line_in_hunk(
+ &origin, &line, &line_len, NULL, NULL, patch, h, num_l));
+ }
+
+ /* confirm fail after the last item */
+ cl_git_fail(git_diff_patch_get_hunk(
+ &range, &header, &header_len, &num_l, patch, num_h));
+
+ git_diff_patch_free(patch);
+ }
+
+ git_diff_list_free(diff);
+ }
+
+ git_tree_free(a);
+ git_tree_free(b);
+}
+
+/* Set up a test that exercises this code. The easiest test using existing
+ * test data is probably to create a sandbox of submod2 and then run a
+ * git_diff_tree_to_workdir against tree
+ * 873585b94bdeabccea991ea5e3ec1a277895b698. As for what you should actually
+ * test, you can start by just checking that the number of lines of diff
+ * content matches the actual output of git diff. That will at least
+ * demonstrate that the submodule content is being used to generate somewhat
+ * comparable outputs. It is a test that would fail without this code and
+ * will succeed with it.
+ */
+
+#include "../submodule/submodule_helpers.h"
+
+void test_diff_workdir__submodules(void)
+{
+ const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698";
+ git_tree *a;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+
+ g_repo = cl_git_sandbox_init("submod2");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+
+ rewrite_gitmodules(git_repository_workdir(g_repo));
+ p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+ p_rename("submod2/not/.gitted", "submod2/not/.git");
+
+ cl_fixture_cleanup("submod2_target");
+
+ a = resolve_commit_oid_to_tree(g_repo, a_commit);
+
+ opts.flags =
+ GIT_DIFF_INCLUDE_UNTRACKED |
+ GIT_DIFF_RECURSE_UNTRACKED_DIRS |
+ GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
+
+ /* diff_print(stderr, diff); */
+
+ /* essentially doing: git diff 873585b94bdeabccea991ea5e3ec1a277895b698 */
+
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ /* so "git diff 873585" returns:
+ * M .gitmodules
+ * A just_a_dir/contents
+ * A just_a_file
+ * A sm_added_and_uncommited
+ * A sm_changed_file
+ * A sm_changed_head
+ * A sm_changed_index
+ * A sm_changed_untracked_file
+ * M sm_missing_commits
+ * A sm_unchanged
+ * which is a little deceptive because of the difference between the
+ * "git diff <treeish>" results from "git_diff_tree_to_workdir". The
+ * only significant difference is that those Added items will show up
+ * as Untracked items in the pure libgit2 diff.
+ *
+ * Then add in the two extra untracked items "not" and "not-submodule"
+ * to get the 12 files reported here.
+ */
+
+ cl_assert_equal_i(12, exp.files);
+
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+ cl_assert_equal_i(10, exp.file_status[GIT_DELTA_UNTRACKED]);
+
+ /* the following numbers match "git diff 873585" exactly */
+
+ cl_assert_equal_i(9, exp.hunks);
+
+ cl_assert_equal_i(33, exp.lines);
+ cl_assert_equal_i(2, exp.line_ctxt);
+ cl_assert_equal_i(30, exp.line_adds);
+ cl_assert_equal_i(1, exp.line_dels);
+
+ git_diff_list_free(diff);
+ git_tree_free(a);
+}
+
+void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ git_tree *tree;
+
+ g_repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_assert_equal_i(
+ GIT_EBAREREPO, git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ cl_git_pass(git_repository_head_tree(&tree, g_repo));
+
+ cl_assert_equal_i(
+ GIT_EBAREREPO, git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+
+ git_tree_free(tree);
+}
+
+void test_diff_workdir__to_null_tree(void)
+{
+ git_diff_list *diff;
+ diff_expects exp;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+
+ opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
+ GIT_DIFF_RECURSE_UNTRACKED_DIRS;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, NULL, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(exp.files, exp.file_status[GIT_DELTA_UNTRACKED]);
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_workdir__checks_options_version(void)
+{
+ git_diff_list *diff;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ const git_error *err;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ opts.version = 0;
+ cl_git_fail(git_diff_tree_to_workdir(&diff, g_repo, NULL, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ giterr_clear();
+ opts.version = 1024;
+ cl_git_fail(git_diff_tree_to_workdir(&diff, g_repo, NULL, &opts));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+}
+
+void test_diff_workdir__can_diff_empty_file(void)
+{
+ git_diff_list *diff;
+ git_tree *tree;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ struct stat st;
+ git_diff_patch *patch;
+
+ g_repo = cl_git_sandbox_init("attr_index");
+
+ tree = resolve_commit_oid_to_tree(g_repo, "3812cfef3661"); /* HEAD */
+
+ /* baseline - make sure there are no outstanding diffs */
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+ git_tree_free(tree);
+ cl_assert_equal_i(2, (int)git_diff_num_deltas(diff));
+ git_diff_list_free(diff);
+
+ /* empty contents of file */
+
+ cl_git_rewritefile("attr_index/README.txt", "");
+ cl_git_pass(git_path_lstat("attr_index/README.txt", &st));
+ cl_assert_equal_i(0, (int)st.st_size);
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+ cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
+ /* diffs are: .gitattributes, README.txt, sub/sub/.gitattributes */
+ cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
+ git_diff_patch_free(patch);
+ git_diff_list_free(diff);
+
+ /* remove a file altogether */
+
+ cl_git_pass(p_unlink("attr_index/README.txt"));
+ cl_assert(!git_path_exists("attr_index/README.txt"));
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+ cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
+ cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
+ git_diff_patch_free(patch);
+ git_diff_list_free(diff);
+}
+
+void test_diff_workdir__to_index_issue_1397(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ diff_expects exp;
+
+ g_repo = cl_git_sandbox_init("issue_1397");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
+
+ git_diff_list_free(diff);
+ diff = NULL;
+
+ cl_git_rewritefile("issue_1397/crlf_file.txt",
+ "first line\r\nsecond line modified\r\nboth with crlf");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+
+ cl_assert_equal_i(1, exp.hunks);
+
+ cl_assert_equal_i(5, exp.lines);
+ cl_assert_equal_i(3, exp.line_ctxt);
+ cl_assert_equal_i(1, exp.line_adds);
+ cl_assert_equal_i(1, exp.line_dels);
+
+ git_diff_list_free(diff);
+}
+
+void test_diff_workdir__to_tree_issue_1397(void)
+{
+ const char *a_commit = "7f483a738"; /* the current HEAD */
+ git_tree *a;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ git_diff_list *diff2 = NULL;
+ diff_expects exp;
+
+ g_repo = cl_git_sandbox_init("issue_1397");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ a = resolve_commit_oid_to_tree(g_repo, a_commit);
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
+
+ git_diff_list_free(diff);
+ diff = NULL;
+
+ cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
+ cl_git_pass(git_diff_merge(diff, diff2));
+ git_diff_list_free(diff2);
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
+
+ git_diff_list_free(diff);
+ git_tree_free(a);
+}
diff --git a/tests-clar/fetchhead/fetchhead_data.h b/tests-clar/fetchhead/fetchhead_data.h
new file mode 100644
index 000000000..294c9fb01
--- /dev/null
+++ b/tests-clar/fetchhead/fetchhead_data.h
@@ -0,0 +1,31 @@
+
+#define FETCH_HEAD_WILDCARD_DATA_LOCAL \
+ "49322bb17d3acc9146f98c97d078513228bbf3c0\t\tbranch 'master' of git://github.com/libgit2/TestGitRepository\n" \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\tnot-for-merge\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n" \
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1\tnot-for-merge\tbranch 'no-parent' of git://github.com/libgit2/TestGitRepository\n" \
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb\tnot-for-merge\ttag 'annotated_tag' of git://github.com/libgit2/TestGitRepository\n" \
+ "55a1a760df4b86a02094a904dfa511deb5655905\tnot-for-merge\ttag 'blob' of git://github.com/libgit2/TestGitRepository\n" \
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee\tnot-for-merge\ttag 'commit_tree' of git://github.com/libgit2/TestGitRepository\n"
+
+#define FETCH_HEAD_WILDCARD_DATA \
+ "49322bb17d3acc9146f98c97d078513228bbf3c0\t\tbranch 'master' of git://github.com/libgit2/TestGitRepository\n" \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\tnot-for-merge\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n" \
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1\tnot-for-merge\tbranch 'no-parent' of git://github.com/libgit2/TestGitRepository\n" \
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb\tnot-for-merge\ttag 'annotated_tag' of git://github.com/libgit2/TestGitRepository\n" \
+ "55a1a760df4b86a02094a904dfa511deb5655905\tnot-for-merge\ttag 'blob' of git://github.com/libgit2/TestGitRepository\n" \
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee\tnot-for-merge\ttag 'commit_tree' of git://github.com/libgit2/TestGitRepository\n" \
+ "6e0c7bdb9b4ed93212491ee778ca1c65047cab4e\tnot-for-merge\ttag 'nearly-dangling' of git://github.com/libgit2/TestGitRepository\n"
+
+#define FETCH_HEAD_NO_MERGE_DATA \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\tnot-for-merge\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n" \
+ "49322bb17d3acc9146f98c97d078513228bbf3c0\tnot-for-merge\tbranch 'master' of git://github.com/libgit2/TestGitRepository\n" \
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1\tnot-for-merge\tbranch 'no-parent' of git://github.com/libgit2/TestGitRepository\n" \
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb\tnot-for-merge\ttag 'annotated_tag' of git://github.com/libgit2/TestGitRepository\n" \
+ "55a1a760df4b86a02094a904dfa511deb5655905\tnot-for-merge\ttag 'blob' of git://github.com/libgit2/TestGitRepository\n" \
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee\tnot-for-merge\ttag 'commit_tree' of git://github.com/libgit2/TestGitRepository\n" \
+ "6e0c7bdb9b4ed93212491ee778ca1c65047cab4e\tnot-for-merge\ttag 'nearly-dangling' of git://github.com/libgit2/TestGitRepository\n"
+
+
+#define FETCH_HEAD_EXPLICIT_DATA \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\t\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n"
+
diff --git a/tests-clar/fetchhead/nonetwork.c b/tests-clar/fetchhead/nonetwork.c
new file mode 100644
index 000000000..ef30679f9
--- /dev/null
+++ b/tests-clar/fetchhead/nonetwork.c
@@ -0,0 +1,309 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "fetchhead.h"
+
+#include "fetchhead_data.h"
+
+#define DO_LOCAL_TEST 0
+
+static git_repository *g_repo;
+
+void test_fetchhead_nonetwork__initialize(void)
+{
+ g_repo = NULL;
+}
+
+static void cleanup_repository(void *path)
+{
+ if (g_repo) {
+ git_repository_free(g_repo);
+ g_repo = NULL;
+ }
+
+ cl_fixture_cleanup((const char *)path);
+}
+
+static void populate_fetchhead(git_vector *out, git_repository *repo)
+{
+ git_fetchhead_ref *fetchhead_ref;
+ git_oid oid;
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "49322bb17d3acc9146f98c97d078513228bbf3c0"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 1,
+ "refs/heads/master",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(out, fetchhead_ref));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0,
+ "refs/heads/first-merge",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(out, fetchhead_ref));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0,
+ "refs/heads/no-parent",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(out, fetchhead_ref));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0,
+ "refs/tags/annotated_tag",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(out, fetchhead_ref));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "55a1a760df4b86a02094a904dfa511deb5655905"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0,
+ "refs/tags/blob",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(out, fetchhead_ref));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0,
+ "refs/tags/commit_tree",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(out, fetchhead_ref));
+
+ cl_git_pass(git_fetchhead_write(repo, out));
+}
+
+void test_fetchhead_nonetwork__write(void)
+{
+ git_vector fetchhead_vector = GIT_VECTOR_INIT;
+ git_fetchhead_ref *fetchhead_ref;
+ git_buf fetchhead_buf = GIT_BUF_INIT;
+ int equals = 0;
+ size_t i;
+
+ git_vector_init(&fetchhead_vector, 6, NULL);
+
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ populate_fetchhead(&fetchhead_vector, g_repo);
+
+ cl_git_pass(git_futils_readbuffer(&fetchhead_buf,
+ "./test1/.git/FETCH_HEAD"));
+
+ equals = (strcmp(fetchhead_buf.ptr, FETCH_HEAD_WILDCARD_DATA_LOCAL) == 0);
+
+ git_buf_free(&fetchhead_buf);
+
+ git_vector_foreach(&fetchhead_vector, i, fetchhead_ref) {
+ git_fetchhead_ref_free(fetchhead_ref);
+ }
+
+ git_vector_free(&fetchhead_vector);
+
+ cl_assert(equals);
+}
+
+typedef struct {
+ git_vector *fetchhead_vector;
+ size_t idx;
+} fetchhead_ref_cb_data;
+
+static int fetchhead_ref_cb(const char *name, const char *url,
+ const git_oid *oid, unsigned int is_merge, void *payload)
+{
+ fetchhead_ref_cb_data *cb_data = payload;
+ git_fetchhead_ref *expected;
+
+ cl_assert(payload);
+
+ expected = git_vector_get(cb_data->fetchhead_vector, cb_data->idx);
+
+ cl_assert(git_oid_cmp(&expected->oid, oid) == 0);
+ cl_assert(expected->is_merge == is_merge);
+
+ if (expected->ref_name)
+ cl_assert_equal_s(expected->ref_name, name);
+ else
+ cl_assert(name == NULL);
+
+ if (expected->remote_url)
+ cl_assert_equal_s(expected->remote_url, url);
+ else
+ cl_assert(url == NULL);
+
+ cb_data->idx++;
+
+ return 0;
+}
+
+void test_fetchhead_nonetwork__read(void)
+{
+ git_vector fetchhead_vector = GIT_VECTOR_INIT;
+ git_fetchhead_ref *fetchhead_ref;
+ fetchhead_ref_cb_data cb_data;
+ size_t i;
+
+ memset(&cb_data, 0x0, sizeof(fetchhead_ref_cb_data));
+
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ populate_fetchhead(&fetchhead_vector, g_repo);
+
+ cb_data.fetchhead_vector = &fetchhead_vector;
+
+ cl_git_pass(git_repository_fetchhead_foreach(g_repo, fetchhead_ref_cb, &cb_data));
+
+ git_vector_foreach(&fetchhead_vector, i, fetchhead_ref) {
+ git_fetchhead_ref_free(fetchhead_ref);
+ }
+
+ git_vector_free(&fetchhead_vector);
+}
+
+static int read_old_style_cb(const char *name, const char *url,
+ const git_oid *oid, unsigned int is_merge, void *payload)
+{
+ git_oid expected;
+
+ GIT_UNUSED(payload);
+
+ git_oid_fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0");
+
+ cl_assert(name == NULL);
+ cl_assert(url == NULL);
+ cl_assert(git_oid_cmp(&expected, oid) == 0);
+ cl_assert(is_merge == 1);
+
+ return 0;
+}
+
+void test_fetchhead_nonetwork__read_old_style(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "49322bb17d3acc9146f98c97d078513228bbf3c0\n");
+
+ cl_git_pass(git_repository_fetchhead_foreach(g_repo, read_old_style_cb, NULL));
+}
+
+static int read_type_missing(const char *ref_name, const char *remote_url,
+ const git_oid *oid, unsigned int is_merge, void *payload)
+{
+ git_oid expected;
+
+ GIT_UNUSED(payload);
+
+ git_oid_fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0");
+
+ cl_assert_equal_s("name", ref_name);
+ cl_assert_equal_s("remote_url", remote_url);
+ cl_assert(git_oid_cmp(&expected, oid) == 0);
+ cl_assert(is_merge == 0);
+
+ return 0;
+}
+
+void test_fetchhead_nonetwork__type_missing(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "49322bb17d3acc9146f98c97d078513228bbf3c0\tnot-for-merge\t'name' of remote_url\n");
+
+ cl_git_pass(git_repository_fetchhead_foreach(g_repo, read_type_missing, NULL));
+}
+
+static int read_name_missing(const char *ref_name, const char *remote_url,
+ const git_oid *oid, unsigned int is_merge, void *payload)
+{
+ git_oid expected;
+
+ GIT_UNUSED(payload);
+
+ git_oid_fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0");
+
+ cl_assert(ref_name == NULL);
+ cl_assert_equal_s("remote_url", remote_url);
+ cl_assert(git_oid_cmp(&expected, oid) == 0);
+ cl_assert(is_merge == 0);
+
+ return 0;
+}
+
+void test_fetchhead_nonetwork__name_missing(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "49322bb17d3acc9146f98c97d078513228bbf3c0\tnot-for-merge\tremote_url\n");
+
+ cl_git_pass(git_repository_fetchhead_foreach(g_repo, read_name_missing, NULL));
+}
+
+static int read_noop(const char *ref_name, const char *remote_url,
+ const git_oid *oid, unsigned int is_merge, void *payload)
+{
+ GIT_UNUSED(ref_name);
+ GIT_UNUSED(remote_url);
+ GIT_UNUSED(oid);
+ GIT_UNUSED(is_merge);
+ GIT_UNUSED(payload);
+
+ return 0;
+}
+
+void test_fetchhead_nonetwork__nonexistent(void)
+{
+ int error;
+
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_fail((error = git_repository_fetchhead_foreach(g_repo, read_noop, NULL)));
+ cl_assert(error == GIT_ENOTFOUND);
+}
+
+void test_fetchhead_nonetwork__invalid_unterminated_last_line(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "unterminated");
+ cl_git_fail(git_repository_fetchhead_foreach(g_repo, read_noop, NULL));
+}
+
+void test_fetchhead_nonetwork__invalid_oid(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "shortoid\n");
+ cl_git_fail(git_repository_fetchhead_foreach(g_repo, read_noop, NULL));
+}
+
+void test_fetchhead_nonetwork__invalid_for_merge(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "49322bb17d3acc9146f98c97d078513228bbf3c0\tinvalid-merge\t\n");
+ cl_git_fail(git_repository_fetchhead_foreach(g_repo, read_noop, NULL));
+
+ cl_assert(git__prefixcmp(giterr_last()->message, "Invalid for-merge") == 0);
+}
+
+void test_fetchhead_nonetwork__invalid_description(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_rewritefile("./test1/.git/FETCH_HEAD", "49322bb17d3acc9146f98c97d078513228bbf3c0\tnot-for-merge\n");
+ cl_git_fail(git_repository_fetchhead_foreach(g_repo, read_noop, NULL));
+
+ cl_assert(git__prefixcmp(giterr_last()->message, "Invalid description") == 0);
+}
+
diff --git a/tests-clar/generate.py b/tests-clar/generate.py
new file mode 100644
index 000000000..d4fe8f2a3
--- /dev/null
+++ b/tests-clar/generate.py
@@ -0,0 +1,244 @@
+#!/usr/bin/env python
+#
+# Copyright (c) Vicent Marti. All rights reserved.
+#
+# This file is part of clar, distributed under the ISC license.
+# For full terms see the included COPYING file.
+#
+
+from __future__ import with_statement
+from string import Template
+import re, fnmatch, os, codecs, pickle
+
+class Module(object):
+ class Template(object):
+ def __init__(self, module):
+ self.module = module
+
+ def _render_callback(self, cb):
+ if not cb:
+ return ' { NULL, NULL }'
+ return ' { "%s", &%s }' % (cb['short_name'], cb['symbol'])
+
+ class DeclarationTemplate(Template):
+ def render(self):
+ out = "\n".join("extern %s;" % cb['declaration'] for cb in self.module.callbacks) + "\n"
+
+ if self.module.initialize:
+ out += "extern %s;\n" % self.module.initialize['declaration']
+
+ if self.module.cleanup:
+ out += "extern %s;\n" % self.module.cleanup['declaration']
+
+ return out
+
+ class CallbacksTemplate(Template):
+ def render(self):
+ out = "static const struct clar_func _clar_cb_%s[] = {\n" % self.module.name
+ out += ",\n".join(self._render_callback(cb) for cb in self.module.callbacks)
+ out += "\n};\n"
+ return out
+
+ class InfoTemplate(Template):
+ def render(self):
+ return Template(
+ r"""
+ {
+ "${clean_name}",
+ ${initialize},
+ ${cleanup},
+ ${cb_ptr}, ${cb_count}, ${enabled}
+ }"""
+ ).substitute(
+ clean_name = self.module.clean_name(),
+ initialize = self._render_callback(self.module.initialize),
+ cleanup = self._render_callback(self.module.cleanup),
+ cb_ptr = "_clar_cb_%s" % self.module.name,
+ cb_count = len(self.module.callbacks),
+ enabled = int(self.module.enabled)
+ )
+
+ def __init__(self, name):
+ self.name = name
+
+ self.mtime = 0
+ self.enabled = True
+ self.modified = False
+
+ def clean_name(self):
+ return self.name.replace("_", "::")
+
+ def _skip_comments(self, text):
+ SKIP_COMMENTS_REGEX = re.compile(
+ r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
+ re.DOTALL | re.MULTILINE)
+
+ def _replacer(match):
+ s = match.group(0)
+ return "" if s.startswith('/') else s
+
+ return re.sub(SKIP_COMMENTS_REGEX, _replacer, text)
+
+ def parse(self, contents):
+ TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*void\s*\))\s*\{"
+
+ contents = self._skip_comments(contents)
+ regex = re.compile(TEST_FUNC_REGEX % self.name, re.MULTILINE)
+
+ self.callbacks = []
+ self.initialize = None
+ self.cleanup = None
+
+ for (declaration, symbol, short_name) in regex.findall(contents):
+ data = {
+ "short_name" : short_name,
+ "declaration" : declaration,
+ "symbol" : symbol
+ }
+
+ if short_name == 'initialize':
+ self.initialize = data
+ elif short_name == 'cleanup':
+ self.cleanup = data
+ else:
+ self.callbacks.append(data)
+
+ return self.callbacks != []
+
+ def refresh(self, path):
+ self.modified = False
+
+ try:
+ st = os.stat(path)
+
+ # Not modified
+ if st.st_mtime == self.mtime:
+ return True
+
+ self.modified = True
+ self.mtime = st.st_mtime
+
+ with open(path) as fp:
+ raw_content = fp.read()
+
+ except IOError:
+ return False
+
+ return self.parse(raw_content)
+
+class TestSuite(object):
+
+ def __init__(self, path):
+ self.path = path
+
+ def should_generate(self, path):
+ if not os.path.isfile(path):
+ return True
+
+ if any(module.modified for module in self.modules.values()):
+ return True
+
+ return False
+
+ def find_modules(self):
+ modules = []
+ for root, _, files in os.walk(self.path):
+ module_root = root[len(self.path):]
+ module_root = [c for c in module_root.split(os.sep) if c]
+
+ tests_in_module = fnmatch.filter(files, "*.c")
+
+ for test_file in tests_in_module:
+ full_path = os.path.join(root, test_file)
+ module_name = "_".join(module_root + [test_file[:-2]])
+
+ modules.append((full_path, module_name))
+
+ return modules
+
+ def load_cache(self):
+ path = os.path.join(self.path, '.clarcache')
+ cache = {}
+
+ try:
+ fp = open(path, 'rb')
+ cache = pickle.load(fp)
+ fp.close()
+ except (IOError, ValueError):
+ pass
+
+ return cache
+
+ def save_cache(self):
+ path = os.path.join(self.path, '.clarcache')
+ with open(path, 'wb') as cache:
+ pickle.dump(self.modules, cache)
+
+ def load(self, force = False):
+ module_data = self.find_modules()
+ self.modules = {} if force else self.load_cache()
+
+ for path, name in module_data:
+ if name not in self.modules:
+ self.modules[name] = Module(name)
+
+ if not self.modules[name].refresh(path):
+ del self.modules[name]
+
+ def disable(self, excluded):
+ for exclude in excluded:
+ for module in self.modules.values():
+ name = module.clean_name()
+ if name.startswith(exclude):
+ module.enabled = False
+ module.modified = True
+
+ def suite_count(self):
+ return len(self.modules)
+
+ def callback_count(self):
+ return sum(len(module.callbacks) for module in self.modules.values())
+
+ def write(self):
+ output = os.path.join(self.path, 'clar.suite')
+
+ if not self.should_generate(output):
+ return False
+
+ with open(output, 'w') as data:
+ for module in self.modules.values():
+ t = Module.DeclarationTemplate(module)
+ data.write(t.render())
+
+ for module in self.modules.values():
+ t = Module.CallbacksTemplate(module)
+ data.write(t.render())
+
+ suites = "static struct clar_suite _clar_suites[] = {" + ','.join(
+ Module.InfoTemplate(module).render() for module in sorted(self.modules.values(), key=lambda module: module.name)
+ ) + "\n};\n"
+
+ data.write(suites)
+
+ data.write("static const size_t _clar_suite_count = %d;\n" % self.suite_count())
+ data.write("static const size_t _clar_callback_count = %d;\n" % self.callback_count())
+
+ suite.save_cache()
+ return True
+
+if __name__ == '__main__':
+ from optparse import OptionParser
+
+ parser = OptionParser()
+ parser.add_option('-f', '--force', dest='force', default=False)
+ parser.add_option('-x', '--exclude', dest='excluded', action='append', default=[])
+
+ options, args = parser.parse_args()
+
+ for path in args or ['.']:
+ suite = TestSuite(path)
+ suite.load(options.force)
+ suite.disable(options.excluded)
+ if suite.write():
+ print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
+
diff --git a/tests-clar/index/conflicts.c b/tests-clar/index/conflicts.c
new file mode 100644
index 000000000..7eee496de
--- /dev/null
+++ b/tests-clar/index/conflicts.c
@@ -0,0 +1,242 @@
+#include "clar_libgit2.h"
+#include "index.h"
+#include "git2/repository.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "mergedrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define CONFLICTS_ONE_ANCESTOR_OID "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81"
+#define CONFLICTS_ONE_OUR_OID "6aea5f295304c36144ad6e9247a291b7f8112399"
+#define CONFLICTS_ONE_THEIR_OID "516bd85f78061e09ccc714561d7b504672cb52da"
+
+#define CONFLICTS_TWO_ANCESTOR_OID "84af62840be1b1c47b778a8a249f3ff45155038c"
+#define CONFLICTS_TWO_OUR_OID "8b3f43d2402825c200f835ca1762413e386fd0b2"
+#define CONFLICTS_TWO_THEIR_OID "220bd62631c8cf7a83ef39c6b94595f00517211e"
+
+#define TEST_ANCESTOR_OID "f00ff00ff00ff00ff00ff00ff00ff00ff00ff00f"
+#define TEST_OUR_OID "b44bb44bb44bb44bb44bb44bb44bb44bb44bb44b"
+#define TEST_THEIR_OID "0123456789abcdef0123456789abcdef01234567"
+
+// Fixture setup and teardown
+void test_index_conflicts__initialize(void)
+{
+ repo = cl_git_sandbox_init("mergedrepo");
+ git_repository_index(&repo_index, repo);
+}
+
+void test_index_conflicts__cleanup(void)
+{
+ git_index_free(repo_index);
+ repo_index = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_index_conflicts__add(void)
+{
+ git_index_entry ancestor_entry, our_entry, their_entry;
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+ memset(&our_entry, 0x0, sizeof(git_index_entry));
+ memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+ ancestor_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&ancestor_entry.oid, TEST_ANCESTOR_OID);
+
+ our_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&our_entry.oid, TEST_OUR_OID);
+
+ their_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&their_entry.oid, TEST_THEIR_OID);
+
+ cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
+
+ cl_assert(git_index_entrycount(repo_index) == 11);
+}
+
+void test_index_conflicts__add_fixes_incorrect_stage(void)
+{
+ git_index_entry ancestor_entry, our_entry, their_entry;
+ git_index_entry *conflict_entry[3];
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+ memset(&our_entry, 0x0, sizeof(git_index_entry));
+ memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+ ancestor_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&ancestor_entry.oid, TEST_ANCESTOR_OID);
+
+ our_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&our_entry.oid, TEST_OUR_OID);
+
+ their_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&their_entry.oid, TEST_THEIR_OID);
+
+ cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
+
+ cl_assert(git_index_entrycount(repo_index) == 11);
+
+ cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt"));
+
+ cl_assert(git_index_entry_stage(conflict_entry[0]) == 1);
+ cl_assert(git_index_entry_stage(conflict_entry[1]) == 2);
+ cl_assert(git_index_entry_stage(conflict_entry[2]) == 3);
+}
+
+void test_index_conflicts__get(void)
+{
+ git_index_entry *conflict_entry[3];
+ git_oid oid;
+
+ cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+ &conflict_entry[2], repo_index, "conflicts-one.txt"));
+
+ cl_assert_equal_s("conflicts-one.txt", conflict_entry[0]->path);
+
+ git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&conflict_entry[0]->oid, &oid) == 0);
+
+ git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID);
+ cl_assert(git_oid_cmp(&conflict_entry[1]->oid, &oid) == 0);
+
+ git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID);
+ cl_assert(git_oid_cmp(&conflict_entry[2]->oid, &oid) == 0);
+
+ cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+ &conflict_entry[2], repo_index, "conflicts-two.txt"));
+
+ cl_assert_equal_s("conflicts-two.txt", conflict_entry[0]->path);
+
+ git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&conflict_entry[0]->oid, &oid) == 0);
+
+ git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID);
+ cl_assert(git_oid_cmp(&conflict_entry[1]->oid, &oid) == 0);
+
+ git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID);
+ cl_assert(git_oid_cmp(&conflict_entry[2]->oid, &oid) == 0);
+}
+
+void test_index_conflicts__remove(void)
+{
+ const git_index_entry *entry;
+ size_t i;
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ cl_git_pass(git_index_conflict_remove(repo_index, "conflicts-one.txt"));
+ cl_assert(git_index_entrycount(repo_index) == 5);
+
+ for (i = 0; i < git_index_entrycount(repo_index); i++) {
+ cl_assert(entry = git_index_get_byindex(repo_index, i));
+ cl_assert(strcmp(entry->path, "conflicts-one.txt") != 0);
+ }
+
+ cl_git_pass(git_index_conflict_remove(repo_index, "conflicts-two.txt"));
+ cl_assert(git_index_entrycount(repo_index) == 2);
+
+ for (i = 0; i < git_index_entrycount(repo_index); i++) {
+ cl_assert(entry = git_index_get_byindex(repo_index, i));
+ cl_assert(strcmp(entry->path, "conflicts-two.txt") != 0);
+ }
+}
+
+void test_index_conflicts__moved_to_reuc_on_add(void)
+{
+ const git_index_entry *entry;
+ size_t i;
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ cl_git_mkfile("./mergedrepo/conflicts-one.txt", "new-file\n");
+
+ cl_git_pass(git_index_add_bypath(repo_index, "conflicts-one.txt"));
+
+ cl_assert(git_index_entrycount(repo_index) == 6);
+
+ for (i = 0; i < git_index_entrycount(repo_index); i++) {
+ cl_assert(entry = git_index_get_byindex(repo_index, i));
+
+ if (strcmp(entry->path, "conflicts-one.txt") == 0)
+ cl_assert(git_index_entry_stage(entry) == 0);
+ }
+}
+
+void test_index_conflicts__moved_to_reuc_on_remove(void)
+{
+ const git_index_entry *entry;
+ size_t i;
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ cl_git_pass(p_unlink("./mergedrepo/conflicts-one.txt"));
+
+ cl_git_pass(git_index_remove_bypath(repo_index, "conflicts-one.txt"));
+
+ cl_assert(git_index_entrycount(repo_index) == 5);
+
+ for (i = 0; i < git_index_entrycount(repo_index); i++) {
+ cl_assert(entry = git_index_get_byindex(repo_index, i));
+ cl_assert(strcmp(entry->path, "conflicts-one.txt") != 0);
+ }
+}
+
+void test_index_conflicts__remove_all_conflicts(void)
+{
+ size_t i;
+ const git_index_entry *entry;
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ cl_assert_equal_i(true, git_index_has_conflicts(repo_index));
+
+ git_index_conflict_cleanup(repo_index);
+
+ cl_assert_equal_i(false, git_index_has_conflicts(repo_index));
+
+ cl_assert(git_index_entrycount(repo_index) == 2);
+
+ for (i = 0; i < git_index_entrycount(repo_index); i++) {
+ cl_assert(entry = git_index_get_byindex(repo_index, i));
+ cl_assert(git_index_entry_stage(entry) == 0);
+ }
+}
+
+void test_index_conflicts__partial(void)
+{
+ git_index_entry ancestor_entry, our_entry, their_entry;
+ git_index_entry *conflict_entry[3];
+
+ cl_assert(git_index_entrycount(repo_index) == 8);
+
+ memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+ memset(&our_entry, 0x0, sizeof(git_index_entry));
+ memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+ ancestor_entry.path = "test-one.txt";
+ ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&ancestor_entry.oid, TEST_ANCESTOR_OID);
+
+ cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, NULL, NULL));
+ cl_assert(git_index_entrycount(repo_index) == 9);
+
+ cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+ &conflict_entry[2], repo_index, "test-one.txt"));
+
+ cl_assert(git_oid_cmp(&ancestor_entry.oid, &conflict_entry[0]->oid) == 0);
+ cl_assert(conflict_entry[1] == NULL);
+ cl_assert(conflict_entry[2] == NULL);
+}
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
new file mode 100644
index 000000000..e56a9c069
--- /dev/null
+++ b/tests-clar/index/filemodes.c
@@ -0,0 +1,153 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "posix.h"
+#include "index.h"
+
+static git_repository *g_repo = NULL;
+
+void test_index_filemodes__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("filemodes");
+}
+
+void test_index_filemodes__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_index_filemodes__read(void)
+{
+ git_index *index;
+ unsigned int i;
+ static bool expected[6] = { 0, 1, 0, 1, 0, 1 };
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_assert_equal_i(6, (int)git_index_entrycount(index));
+
+ for (i = 0; i < 6; ++i) {
+ const git_index_entry *entry = git_index_get_byindex(index, i);
+ cl_assert(entry != NULL);
+ cl_assert(((entry->mode & 0100) ? 1 : 0) == expected[i]);
+ }
+
+ git_index_free(index);
+}
+
+static void replace_file_with_mode(
+ const char *filename, const char *backup, unsigned int create_mode)
+{
+ git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_joinpath(&path, "filemodes", filename));
+ cl_git_pass(git_buf_printf(&content, "%s as %08u (%d)",
+ filename, create_mode, rand()));
+
+ cl_git_pass(p_rename(path.ptr, backup));
+ cl_git_write2file(
+ path.ptr, content.ptr, O_WRONLY|O_CREAT|O_TRUNC, create_mode);
+
+ git_buf_free(&path);
+ git_buf_free(&content);
+}
+
+static void add_and_check_mode(
+ git_index *index, const char *filename, unsigned int expect_mode)
+{
+ size_t pos;
+ const git_index_entry *entry;
+
+ cl_git_pass(git_index_add_bypath(index, filename));
+
+ cl_assert(!git_index_find(&pos, index, filename));
+
+ entry = git_index_get_byindex(index, pos);
+ cl_assert(entry->mode == expect_mode);
+}
+
+void test_index_filemodes__untrusted(void)
+{
+ git_index *index;
+ bool can_filemode = cl_is_chmod_supported();
+
+ cl_repo_set_bool(g_repo, "core.filemode", false);
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) != 0);
+
+ /* 1 - add 0644 over existing 0644 -> expect 0644 */
+ replace_file_with_mode("exec_off", "filemodes/exec_off.0", 0644);
+ add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB);
+
+ /* 2 - add 0644 over existing 0755 -> expect 0755 */
+ replace_file_with_mode("exec_on", "filemodes/exec_on.0", 0644);
+ add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
+
+ /* 3 - add 0755 over existing 0644 -> expect 0644 */
+ replace_file_with_mode("exec_off", "filemodes/exec_off.1", 0755);
+ add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB);
+
+ /* 4 - add 0755 over existing 0755 -> expect 0755 */
+ replace_file_with_mode("exec_on", "filemodes/exec_on.1", 0755);
+ add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
+
+ /* 5 - add new 0644 -> expect 0644 */
+ cl_git_write2file("filemodes/new_off", "blah",
+ O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
+
+ /* this test won't give predictable results on a platform
+ * that doesn't support filemodes correctly, so skip it.
+ */
+ if (can_filemode) {
+ /* 6 - add 0755 -> expect 0755 */
+ cl_git_write2file("filemodes/new_on", "blah",
+ O_WRONLY | O_CREAT | O_TRUNC, 0755);
+ add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
+ }
+
+ git_index_free(index);
+}
+
+void test_index_filemodes__trusted(void)
+{
+ git_index *index;
+
+ /* Only run these tests on platforms where I can actually
+ * chmod a file and get the stat results I expect!
+ */
+ if (!cl_is_chmod_supported())
+ return;
+
+ cl_repo_set_bool(g_repo, "core.filemode", true);
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) == 0);
+
+ /* 1 - add 0644 over existing 0644 -> expect 0644 */
+ replace_file_with_mode("exec_off", "filemodes/exec_off.0", 0644);
+ add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB);
+
+ /* 2 - add 0644 over existing 0755 -> expect 0644 */
+ replace_file_with_mode("exec_on", "filemodes/exec_on.0", 0644);
+ add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB);
+
+ /* 3 - add 0755 over existing 0644 -> expect 0755 */
+ replace_file_with_mode("exec_off", "filemodes/exec_off.1", 0755);
+ add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB_EXECUTABLE);
+
+ /* 4 - add 0755 over existing 0755 -> expect 0755 */
+ replace_file_with_mode("exec_on", "filemodes/exec_on.1", 0755);
+ add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
+
+ /* 5 - add new 0644 -> expect 0644 */
+ cl_git_write2file("filemodes/new_off", "blah",
+ O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
+
+ /* 6 - add 0755 -> expect 0755 */
+ cl_git_write2file("filemodes/new_on", "blah",
+ O_WRONLY | O_CREAT | O_TRUNC, 0755);
+ add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
+
+ git_index_free(index);
+}
diff --git a/tests-clar/index/inmemory.c b/tests-clar/index/inmemory.c
new file mode 100644
index 000000000..38e91e0fd
--- /dev/null
+++ b/tests-clar/index/inmemory.c
@@ -0,0 +1,22 @@
+#include "clar_libgit2.h"
+
+void test_index_inmemory__can_create_an_inmemory_index(void)
+{
+ git_index *index;
+
+ cl_git_pass(git_index_new(&index));
+ cl_assert_equal_i(0, (int)git_index_entrycount(index));
+
+ git_index_free(index);
+}
+
+void test_index_inmemory__cannot_add_bypath_to_an_inmemory_index(void)
+{
+ git_index *index;
+
+ cl_git_pass(git_index_new(&index));
+
+ cl_assert_equal_i(GIT_ERROR, git_index_add_bypath(index, "test.txt"));
+
+ git_index_free(index);
+}
diff --git a/tests-clar/index/read_tree.c b/tests-clar/index/read_tree.c
index c657d4f71..6c6b40121 100644
--- a/tests-clar/index/read_tree.c
+++ b/tests-clar/index/read_tree.c
@@ -24,19 +24,19 @@ void test_index_read_tree__read_write_involution(void)
cl_git_mkfile("./read_tree/abc/d", NULL);
cl_git_mkfile("./read_tree/abc_d", NULL);
- cl_git_pass(git_index_add(index, "abc-d", 0));
- cl_git_pass(git_index_add(index, "abc_d", 0));
- cl_git_pass(git_index_add(index, "abc/d", 0));
+ cl_git_pass(git_index_add_bypath(index, "abc-d"));
+ cl_git_pass(git_index_add_bypath(index, "abc_d"));
+ cl_git_pass(git_index_add_bypath(index, "abc/d"));
/* write-tree */
- cl_git_pass(git_tree_create_fromindex(&expected, index));
+ cl_git_pass(git_index_write_tree(&expected, index));
/* read-tree */
git_tree_lookup(&tree, repo, &expected);
cl_git_pass(git_index_read_tree(index, tree));
git_tree_free(tree);
- cl_git_pass(git_tree_create_fromindex(&tree_oid, index));
+ cl_git_pass(git_index_write_tree(&tree_oid, index));
cl_assert(git_oid_cmp(&expected, &tree_oid) == 0);
git_index_free(index);
diff --git a/tests-clar/index/rename.c b/tests-clar/index/rename.c
index eecd257fd..4deef1332 100644
--- a/tests-clar/index/rename.c
+++ b/tests-clar/index/rename.c
@@ -5,9 +5,9 @@ void test_index_rename__single_file(void)
{
git_repository *repo;
git_index *index;
- int position;
+ size_t position;
git_oid expected;
- git_index_entry *entry;
+ const git_index_entry *entry;
p_mkdir("rename", 0700);
@@ -19,28 +19,28 @@ void test_index_rename__single_file(void)
cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
- cl_git_pass(git_index_add(index, "lame.name.txt", 0));
+ cl_git_pass(git_index_add_bypath(index, "lame.name.txt"));
cl_assert(git_index_entrycount(index) == 1);
cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"));
- position = git_index_find(index, "lame.name.txt");
+ cl_assert(!git_index_find(&position, index, "lame.name.txt"));
- entry = git_index_get(index, position);
+ entry = git_index_get_byindex(index, position);
cl_assert(git_oid_cmp(&expected, &entry->oid) == 0);
/* This removes the entry from the index, but not from the object database */
- cl_git_pass(git_index_remove(index, position));
+ cl_git_pass(git_index_remove(index, "lame.name.txt", 0));
cl_assert(git_index_entrycount(index) == 0);
p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt");
- cl_git_pass(git_index_add(index, "fancy.name.txt", 0));
+ cl_git_pass(git_index_add_bypath(index, "fancy.name.txt"));
cl_assert(git_index_entrycount(index) == 1);
- position = git_index_find(index, "fancy.name.txt");
+ cl_assert(!git_index_find(&position, index, "fancy.name.txt"));
- entry = git_index_get(index, position);
+ entry = git_index_get_byindex(index, position);
cl_assert(git_oid_cmp(&expected, &entry->oid) == 0);
git_index_free(index);
diff --git a/tests-clar/index/reuc.c b/tests-clar/index/reuc.c
new file mode 100644
index 000000000..4d5955a01
--- /dev/null
+++ b/tests-clar/index/reuc.c
@@ -0,0 +1,373 @@
+#include "clar_libgit2.h"
+#include "index.h"
+#include "git2/repository.h"
+#include "../reset/reset_helpers.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "mergedrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define ONE_ANCESTOR_OID "478871385b9cd03908c5383acfd568bef023c6b3"
+#define ONE_OUR_OID "4458b8bc9e72b6c8755ae456f60e9844d0538d8c"
+#define ONE_THEIR_OID "8b72416545c7e761b64cecad4f1686eae4078aa8"
+
+#define TWO_ANCESTOR_OID "9d81f82fccc7dcd7de7a1ffead1815294c2e092c"
+#define TWO_OUR_OID "8f3c06cff9a83757cec40c80bc9bf31a2582bde9"
+#define TWO_THEIR_OID "887b153b165d32409c70163e0f734c090f12f673"
+
+// Fixture setup and teardown
+void test_index_reuc__initialize(void)
+{
+ repo = cl_git_sandbox_init("mergedrepo");
+ git_repository_index(&repo_index, repo);
+}
+
+void test_index_reuc__cleanup(void)
+{
+ git_index_free(repo_index);
+ repo_index = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_index_reuc__add(void)
+{
+ git_oid ancestor_oid, our_oid, their_oid;
+ const git_index_reuc_entry *reuc;
+
+ git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID);
+ git_oid_fromstr(&our_oid, ONE_OUR_OID);
+ git_oid_fromstr(&their_oid, ONE_THEIR_OID);
+
+ cl_git_pass(git_index_reuc_add(repo_index, "newfile.txt",
+ 0100644, &ancestor_oid,
+ 0100644, &our_oid,
+ 0100644, &their_oid));
+
+ cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "newfile.txt"));
+
+ cl_assert_equal_s("newfile.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &ancestor_oid) == 0);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &our_oid) == 0);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &their_oid) == 0);
+}
+
+void test_index_reuc__add_no_ancestor(void)
+{
+ git_oid ancestor_oid, our_oid, their_oid;
+ const git_index_reuc_entry *reuc;
+
+ memset(&ancestor_oid, 0x0, sizeof(git_oid));
+ git_oid_fromstr(&our_oid, ONE_OUR_OID);
+ git_oid_fromstr(&their_oid, ONE_THEIR_OID);
+
+ cl_git_pass(git_index_reuc_add(repo_index, "newfile.txt",
+ 0, NULL,
+ 0100644, &our_oid,
+ 0100644, &their_oid));
+
+ cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "newfile.txt"));
+
+ cl_assert_equal_s("newfile.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &ancestor_oid) == 0);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &our_oid) == 0);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &their_oid) == 0);
+}
+
+void test_index_reuc__read_bypath(void)
+{
+ const git_index_reuc_entry *reuc;
+ git_oid oid;
+
+ cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+ cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "two.txt"));
+
+ cl_assert_equal_s("two.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+
+ cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "one.txt"));
+
+ cl_assert_equal_s("one.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ git_oid_fromstr(&oid, ONE_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, ONE_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, ONE_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__ignore_case(void)
+{
+ const git_index_reuc_entry *reuc;
+ git_oid oid;
+ int index_caps;
+
+ index_caps = git_index_caps(repo_index);
+
+ index_caps &= ~GIT_INDEXCAP_IGNORE_CASE;
+ cl_git_pass(git_index_set_caps(repo_index, index_caps));
+
+ cl_assert(!git_index_reuc_get_bypath(repo_index, "TWO.txt"));
+
+ index_caps |= GIT_INDEXCAP_IGNORE_CASE;
+ cl_git_pass(git_index_set_caps(repo_index, index_caps));
+
+ cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+ cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "TWO.txt"));
+
+ cl_assert_equal_s("two.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__read_byindex(void)
+{
+ const git_index_reuc_entry *reuc;
+ git_oid oid;
+
+ cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+ cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+
+ cl_assert_equal_s("one.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ git_oid_fromstr(&oid, ONE_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, ONE_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, ONE_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+
+ cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));
+
+ cl_assert_equal_s("two.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__updates_existing(void)
+{
+ const git_index_reuc_entry *reuc;
+ git_oid ancestor_oid, our_oid, their_oid, oid;
+ int index_caps;
+
+ git_index_clear(repo_index);
+
+ index_caps = git_index_caps(repo_index);
+
+ index_caps |= GIT_INDEXCAP_IGNORE_CASE;
+ cl_git_pass(git_index_set_caps(repo_index, index_caps));
+
+ git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
+ git_oid_fromstr(&our_oid, TWO_OUR_OID);
+ git_oid_fromstr(&their_oid, TWO_THEIR_OID);
+
+ cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
+ 0100644, &ancestor_oid,
+ 0100644, &our_oid,
+ 0100644, &their_oid));
+
+ cl_git_pass(git_index_reuc_add(repo_index, "TWO.txt",
+ 0100644, &our_oid,
+ 0100644, &their_oid,
+ 0100644, &ancestor_oid));
+
+ cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index));
+
+ cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+
+ cl_assert_equal_s("TWO.txt", reuc->path);
+ git_oid_fromstr(&oid, TWO_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__remove(void)
+{
+ git_oid oid;
+ const git_index_reuc_entry *reuc;
+
+ cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+ cl_git_pass(git_index_reuc_remove(repo_index, 0));
+ cl_git_fail(git_index_reuc_remove(repo_index, 1));
+
+ cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index));
+
+ cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+
+ cl_assert_equal_s("two.txt", reuc->path);
+ cl_assert(reuc->mode[0] == 0100644);
+ cl_assert(reuc->mode[1] == 0100644);
+ cl_assert(reuc->mode[2] == 0100644);
+ git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_OUR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+ git_oid_fromstr(&oid, TWO_THEIR_OID);
+ cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__write(void)
+{
+ git_oid ancestor_oid, our_oid, their_oid;
+ const git_index_reuc_entry *reuc;
+
+ git_index_clear(repo_index);
+
+ /* Write out of order to ensure sorting is correct */
+ git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
+ git_oid_fromstr(&our_oid, TWO_OUR_OID);
+ git_oid_fromstr(&their_oid, TWO_THEIR_OID);
+
+ cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
+ 0100644, &ancestor_oid,
+ 0100644, &our_oid,
+ 0100644, &their_oid));
+
+ git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID);
+ git_oid_fromstr(&our_oid, ONE_OUR_OID);
+ git_oid_fromstr(&their_oid, ONE_THEIR_OID);
+
+ cl_git_pass(git_index_reuc_add(repo_index, "one.txt",
+ 0100644, &ancestor_oid,
+ 0100644, &our_oid,
+ 0100644, &their_oid));
+
+ cl_git_pass(git_index_write(repo_index));
+
+ cl_git_pass(git_index_read(repo_index));
+ cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+ /* ensure sort order was round-tripped correct */
+ cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+ cl_assert_equal_s("one.txt", reuc->path);
+
+ cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));
+ cl_assert_equal_s("two.txt", reuc->path);
+}
+
+static int reuc_entry_exists(void)
+{
+ return (git_index_reuc_get_bypath(repo_index, "newfile.txt") != NULL);
+}
+
+void test_index_reuc__cleaned_on_reset_hard(void)
+{
+ git_object *target;
+
+ retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
+
+ test_index_reuc__add();
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
+ cl_assert(reuc_entry_exists() == false);
+
+ git_object_free(target);
+}
+
+void test_index_reuc__cleaned_on_reset_mixed(void)
+{
+ git_object *target;
+
+ retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
+
+ test_index_reuc__add();
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
+ cl_assert(reuc_entry_exists() == false);
+
+ git_object_free(target);
+}
+
+void test_index_reuc__retained_on_reset_soft(void)
+{
+ git_object *target;
+
+ retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
+
+ git_reset(repo, target, GIT_RESET_HARD);
+
+ test_index_reuc__add();
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
+ cl_assert(reuc_entry_exists() == true);
+
+ git_object_free(target);
+}
+
+void test_index_reuc__cleaned_on_checkout_tree(void)
+{
+ git_oid oid;
+ git_object *obj;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+
+ test_index_reuc__add();
+ git_reference_name_to_id(&oid, repo, "refs/heads/master");
+ git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY);
+ git_checkout_tree(repo, obj, &opts);
+ cl_assert(reuc_entry_exists() == false);
+
+ git_object_free(obj);
+}
+
+void test_index_reuc__cleaned_on_checkout_head(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+
+ test_index_reuc__add();
+ git_checkout_head(repo, &opts);
+ cl_assert(reuc_entry_exists() == false);
+}
+
+void test_index_reuc__retained_on_checkout_index(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+
+ test_index_reuc__add();
+ git_checkout_index(repo, repo_index, &opts);
+ cl_assert(reuc_entry_exists() == true);
+}
diff --git a/tests-clar/index/stage.c b/tests-clar/index/stage.c
new file mode 100644
index 000000000..58dc1fb5e
--- /dev/null
+++ b/tests-clar/index/stage.c
@@ -0,0 +1,62 @@
+#include "clar_libgit2.h"
+#include "index.h"
+#include "git2/repository.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "mergedrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+// Fixture setup and teardown
+void test_index_stage__initialize(void)
+{
+ repo = cl_git_sandbox_init("mergedrepo");
+ git_repository_index(&repo_index, repo);
+}
+
+void test_index_stage__cleanup(void)
+{
+ git_index_free(repo_index);
+ repo_index = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+
+void test_index_stage__add_always_adds_stage_0(void)
+{
+ size_t entry_idx;
+ const git_index_entry *entry;
+
+ cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");
+
+ cl_git_pass(git_index_add_bypath(repo_index, "new-file.txt"));
+
+ cl_assert(!git_index_find(&entry_idx, repo_index, "new-file.txt"));
+ cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+ cl_assert(git_index_entry_stage(entry) == 0);
+}
+
+void test_index_stage__find_gets_first_stage(void)
+{
+ size_t entry_idx;
+ const git_index_entry *entry;
+
+ cl_assert(!git_index_find(&entry_idx, repo_index, "one.txt"));
+ cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+ cl_assert(git_index_entry_stage(entry) == 0);
+
+ cl_assert(!git_index_find(&entry_idx, repo_index, "two.txt"));
+ cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+ cl_assert(git_index_entry_stage(entry) == 0);
+
+ cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-one.txt"));
+ cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+ cl_assert(git_index_entry_stage(entry) == 1);
+
+ cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-two.txt"));
+ cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+ cl_assert(git_index_entry_stage(entry) == 1);
+}
+
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 3436f8d1e..88e374e6e 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -1,8 +1,8 @@
#include "clar_libgit2.h"
#include "index.h"
-static const int index_entry_count = 109;
-static const int index_entry_count_2 = 1437;
+static const size_t index_entry_count = 109;
+static const size_t index_entry_count_2 = 1437;
#define TEST_INDEX_PATH cl_fixture("testrepo.git/index")
#define TEST_INDEX2_PATH cl_fixture("gitgit.index")
#define TEST_INDEXBIG_PATH cl_fixture("big.index")
@@ -10,7 +10,7 @@ static const int index_entry_count_2 = 1437;
// Suite data
struct test_entry {
- int index;
+ size_t index;
char path[128];
git_off_t file_size;
git_time_t mtime;
@@ -24,7 +24,6 @@ static struct test_entry test_entries[] = {
{48, "src/revobject.h", 1448, 0x4C3F7FE2}
};
-
// Helpers
static void copy_file(const char *src, const char *dst)
{
@@ -33,7 +32,7 @@ static void copy_file(const char *src, const char *dst)
cl_git_pass(git_futils_readbuffer(&source_buf, src));
- dst_fd = git_futils_creat_withpath(dst, 0777, 0666);
+ dst_fd = git_futils_creat_withpath(dst, 0777, 0666); //-V536
if (dst_fd < 0)
goto cleanup;
@@ -72,11 +71,6 @@ void test_index_tests__initialize(void)
{
}
-void test_index_tests__cleanup(void)
-{
-}
-
-
void test_index_tests__empty_index(void)
{
git_index *index;
@@ -99,7 +93,7 @@ void test_index_tests__default_test_index(void)
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_assert(index->on_disk);
- cl_assert(git_index_entrycount(index) == (unsigned int)index_entry_count);
+ cl_assert(git_index_entrycount(index) == index_entry_count);
cl_assert(index->entries.sorted);
entries = (git_index_entry **)index->entries.contents;
@@ -122,7 +116,7 @@ void test_index_tests__gitgit_index(void)
cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH));
cl_assert(index->on_disk);
- cl_assert(git_index_entrycount(index) == (unsigned int)index_entry_count_2);
+ cl_assert(git_index_entrycount(index) == index_entry_count_2);
cl_assert(index->entries.sorted);
cl_assert(index->tree != NULL);
@@ -137,8 +131,10 @@ void test_index_tests__find_in_existing(void)
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
- int idx = git_index_find(index, test_entries[i].path);
- cl_assert(idx == test_entries[i].index);
+ size_t idx;
+
+ cl_assert(!git_index_find(&idx, index, test_entries[i].path));
+ cl_assert(idx == test_entries[i].index);
}
git_index_free(index);
@@ -152,8 +148,7 @@ void test_index_tests__find_in_empty(void)
cl_git_pass(git_index_open(&index, "fake-index"));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
- int idx = git_index_find(index, test_entries[i].path);
- cl_assert(idx == GIT_ENOTFOUND);
+ cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
}
git_index_free(index);
@@ -203,44 +198,221 @@ void test_index_tests__sort1(void)
git_index_free(index);
}
+static void cleanup_myrepo(void *opaque)
+{
+ GIT_UNUSED(opaque);
+ cl_fixture_cleanup("myrepo");
+}
+
void test_index_tests__add(void)
{
- git_index *index;
- git_filebuf file = GIT_FILEBUF_INIT;
- git_repository *repo;
- git_index_entry *entry;
- git_oid id1;
+ git_index *index;
+ git_filebuf file = GIT_FILEBUF_INIT;
+ git_repository *repo;
+ const git_index_entry *entry;
+ git_oid id1;
- /* Intialize a new repository */
- cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
+ cl_set_cleanup(&cleanup_myrepo, NULL);
- /* Ensure we're the only guy in the room */
- cl_git_pass(git_repository_index(&index, repo));
- cl_assert(git_index_entrycount(index) == 0);
+ /* Intialize a new repository */
+ cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
- /* Create a new file in the working directory */
- cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
- cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0));
- cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
- /* Store the expected hash of the file/blob
- * This has been generated by executing the following
- * $ echo "hey there" | git hash-object --stdin
- */
- cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
+ /* Create a new file in the working directory */
+ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0));
+ cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
+ cl_git_pass(git_filebuf_commit(&file, 0666));
- /* Add the new file to the index */
- cl_git_pass(git_index_add(index, "test.txt", 0));
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
- /* Wow... it worked! */
- cl_assert(git_index_entrycount(index) == 1);
- entry = git_index_get(index, 0);
+ /* Add the new file to the index */
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
- /* And the built-in hashing mechanism worked as expected */
- cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ entry = git_index_get_byindex(index, 0);
- git_index_free(index);
- git_repository_free(repo);
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+
+ /* Test access by path instead of index */
+ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+static void cleanup_1397(void *opaque)
+{
+ GIT_UNUSED(opaque);
+ cl_git_sandbox_cleanup();
+}
+
+void test_index_tests__add_issue_1397(void)
+{
+ git_index *index;
+ git_repository *repo;
+ const git_index_entry *entry;
+ git_oid id1;
+
+ cl_set_cleanup(&cleanup_1397, NULL);
+
+ repo = cl_git_sandbox_init("issue_1397");
+
+ cl_repo_set_bool(repo, "core.autocrlf", true);
+
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ git hash-object crlf_file.txt
+ */
+ cl_git_pass(git_oid_fromstr(&id1, "8312e0889a9cbab77c732b6bc39b51a683e3a318"));
+
+ /* Make sure the initial SHA-1 is correct */
+ cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL);
+ cl_assert_(git_oid_cmp(&id1, &entry->oid) == 0, "first oid check");
+
+ /* Update the index */
+ cl_git_pass(git_index_add_bypath(index, "crlf_file.txt"));
+
+ /* Check the new SHA-1 */
+ cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL);
+ cl_assert_(git_oid_cmp(&id1, &entry->oid) == 0, "second oid check");
+
+ git_index_free(index);
}
+void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
+{
+ git_repository *bare_repo;
+ git_index *index;
+
+ cl_git_pass(git_repository_open(&bare_repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_index(&index, bare_repo));
+
+ cl_assert_equal_i(GIT_EBAREREPO, git_index_add_bypath(index, "test.txt"));
+
+ git_index_free(index);
+ git_repository_free(bare_repo);
+}
+
+/* Test that writing an invalid filename fails */
+void test_index_tests__write_invalid_filename(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_oid expected;
+
+ p_mkdir("read_tree", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./read_tree", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ cl_git_mkfile("./read_tree/.git/hello", NULL);
+
+ cl_git_pass(git_index_add_bypath(index, ".git/hello"));
+
+ /* write-tree */
+ cl_git_fail(git_index_write_tree(&expected, index));
+
+ git_index_free(index);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("read_tree");
+}
+
+void test_index_tests__remove_entry(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ p_mkdir("index_test", 0770);
+
+ cl_git_pass(git_repository_init(&repo, "index_test", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ cl_git_mkfile("index_test/hello", NULL);
+ cl_git_pass(git_index_add_bypath(index, "hello"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index)); /* reload */
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_get_bypath(index, "hello", 0) != NULL);
+
+ cl_git_pass(git_index_remove(index, "hello", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index)); /* reload */
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_index_get_bypath(index, "hello", 0) == NULL);
+
+ git_index_free(index);
+ git_repository_free(repo);
+ cl_fixture_cleanup("index_test");
+}
+
+void test_index_tests__remove_directory(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ p_mkdir("index_test", 0770);
+
+ cl_git_pass(git_repository_init(&repo, "index_test", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert_equal_i(0, (int)git_index_entrycount(index));
+
+ p_mkdir("index_test/a", 0770);
+ cl_git_mkfile("index_test/a/1.txt", NULL);
+ cl_git_mkfile("index_test/a/2.txt", NULL);
+ cl_git_mkfile("index_test/a/3.txt", NULL);
+ cl_git_mkfile("index_test/b.txt", NULL);
+
+ cl_git_pass(git_index_add_bypath(index, "a/1.txt"));
+ cl_git_pass(git_index_add_bypath(index, "a/2.txt"));
+ cl_git_pass(git_index_add_bypath(index, "a/3.txt"));
+ cl_git_pass(git_index_add_bypath(index, "b.txt"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index)); /* reload */
+ cl_assert_equal_i(4, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ cl_git_pass(git_index_remove(index, "a/1.txt", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index)); /* reload */
+ cl_assert_equal_i(3, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ cl_git_pass(git_index_remove_directory(index, "a", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index)); /* reload */
+ cl_assert_equal_i(1, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ git_index_free(index);
+ git_repository_free(repo);
+ cl_fixture_cleanup("index_test");
+}
diff --git a/tests-clar/main.c b/tests-clar/main.c
new file mode 100644
index 000000000..6b498939d
--- /dev/null
+++ b/tests-clar/main.c
@@ -0,0 +1,20 @@
+#include "clar_libgit2.h"
+
+#ifdef _WIN32
+int __cdecl main(int argc, char *argv[])
+#else
+int main(int argc, char *argv[])
+#endif
+{
+ int res;
+
+ git_threads_init();
+
+ /* Run the test suite */
+ res = clar_test(argc, argv);
+
+ giterr_clear();
+ git_threads_shutdown();
+
+ return res;
+}
diff --git a/tests-clar/merge/setup.c b/tests-clar/merge/setup.c
new file mode 100644
index 000000000..946c67e7b
--- /dev/null
+++ b/tests-clar/merge/setup.c
@@ -0,0 +1,139 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/merge.h"
+#include "merge.h"
+#include "refs.h"
+#include "fileops.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "testrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define ORIG_HEAD "bd593285fc7fe4ca18ccdbabf027f5d689101452"
+
+#define THEIRS_SIMPLE_BRANCH "branch"
+#define THEIRS_SIMPLE_OID "7cb63eed597130ba4abb87b3e544b85021905520"
+
+#define OCTO1_BRANCH "octo1"
+#define OCTO1_OID "16f825815cfd20a07a75c71554e82d8eede0b061"
+
+#define OCTO2_BRANCH "octo2"
+#define OCTO2_OID "158dc7bedb202f5b26502bf3574faa7f4238d56c"
+
+#define OCTO3_BRANCH "octo3"
+#define OCTO3_OID "50ce7d7d01217679e26c55939eef119e0c93e272"
+
+#define OCTO4_BRANCH "octo4"
+#define OCTO4_OID "54269b3f6ec3d7d4ede24dd350dd5d605495c3ae"
+
+#define OCTO5_BRANCH "octo5"
+#define OCTO5_OID "e4f618a2c3ed0669308735727df5ebf2447f022f"
+
+// Fixture setup and teardown
+void test_merge_setup__initialize(void)
+{
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+ git_repository_index(&repo_index, repo);
+}
+
+void test_merge_setup__cleanup(void)
+{
+ git_index_free(repo_index);
+ cl_git_sandbox_cleanup();
+}
+
+static void write_file_contents(const char *filename, const char *output)
+{
+ git_buf file_path_buf = GIT_BUF_INIT;
+
+ git_buf_printf(&file_path_buf, "%s/%s", git_repository_path(repo), filename);
+ cl_git_rewritefile(file_path_buf.ptr, output);
+
+ git_buf_free(&file_path_buf);
+}
+
+struct merge_head_cb_data {
+ const char **oid_str;
+ unsigned int len;
+
+ unsigned int i;
+};
+
+static int merge_head_foreach_cb(const git_oid *oid, void *payload)
+{
+ git_oid expected_oid;
+ struct merge_head_cb_data *cb_data = payload;
+
+ git_oid_fromstr(&expected_oid, cb_data->oid_str[cb_data->i]);
+ cl_assert(git_oid_cmp(&expected_oid, oid) == 0);
+ cb_data->i++;
+ return 0;
+}
+
+void test_merge_setup__head_notfound(void)
+{
+ int error;
+
+ cl_git_fail((error = git_repository_mergehead_foreach(repo,
+ merge_head_foreach_cb, NULL)));
+ cl_assert(error == GIT_ENOTFOUND);
+}
+
+void test_merge_setup__head_invalid_oid(void)
+{
+ int error;
+
+ write_file_contents(GIT_MERGE_HEAD_FILE, "invalid-oid\n");
+
+ cl_git_fail((error = git_repository_mergehead_foreach(repo,
+ merge_head_foreach_cb, NULL)));
+ cl_assert(error == -1);
+}
+
+void test_merge_setup__head_foreach_nonewline(void)
+{
+ int error;
+
+ write_file_contents(GIT_MERGE_HEAD_FILE, THEIRS_SIMPLE_OID);
+
+ cl_git_fail((error = git_repository_mergehead_foreach(repo,
+ merge_head_foreach_cb, NULL)));
+ cl_assert(error == -1);
+}
+
+void test_merge_setup__head_foreach_one(void)
+{
+ const char *expected = THEIRS_SIMPLE_OID;
+
+ struct merge_head_cb_data cb_data = { &expected, 1 };
+
+ write_file_contents(GIT_MERGE_HEAD_FILE, THEIRS_SIMPLE_OID "\n");
+
+ cl_git_pass(git_repository_mergehead_foreach(repo,
+ merge_head_foreach_cb, &cb_data));
+
+ cl_assert(cb_data.i == cb_data.len);
+}
+
+void test_merge_setup__head_foreach_octopus(void)
+{
+ const char *expected[] = { THEIRS_SIMPLE_OID,
+ OCTO1_OID, OCTO2_OID, OCTO3_OID, OCTO4_OID, OCTO5_OID };
+
+ struct merge_head_cb_data cb_data = { expected, 6 };
+
+ write_file_contents(GIT_MERGE_HEAD_FILE,
+ THEIRS_SIMPLE_OID "\n"
+ OCTO1_OID "\n"
+ OCTO2_OID "\n"
+ OCTO3_OID "\n"
+ OCTO4_OID "\n"
+ OCTO5_OID "\n");
+
+ cl_git_pass(git_repository_mergehead_foreach(repo,
+ merge_head_foreach_cb, &cb_data));
+
+ cl_assert(cb_data.i == cb_data.len);
+}
diff --git a/tests-clar/network/cred.c b/tests-clar/network/cred.c
new file mode 100644
index 000000000..6994cc0c3
--- /dev/null
+++ b/tests-clar/network/cred.c
@@ -0,0 +1,50 @@
+#include "clar_libgit2.h"
+
+#include "git2/cred_helpers.h"
+
+void test_network_cred__stock_userpass_validates_args(void)
+{
+ git_cred_userpass_payload payload = {0};
+
+ cl_git_fail(git_cred_userpass(NULL, NULL, NULL, 0, NULL));
+
+ payload.username = "user";
+ cl_git_fail(git_cred_userpass(NULL, NULL, NULL, 0, &payload));
+
+ payload.username = NULL;
+ payload.username = "pass";
+ cl_git_fail(git_cred_userpass(NULL, NULL, NULL, 0, &payload));
+}
+
+void test_network_cred__stock_userpass_validates_that_method_is_allowed(void)
+{
+ git_cred *cred;
+ git_cred_userpass_payload payload = {"user", "pass"};
+
+ cl_git_fail(git_cred_userpass(&cred, NULL, NULL, 0, &payload));
+ cl_git_pass(git_cred_userpass(&cred, NULL, NULL, GIT_CREDTYPE_USERPASS_PLAINTEXT, &payload));
+ cred->free(cred);
+}
+
+void test_network_cred__stock_userpass_properly_handles_username_in_url(void)
+{
+ git_cred *cred;
+ git_cred_userpass_plaintext *plain;
+ git_cred_userpass_payload payload = {"alice", "password"};
+
+ cl_git_pass(git_cred_userpass(&cred, NULL, NULL, GIT_CREDTYPE_USERPASS_PLAINTEXT, &payload));
+ plain = (git_cred_userpass_plaintext*)cred;
+ cl_assert_equal_s(plain->username, "alice");
+ cred->free(cred);
+
+ cl_git_pass(git_cred_userpass(&cred, NULL, "bob", GIT_CREDTYPE_USERPASS_PLAINTEXT, &payload));
+ plain = (git_cred_userpass_plaintext*)cred;
+ cl_assert_equal_s(plain->username, "alice");
+ cred->free(cred);
+
+ payload.username = NULL;
+ cl_git_pass(git_cred_userpass(&cred, NULL, "bob", GIT_CREDTYPE_USERPASS_PLAINTEXT, &payload));
+ plain = (git_cred_userpass_plaintext*)cred;
+ cl_assert_equal_s(plain->username, "bob");
+ cred->free(cred);
+}
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
new file mode 100644
index 000000000..bcf298cde
--- /dev/null
+++ b/tests-clar/network/fetchlocal.c
@@ -0,0 +1,78 @@
+#include "clar_libgit2.h"
+
+#include "buffer.h"
+#include "path.h"
+#include "remote.h"
+
+static int transfer_cb(const git_transfer_progress *stats, void *payload)
+{
+ int *callcount = (int*)payload;
+ GIT_UNUSED(stats);
+ (*callcount)++;
+ return 0;
+}
+
+static void cleanup_local_repo(void *path)
+{
+ cl_fixture_cleanup((char *)path);
+}
+
+void test_network_fetchlocal__complete(void)
+{
+ git_repository *repo;
+ git_remote *origin;
+ int callcount = 0;
+ git_strarray refnames = {0};
+
+ const char *url = cl_git_fixture_url("testrepo.git");
+
+ cl_set_cleanup(&cleanup_local_repo, "foo");
+ cl_git_pass(git_repository_init(&repo, "foo", true));
+
+ cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
+ cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
+ cl_git_pass(git_remote_update_tips(origin));
+
+ cl_git_pass(git_reference_list(&refnames, repo, GIT_REF_LISTALL));
+ cl_assert_equal_i(19, (int)refnames.count);
+ cl_assert(callcount > 0);
+
+ git_strarray_free(&refnames);
+ git_remote_free(origin);
+ git_repository_free(repo);
+}
+
+static void cleanup_sandbox(void *unused)
+{
+ GIT_UNUSED(unused);
+ cl_git_sandbox_cleanup();
+}
+
+void test_network_fetchlocal__partial(void)
+{
+ git_repository *repo = cl_git_sandbox_init("partial-testrepo");
+ git_remote *origin;
+ int callcount = 0;
+ git_strarray refnames = {0};
+ const char *url;
+
+ cl_set_cleanup(&cleanup_sandbox, NULL);
+ cl_git_pass(git_reference_list(&refnames, repo, GIT_REF_LISTALL));
+ cl_assert_equal_i(1, (int)refnames.count);
+
+ url = cl_git_fixture_url("testrepo.git");
+ cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
+ cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
+ cl_git_pass(git_remote_update_tips(origin));
+
+ git_strarray_free(&refnames);
+
+ cl_git_pass(git_reference_list(&refnames, repo, GIT_REF_LISTALL));
+ cl_assert_equal_i(20, (int)refnames.count); /* 18 remote + 1 local */
+ cl_assert(callcount > 0);
+
+ git_strarray_free(&refnames);
+ git_remote_free(origin);
+}
diff --git a/tests-clar/network/refspecs.c b/tests-clar/network/refspecs.c
new file mode 100644
index 000000000..b3d80fb85
--- /dev/null
+++ b/tests-clar/network/refspecs.c
@@ -0,0 +1,84 @@
+#include "clar_libgit2.h"
+#include "refspec.h"
+#include "remote.h"
+
+static void assert_refspec(unsigned int direction, const char *input, bool is_expected_to_be_valid)
+{
+ git_refspec refspec;
+ int error;
+
+ error = git_refspec__parse(&refspec, input, direction == GIT_DIRECTION_FETCH);
+ git_refspec__free(&refspec);
+
+ if (is_expected_to_be_valid)
+ cl_assert_equal_i(0, error);
+ else
+ cl_assert_equal_i(GIT_ERROR, error);
+}
+
+void test_network_refspecs__parsing(void)
+{
+ // Ported from https://github.com/git/git/blob/abd2bde78bd994166900290434a2048e660dabed/t/t5511-refspec.sh
+
+ assert_refspec(GIT_DIRECTION_PUSH, "", false);
+ assert_refspec(GIT_DIRECTION_PUSH, ":", true);
+ assert_refspec(GIT_DIRECTION_PUSH, "::", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "+:", true);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "", true);
+ assert_refspec(GIT_DIRECTION_PUSH, ":", true);
+ assert_refspec(GIT_DIRECTION_FETCH, "::", false);
+
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*:refs/remotes/frotz/*", true);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*:refs/remotes/frotz", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads:refs/remotes/frotz/*", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/master:refs/remotes/frotz/xyzzy", true);
+
+ /*
+ * These have invalid LHS, but we do not have a formal "valid sha-1
+ * expression syntax checker" so they are not checked with the current
+ * code. They will be caught downstream anyway, but we may want to
+ * have tighter check later...
+ */
+ //assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/master::refs/remotes/frotz/xyzzy", false);
+ //assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/maste :refs/remotes/frotz/xyzzy", false);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*:refs/remotes/frotz/*", true);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*:refs/remotes/frotz", false);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads:refs/remotes/frotz/*", false);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/master:refs/remotes/frotz/xyzzy", true);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/master::refs/remotes/frotz/xyzzy", false);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/maste :refs/remotes/frotz/xyzzy", false);
+
+ assert_refspec(GIT_DIRECTION_PUSH, "master~1:refs/remotes/frotz/backup", true);
+ assert_refspec(GIT_DIRECTION_FETCH, "master~1:refs/remotes/frotz/backup", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "HEAD~4:refs/remotes/frotz/new", true);
+ assert_refspec(GIT_DIRECTION_FETCH, "HEAD~4:refs/remotes/frotz/new", false);
+
+ assert_refspec(GIT_DIRECTION_PUSH, "HEAD", true);
+ assert_refspec(GIT_DIRECTION_FETCH, "HEAD", true);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/ nitfol", false);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/ nitfol", false);
+
+ assert_refspec(GIT_DIRECTION_PUSH, "HEAD:", false);
+ assert_refspec(GIT_DIRECTION_FETCH, "HEAD:", true);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/ nitfol:", false);
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/ nitfol:", false);
+
+ assert_refspec(GIT_DIRECTION_PUSH, ":refs/remotes/frotz/deleteme", true);
+ assert_refspec(GIT_DIRECTION_FETCH, ":refs/remotes/frotz/HEAD-to-me", true);
+ assert_refspec(GIT_DIRECTION_PUSH, ":refs/remotes/frotz/delete me", false);
+ assert_refspec(GIT_DIRECTION_FETCH, ":refs/remotes/frotz/HEAD to me", false);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/for-linus:refs/remotes/mine/*-blah", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/for-linus:refs/remotes/mine/*-blah", false);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads*/for-linus:refs/remotes/mine/*", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads*/for-linus:refs/remotes/mine/*", false);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/*/for-linus:refs/remotes/mine/*", false);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/*/for-linus:refs/remotes/mine/*", false);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/for-linus:refs/remotes/mine/*", true);
+ assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/for-linus:refs/remotes/mine/*", true);
+}
diff --git a/tests-clar/network/createremotethenload.c b/tests-clar/network/remote/createthenload.c
index 45931d376..ac6cfccd3 100644
--- a/tests-clar/network/createremotethenload.c
+++ b/tests-clar/network/remote/createthenload.c
@@ -5,7 +5,7 @@ static git_repository *_repo;
static git_config *_config;
static char url[] = "http://github.com/libgit2/libgit2.git";
-void test_network_createremotethenload__initialize(void)
+void test_network_remote_createthenload__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
@@ -19,14 +19,18 @@ void test_network_createremotethenload__initialize(void)
cl_git_pass(git_remote_load(&_remote, _repo, "origin"));
}
-void test_network_createremotethenload__cleanup(void)
+void test_network_remote_createthenload__cleanup(void)
{
git_remote_free(_remote);
+ _remote = NULL;
+
git_repository_free(_repo);
+ _repo = NULL;
+
cl_fixture_cleanup("testrepo.git");
}
-void test_network_createremotethenload__parsing(void)
+void test_network_remote_createthenload__parsing(void)
{
cl_assert_equal_s(git_remote_name(_remote), "origin");
cl_assert_equal_s(git_remote_url(_remote), url);
diff --git a/tests-clar/network/remote/isvalidname.c b/tests-clar/network/remote/isvalidname.c
new file mode 100644
index 000000000..c26fbd0a5
--- /dev/null
+++ b/tests-clar/network/remote/isvalidname.c
@@ -0,0 +1,17 @@
+#include "clar_libgit2.h"
+
+void test_network_remote_isvalidname__can_detect_invalid_formats(void)
+{
+ cl_assert_equal_i(false, git_remote_is_valid_name("/"));
+ cl_assert_equal_i(false, git_remote_is_valid_name("//"));
+ cl_assert_equal_i(false, git_remote_is_valid_name(".lock"));
+ cl_assert_equal_i(false, git_remote_is_valid_name("a.lock"));
+ cl_assert_equal_i(false, git_remote_is_valid_name("/no/leading/slash"));
+ cl_assert_equal_i(false, git_remote_is_valid_name("no/trailing/slash/"));
+}
+
+void test_network_remote_isvalidname__wont_hopefully_choke_on_valid_formats(void)
+{
+ cl_assert_equal_i(true, git_remote_is_valid_name("webmatrix"));
+ cl_assert_equal_i(true, git_remote_is_valid_name("yishaigalatzer/rules"));
+}
diff --git a/tests-clar/network/remote/local.c b/tests-clar/network/remote/local.c
new file mode 100644
index 000000000..7e847e654
--- /dev/null
+++ b/tests-clar/network/remote/local.c
@@ -0,0 +1,102 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "path.h"
+#include "posix.h"
+
+static git_repository *repo;
+static git_buf file_path_buf = GIT_BUF_INIT;
+static git_remote *remote;
+
+void test_network_remote_local__initialize(void)
+{
+ cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
+ cl_assert(repo != NULL);
+}
+
+void test_network_remote_local__cleanup(void)
+{
+ git_buf_free(&file_path_buf);
+
+ git_remote_free(remote);
+ remote = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_fixture_cleanup("remotelocal");
+}
+
+static int count_ref__cb(git_remote_head *head, void *payload)
+{
+ int *count = (int *)payload;
+
+ (void)head;
+ (*count)++;
+
+ return 0;
+}
+
+static int ensure_peeled__cb(git_remote_head *head, void *payload)
+{
+ GIT_UNUSED(payload);
+
+ if(strcmp(head->name, "refs/tags/test^{}") != 0)
+ return 0;
+
+ return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d");
+}
+
+static void connect_to_local_repository(const char *local_repository)
+{
+ git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
+
+ cl_git_pass(git_remote_create_inmemory(&remote, repo, NULL, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+
+}
+
+void test_network_remote_local__connected(void)
+{
+ connect_to_local_repository(cl_fixture("testrepo.git"));
+ cl_assert(git_remote_connected(remote));
+
+ git_remote_disconnect(remote);
+ cl_assert(!git_remote_connected(remote));
+}
+
+void test_network_remote_local__retrieve_advertised_references(void)
+{
+ int how_many_refs = 0;
+
+ connect_to_local_repository(cl_fixture("testrepo.git"));
+
+ cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+
+ cl_assert_equal_i(how_many_refs, 28);
+}
+
+void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void)
+{
+ int how_many_refs = 0;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
+
+ connect_to_local_repository("spaced testrepo.git");
+
+ cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+
+ cl_assert_equal_i(how_many_refs, 28);
+
+ git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
+ remote = NULL;
+
+ cl_fixture_cleanup("spaced testrepo.git");
+}
+
+void test_network_remote_local__nested_tags_are_completely_peeled(void)
+{
+ connect_to_local_repository(cl_fixture("testrepo.git"));
+
+ cl_git_pass(git_remote_ls(remote, &ensure_peeled__cb, NULL));
+}
diff --git a/tests-clar/network/remote/remotes.c b/tests-clar/network/remote/remotes.c
new file mode 100644
index 000000000..a5ff7415f
--- /dev/null
+++ b/tests-clar/network/remote/remotes.c
@@ -0,0 +1,388 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "refspec.h"
+#include "remote.h"
+
+static git_remote *_remote;
+static git_repository *_repo;
+static const git_refspec *_refspec;
+
+void test_network_remote_remotes__initialize(void)
+{
+ _repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "test"));
+
+ _refspec = git_remote_fetchspec(_remote);
+ cl_assert(_refspec != NULL);
+}
+
+void test_network_remote_remotes__cleanup(void)
+{
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_network_remote_remotes__parsing(void)
+{
+ git_remote *_remote2 = NULL;
+
+ cl_assert_equal_s(git_remote_name(_remote), "test");
+ cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
+ cl_assert(git_remote_pushurl(_remote) == NULL);
+
+ cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_FETCH),
+ "git://github.com/libgit2/libgit2");
+ cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_PUSH),
+ "git://github.com/libgit2/libgit2");
+
+ cl_git_pass(git_remote_load(&_remote2, _repo, "test_with_pushurl"));
+ cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
+ cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
+ cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
+
+ cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_FETCH),
+ "git://github.com/libgit2/fetchlibgit2");
+ cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_PUSH),
+ "git://github.com/libgit2/pushlibgit2");
+
+ git_remote_free(_remote2);
+}
+
+void test_network_remote_remotes__pushurl(void)
+{
+ cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/notlibgit2"));
+ cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/notlibgit2");
+
+ cl_git_pass(git_remote_set_pushurl(_remote, NULL));
+ cl_assert(git_remote_pushurl(_remote) == NULL);
+}
+
+void test_network_remote_remotes__error_when_no_push_available(void)
+{
+ git_remote *r;
+ git_transport *t;
+ git_push *p;
+
+ cl_git_pass(git_remote_create_inmemory(&r, _repo, NULL, cl_fixture("testrepo.git")));
+
+ cl_git_pass(git_transport_local(&t,r,NULL));
+
+ /* Make sure that push is really not available */
+ t->push = NULL;
+ cl_git_pass(git_remote_set_transport(r, t));
+
+ cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_push_new(&p, r));
+ cl_git_pass(git_push_add_refspec(p, "refs/heads/master"));
+ cl_git_fail_with(git_push_finish(p), GIT_ERROR);
+
+ git_push_free(p);
+ git_remote_free(r);
+}
+
+void test_network_remote_remotes__parsing_ssh_remote(void)
+{
+ cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") );
+}
+
+void test_network_remote_remotes__parsing_local_path_fails_if_path_not_found(void)
+{
+ cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") );
+}
+
+void test_network_remote_remotes__supported_transport_methods_are_supported(void)
+{
+ cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") );
+}
+
+void test_network_remote_remotes__unsupported_transport_methods_are_unsupported(void)
+{
+ cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") );
+}
+
+void test_network_remote_remotes__refspec_parsing(void)
+{
+ cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
+ cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*");
+}
+
+void test_network_remote_remotes__set_fetchspec(void)
+{
+ cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*"));
+ _refspec = git_remote_fetchspec(_remote);
+ cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
+ cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
+}
+
+void test_network_remote_remotes__set_pushspec(void)
+{
+ cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*"));
+ _refspec = git_remote_pushspec(_remote);
+ cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
+ cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
+}
+
+void test_network_remote_remotes__save(void)
+{
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ /* Set up the remote and save it to config */
+ cl_git_pass(git_remote_create(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2"));
+ cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*"));
+ cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*"));
+ cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push"));
+ cl_git_pass(git_remote_save(_remote));
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ /* Load it from config and make sure everything matches */
+ cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));
+
+ _refspec = git_remote_fetchspec(_remote);
+ cl_assert(_refspec != NULL);
+ cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
+ cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*");
+ cl_assert_equal_i(0, git_refspec_force(_refspec));
+
+ _refspec = git_remote_pushspec(_remote);
+ cl_assert(_refspec != NULL);
+ cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
+ cl_assert_equal_s(git_refspec_dst(_refspec), "refs/heads/*");
+
+ cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
+ cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/libgit2_push");
+
+ /* remove the pushurl again and see if we can save that too */
+ cl_git_pass(git_remote_set_pushurl(_remote, NULL));
+ cl_git_pass(git_remote_save(_remote));
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));
+ cl_assert(git_remote_pushurl(_remote) == NULL);
+}
+
+void test_network_remote_remotes__fnmatch(void)
+{
+ cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
+ cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
+}
+
+void test_network_remote_remotes__transform(void)
+{
+ char ref[1024] = {0};
+
+ cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master"));
+ cl_assert_equal_s(ref, "refs/remotes/test/master");
+}
+
+void test_network_remote_remotes__transform_destination_to_source(void)
+{
+ char ref[1024] = {0};
+
+ cl_git_pass(git_refspec_rtransform(ref, sizeof(ref), _refspec, "refs/remotes/test/master"));
+ cl_assert_equal_s(ref, "refs/heads/master");
+}
+
+void test_network_remote_remotes__transform_r(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_refspec_transform_r(&buf, _refspec, "refs/heads/master"));
+ cl_assert_equal_s(git_buf_cstr(&buf), "refs/remotes/test/master");
+ git_buf_free(&buf);
+}
+
+void test_network_remote_remotes__missing_refspecs(void)
+{
+ git_config *cfg;
+
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_pass(git_repository_config(&cfg, _repo));
+ cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
+ cl_git_pass(git_remote_load(&_remote, _repo, "specless"));
+
+ git_config_free(cfg);
+}
+
+void test_network_remote_remotes__list(void)
+{
+ git_strarray list;
+ git_config *cfg;
+
+ cl_git_pass(git_remote_list(&list, _repo));
+ cl_assert(list.count == 4);
+ git_strarray_free(&list);
+
+ cl_git_pass(git_repository_config(&cfg, _repo));
+ cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
+ cl_git_pass(git_remote_list(&list, _repo));
+ cl_assert(list.count == 5);
+ git_strarray_free(&list);
+
+ git_config_free(cfg);
+}
+
+void test_network_remote_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
+{
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago"));
+}
+
+void test_network_remote_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_load(&_remote, _repo, "Inv@{id"));
+}
+
+/*
+ * $ git remote add addtest http://github.com/libgit2/libgit2
+ *
+ * $ cat .git/config
+ * [...]
+ * [remote "addtest"]
+ * url = http://github.com/libgit2/libgit2
+ * fetch = +refs/heads/\*:refs/remotes/addtest/\*
+ */
+void test_network_remote_remotes__add(void)
+{
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_pass(git_remote_create(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
+
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "addtest"));
+ _refspec = git_remote_fetchspec(_remote);
+ cl_assert_equal_s("refs/heads/*", git_refspec_src(_refspec));
+ cl_assert(git_refspec_force(_refspec) == 1);
+ cl_assert_equal_s("refs/remotes/addtest/*", git_refspec_dst(_refspec));
+ cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
+}
+
+void test_network_remote_remotes__cannot_add_a_nameless_remote(void)
+{
+ git_remote *remote;
+
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC,
+ git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
+}
+
+void test_network_remote_remotes__cannot_save_an_inmemory_remote(void)
+{
+ git_remote *remote;
+
+ cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
+
+ cl_assert_equal_p(NULL, git_remote_name(remote));
+
+ cl_git_fail(git_remote_save(remote));
+ git_remote_free(remote);
+}
+
+void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
+{
+ git_remote *remote = NULL;
+
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC,
+ git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
+ cl_assert_equal_p(remote, NULL);
+
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC,
+ git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
+ cl_assert_equal_p(remote, NULL);
+}
+
+void test_network_remote_remotes__tagopt(void)
+{
+ const char *opt;
+ git_config *cfg;
+
+ cl_git_pass(git_repository_config(&cfg, _repo));
+
+ git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
+ cl_git_pass(git_remote_save(_remote));
+ cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
+ cl_assert_equal_s("--tags", opt);
+
+ git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
+ cl_git_pass(git_remote_save(_remote));
+ cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
+ cl_assert_equal_s("--no-tags", opt);
+
+ git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
+ cl_git_pass(git_remote_save(_remote));
+ cl_assert(git_config_get_string(&opt, cfg, "remote.test.tagopt") == GIT_ENOTFOUND);
+
+ git_config_free(cfg);
+}
+
+void test_network_remote_remotes__cannot_load_with_an_empty_url(void)
+{
+ git_remote *remote = NULL;
+
+ cl_git_fail(git_remote_load(&remote, _repo, "empty-remote-url"));
+ cl_assert(giterr_last()->klass == GITERR_INVALID);
+ cl_assert_equal_p(remote, NULL);
+}
+
+void test_network_remote_remotes__check_structure_version(void)
+{
+ git_transport transport = GIT_TRANSPORT_INIT;
+ const git_error *err;
+
+ git_remote_free(_remote);
+ _remote = NULL;
+ cl_git_pass(git_remote_create_inmemory(&_remote, _repo, NULL, "test-protocol://localhost"));
+
+ transport.version = 0;
+ cl_git_fail(git_remote_set_transport(_remote, &transport));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+
+ giterr_clear();
+ transport.version = 1024;
+ cl_git_fail(git_remote_set_transport(_remote, &transport));
+ err = giterr_last();
+ cl_assert_equal_i(GITERR_INVALID, err->klass);
+}
+
+void assert_cannot_create_remote(const char *name, int expected_error)
+{
+ git_remote *remote = NULL;
+
+ cl_git_fail_with(
+ git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"),
+ expected_error);
+
+ cl_assert_equal_p(remote, NULL);
+}
+
+void test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void)
+{
+ assert_cannot_create_remote("test", GIT_EEXISTS);
+}
+
+
+void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
+{
+ assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
+ assert_cannot_create_remote("//", GIT_EINVALIDSPEC);
+ assert_cannot_create_remote(".lock", GIT_EINVALIDSPEC);
+ assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
+}
diff --git a/tests-clar/network/remote/rename.c b/tests-clar/network/remote/rename.c
new file mode 100644
index 000000000..ed98ee811
--- /dev/null
+++ b/tests-clar/network/remote/rename.c
@@ -0,0 +1,174 @@
+#include "clar_libgit2.h"
+#include "config/config_helpers.h"
+
+#include "repository.h"
+
+static git_remote *_remote;
+static git_repository *_repo;
+
+void test_network_remote_rename__initialize(void)
+{
+ _repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "test"));
+}
+
+void test_network_remote_rename__cleanup(void)
+{
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+static int dont_call_me_cb(const char *fetch_refspec, void *payload)
+{
+ GIT_UNUSED(fetch_refspec);
+ GIT_UNUSED(payload);
+
+ cl_assert(false);
+
+ return -1;
+}
+
+void test_network_remote_rename__renaming_a_remote_moves_related_configuration_section(void)
+{
+ assert_config_entry_existence(_repo, "remote.test.fetch", true);
+ assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false);
+
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
+
+ assert_config_entry_existence(_repo, "remote.test.fetch", false);
+ assert_config_entry_existence(_repo, "remote.just/renamed.fetch", true);
+}
+
+void test_network_remote_rename__renaming_a_remote_updates_branch_related_configuration_entries(void)
+{
+ assert_config_entry_value(_repo, "branch.master.remote", "test");
+
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
+
+ assert_config_entry_value(_repo, "branch.master.remote", "just/renamed");
+}
+
+void test_network_remote_rename__renaming_a_remote_updates_default_fetchrefspec(void)
+{
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
+
+ assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*");
+}
+
+void test_network_remote_rename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void)
+{
+ git_config *config;
+
+ git_remote_free(_remote);
+ cl_git_pass(git_repository_config__weakptr(&config, _repo));
+ cl_git_pass(git_config_delete_entry(config, "remote.test.fetch"));
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "test"));
+
+ assert_config_entry_existence(_repo, "remote.test.fetch", false);
+
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
+
+ assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false);
+}
+
+static int ensure_refspecs(const char* refspec_name, void *payload)
+{
+ int i = 0;
+ bool found = false;
+ const char ** exp = (const char **)payload;
+
+ while (exp[i]) {
+ if (strcmp(exp[i++], refspec_name))
+ continue;
+
+ found = true;
+ break;
+ }
+
+ cl_assert(found);
+
+ return 0;
+}
+
+void test_network_remote_rename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void)
+{
+ git_config *config;
+
+ char *expected_refspecs[] = {
+ "+refs/*:refs/*",
+ NULL
+ };
+
+ git_remote_free(_remote);
+ cl_git_pass(git_repository_config__weakptr(&config, _repo));
+ cl_git_pass(git_config_set_string(config, "remote.test.fetch", "+refs/*:refs/*"));
+ cl_git_pass(git_remote_load(&_remote, _repo, "test"));
+
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", ensure_refspecs, &expected_refspecs));
+
+ assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/*:refs/*");
+}
+
+void test_network_remote_rename__new_name_can_contain_dots(void)
+{
+ cl_git_pass(git_remote_rename(_remote, "just.renamed", dont_call_me_cb, NULL));
+ cl_assert_equal_s("just.renamed", git_remote_name(_remote));
+}
+
+void test_network_remote_rename__new_name_must_conform_to_reference_naming_conventions(void)
+{
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC,
+ git_remote_rename(_remote, "new@{name", dont_call_me_cb, NULL));
+}
+
+void test_network_remote_rename__renamed_name_is_persisted(void)
+{
+ git_remote *renamed;
+ git_repository *another_repo;
+
+ cl_git_fail(git_remote_load(&renamed, _repo, "just/renamed"));
+
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
+
+ cl_git_pass(git_repository_open(&another_repo, "testrepo.git"));
+ cl_git_pass(git_remote_load(&renamed, _repo, "just/renamed"));
+
+ git_remote_free(renamed);
+ git_repository_free(another_repo);
+}
+
+void test_network_remote_rename__cannot_overwrite_an_existing_remote(void)
+{
+ cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test", dont_call_me_cb, NULL));
+ cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test_with_pushurl", dont_call_me_cb, NULL));
+}
+
+void test_network_remote_rename__renaming_a_remote_moves_the_underlying_reference(void)
+{
+ git_reference *underlying;
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed"));
+ cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/test/master"));
+ git_reference_free(underlying);
+
+ cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/test/master"));
+ cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed/master"));
+ git_reference_free(underlying);
+}
+
+void test_network_remote_rename__cannot_rename_an_inmemory_remote(void)
+{
+ git_remote *remote;
+
+ cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "file:///blah"));
+ cl_git_fail(git_remote_rename(remote, "newname", NULL, NULL));
+
+ git_remote_free(remote);
+}
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
deleted file mode 100644
index 98abbbeb9..000000000
--- a/tests-clar/network/remotelocal.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include "clar_libgit2.h"
-#include "transport.h"
-#include "buffer.h"
-#include "path.h"
-#include "posix.h"
-
-static git_repository *repo;
-static git_buf file_path_buf = GIT_BUF_INIT;
-static git_remote *remote;
-
-static void build_local_file_url(git_buf *out, const char *fixture)
-{
- const char *in_buf;
-
- git_buf path_buf = GIT_BUF_INIT;
-
- cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL));
- cl_git_pass(git_buf_puts(out, "file://"));
-
-#ifdef _MSC_VER
- /*
- * A FILE uri matches the following format: file://[host]/path
- * where "host" can be empty and "path" is an absolute path to the resource.
- *
- * In this test, no hostname is used, but we have to ensure the leading triple slashes:
- *
- * *nix: file:///usr/home/...
- * Windows: file:///C:/Users/...
- */
- cl_git_pass(git_buf_putc(out, '/'));
-#endif
-
- in_buf = git_buf_cstr(&path_buf);
-
- /*
- * A very hacky Url encoding that only takes care of escaping the spaces
- */
- while (*in_buf) {
- if (*in_buf == ' ')
- cl_git_pass(git_buf_puts(out, "%20"));
- else
- cl_git_pass(git_buf_putc(out, *in_buf));
-
- in_buf++;
- }
-
- git_buf_free(&path_buf);
-}
-
-void test_network_remotelocal__initialize(void)
-{
- cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
- cl_assert(repo != NULL);
-}
-
-void test_network_remotelocal__cleanup(void)
-{
- git_remote_free(remote);
- git_buf_free(&file_path_buf);
- git_repository_free(repo);
- cl_fixture_cleanup("remotelocal");
-}
-
-static int count_ref__cb(git_remote_head *head, void *payload)
-{
- int *count = (int *)payload;
-
- (void)head;
- (*count)++;
-
- return 0;
-}
-
-static int ensure_peeled__cb(git_remote_head *head, void *payload)
-{
- GIT_UNUSED(payload);
-
- if(strcmp(head->name, "refs/tags/test^{}") != 0)
- return 0;
-
- return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d");
-}
-
-static void connect_to_local_repository(const char *local_repository)
-{
- build_local_file_url(&file_path_buf, local_repository);
-
- cl_git_pass(git_remote_new(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL));
- cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
-
-}
-
-void test_network_remotelocal__retrieve_advertised_references(void)
-{
- int how_many_refs = 0;
-
- connect_to_local_repository(cl_fixture("testrepo.git"));
-
- cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
-
- cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */
-}
-
-void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
-{
- int how_many_refs = 0;
-
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
-
- connect_to_local_repository("spaced testrepo.git");
-
- cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
-
- cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */
-
- git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
- remote = NULL;
-
- cl_fixture_cleanup("spaced testrepo.git");
-}
-
-void test_network_remotelocal__nested_tags_are_completely_peeled(void)
-{
- connect_to_local_repository(cl_fixture("testrepo.git"));
-
- cl_git_pass(git_remote_ls(remote, &ensure_peeled__cb, NULL));
-}
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
deleted file mode 100644
index 0649c86dd..000000000
--- a/tests-clar/network/remotes.c
+++ /dev/null
@@ -1,172 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-#include "refspec.h"
-#include "transport.h"
-
-static git_remote *_remote;
-static git_repository *_repo;
-static const git_refspec *_refspec;
-
-void test_network_remotes__initialize(void)
-{
- cl_fixture_sandbox("testrepo.git");
-
- cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
- cl_git_pass(git_remote_load(&_remote, _repo, "test"));
-
- _refspec = git_remote_fetchspec(_remote);
- cl_assert(_refspec != NULL);
-}
-
-void test_network_remotes__cleanup(void)
-{
- git_remote_free(_remote);
- git_repository_free(_repo);
- cl_fixture_cleanup("testrepo.git");
-}
-
-void test_network_remotes__parsing(void)
-{
- cl_assert_equal_s(git_remote_name(_remote), "test");
- cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
-}
-
-void test_network_remotes__parsing_ssh_remote(void)
-{
- cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") );
-}
-
-void test_network_remotes__parsing_local_path_fails_if_path_not_found(void)
-{
- cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") );
-}
-
-void test_network_remotes__supported_transport_methods_are_supported(void)
-{
- cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") );
-}
-
-void test_network_remotes__unsupported_transport_methods_are_unsupported(void)
-{
- cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") );
-}
-
-void test_network_remotes__refspec_parsing(void)
-{
- cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
- cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*");
-}
-
-void test_network_remotes__set_fetchspec(void)
-{
- cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*"));
- _refspec = git_remote_fetchspec(_remote);
- cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
- cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
-}
-
-void test_network_remotes__set_pushspec(void)
-{
- cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*"));
- _refspec = git_remote_pushspec(_remote);
- cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
- cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
-}
-
-void test_network_remotes__save(void)
-{
- git_remote_free(_remote);
-
- /* Set up the remote and save it to config */
- cl_git_pass(git_remote_new(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2", NULL));
- cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*"));
- cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*"));
- cl_git_pass(git_remote_save(_remote));
- git_remote_free(_remote);
- _remote = NULL;
-
- /* Load it from config and make sure everything matches */
- cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));
-
- _refspec = git_remote_fetchspec(_remote);
- cl_assert(_refspec != NULL);
- cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
- cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*");
-
- _refspec = git_remote_pushspec(_remote);
- cl_assert(_refspec != NULL);
- cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
- cl_assert_equal_s(git_refspec_dst(_refspec), "refs/heads/*");
-}
-
-void test_network_remotes__fnmatch(void)
-{
- cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
- cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
-}
-
-void test_network_remotes__transform(void)
-{
- char ref[1024];
-
- memset(ref, 0x0, sizeof(ref));
- cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master"));
- cl_assert_equal_s(ref, "refs/remotes/test/master");
-}
-
-void test_network_remotes__transform_r(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_refspec_transform_r(&buf, _refspec, "refs/heads/master"));
- cl_assert_equal_s(git_buf_cstr(&buf), "refs/remotes/test/master");
- git_buf_free(&buf);
-}
-
-void test_network_remotes__missing_refspecs(void)
-{
- git_config *cfg;
-
- git_remote_free(_remote);
-
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
- cl_git_pass(git_remote_load(&_remote, _repo, "specless"));
-
- git_config_free(cfg);
-}
-
-void test_network_remotes__list(void)
-{
- git_strarray list;
- git_config *cfg;
-
- cl_git_pass(git_remote_list(&list, _repo));
- cl_assert(list.count == 1);
- git_strarray_free(&list);
-
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
- cl_git_pass(git_remote_list(&list, _repo));
- cl_assert(list.count == 2);
- git_strarray_free(&list);
-
- git_config_free(cfg);
-}
-
-void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
-{
- cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago"));
-}
-
-void test_network_remotes__add(void)
-{
- git_remote_free(_remote);
- cl_git_pass(git_remote_add(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
- git_remote_free(_remote);
-
- cl_git_pass(git_remote_load(&_remote, _repo, "addtest"));
- _refspec = git_remote_fetchspec(_remote);
- cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*"));
- cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/addtest/*"));
-}
diff --git a/tests-clar/network/urlparse.c b/tests-clar/network/urlparse.c
new file mode 100644
index 000000000..173e57d0f
--- /dev/null
+++ b/tests-clar/network/urlparse.c
@@ -0,0 +1,82 @@
+#include "clar_libgit2.h"
+#include "netops.h"
+
+char *host, *port, *user, *pass;
+
+void test_network_urlparse__initialize(void)
+{
+ host = port = user = pass = NULL;
+}
+
+void test_network_urlparse__cleanup(void)
+{
+#define FREE_AND_NULL(x) if (x) { git__free(x); x = NULL; }
+ FREE_AND_NULL(host);
+ FREE_AND_NULL(port);
+ FREE_AND_NULL(user);
+ FREE_AND_NULL(pass);
+}
+
+void test_network_urlparse__trivial(void)
+{
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
+ "example.com/resource", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "8080");
+ cl_assert_equal_p(user, NULL);
+ cl_assert_equal_p(pass, NULL);
+}
+
+void test_network_urlparse__user(void)
+{
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
+ "user@example.com/resource", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "8080");
+ cl_assert_equal_s(user, "user");
+ cl_assert_equal_p(pass, NULL);
+}
+
+void test_network_urlparse__user_pass(void)
+{
+ /* user:pass@hostname.tld/resource */
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
+ "user:pass@example.com/resource", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "8080");
+ cl_assert_equal_s(user, "user");
+ cl_assert_equal_s(pass, "pass");
+}
+
+void test_network_urlparse__port(void)
+{
+ /* hostname.tld:port/resource */
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
+ "example.com:9191/resource", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "9191");
+ cl_assert_equal_p(user, NULL);
+ cl_assert_equal_p(pass, NULL);
+}
+
+void test_network_urlparse__user_port(void)
+{
+ /* user@hostname.tld:port/resource */
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
+ "user@example.com:9191/resource", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "9191");
+ cl_assert_equal_s(user, "user");
+ cl_assert_equal_p(pass, NULL);
+}
+
+void test_network_urlparse__user_pass_port(void)
+{
+ /* user:pass@hostname.tld:port/resource */
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
+ "user:pass@example.com:9191/resource", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "9191");
+ cl_assert_equal_s(user, "user");
+ cl_assert_equal_s(pass, "pass");
+}
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c
index 5185f25ea..82dcaf8ca 100644
--- a/tests-clar/notes/notes.c
+++ b/tests-clar/notes/notes.c
@@ -12,53 +12,36 @@ void test_notes_notes__initialize(void)
void test_notes_notes__cleanup(void)
{
git_signature_free(_sig);
- cl_git_sandbox_cleanup();
-}
+ _sig = NULL;
-static void create_note(git_oid *note_oid, const char *canonical_namespace, const char *target_sha, const char *message)
-{
- git_oid oid;
-
- cl_git_pass(git_oid_fromstr(&oid, target_sha));
- cl_git_pass(git_note_create(note_oid, _repo, _sig, _sig, canonical_namespace, &oid, message));
+ cl_git_sandbox_cleanup();
}
-void test_notes_notes__1(void)
-{
- git_oid oid, note_oid;
- static git_note *note;
- static git_blob *blob;
+static void assert_note_equal(git_note *note, char *message, git_oid *note_oid) {
+ git_blob *blob;
- cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
+ cl_assert_equal_s(git_note_message(note), message);
+ cl_assert(!git_oid_cmp(git_note_oid(note), note_oid));
- cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
- cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
+ cl_git_pass(git_blob_lookup(&blob, _repo, note_oid));
+ cl_assert_equal_s(git_note_message(note), (const char *)git_blob_rawcontent(blob));
- cl_git_pass(git_note_read(&note, _repo, NULL, &oid));
-
- cl_assert_equal_s(git_note_message(note), "hello world\n");
- cl_assert(!git_oid_cmp(git_note_oid(note), &note_oid));
-
- cl_git_pass(git_blob_lookup(&blob, _repo, &note_oid));
- cl_assert_equal_s(git_note_message(note), git_blob_rawcontent(blob));
-
- cl_git_fail(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
- cl_git_fail(git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
-
- cl_git_pass(git_note_remove(_repo, NULL, _sig, _sig, &oid));
- cl_git_pass(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid));
+ git_blob_free(blob);
+}
- cl_git_fail(git_note_remove(_repo, NULL, _sig, _sig, &note_oid));
- cl_git_fail(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid));
+static void create_note(git_oid *note_oid, const char *canonical_namespace, const char *target_sha, const char *message)
+{
+ git_oid oid;
- git_note_free(note);
- git_blob_free(blob);
+ cl_git_pass(git_oid_fromstr(&oid, target_sha));
+ cl_git_pass(git_note_create(note_oid, _repo, _sig, _sig, canonical_namespace, &oid, message, 0));
}
static struct {
const char *note_sha;
const char *annotated_object_sha;
-} list_expectations[] = {
+}
+list_expectations[] = {
{ "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" },
{ "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "9fd738e8f7967c078dceed8190330fc8648ee56a" },
{ "257b43746b6b46caa4aa788376c647cce0a33e2b", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" },
@@ -68,7 +51,8 @@ static struct {
#define EXPECTATIONS_COUNT (sizeof(list_expectations)/sizeof(list_expectations[0])) - 1
-static int note_list_cb(git_note_data *note_data, void *payload)
+static int note_list_cb(
+ const git_oid *blob_id, const git_oid *annotated_obj_id, void *payload)
{
git_oid expected_note_oid, expected_target_oid;
@@ -77,10 +61,10 @@ static int note_list_cb(git_note_data *note_data, void *payload)
cl_assert(*count < EXPECTATIONS_COUNT);
cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha));
- cl_assert(git_oid_cmp(&expected_note_oid, &note_data->blob_oid) == 0);
+ cl_assert(git_oid_cmp(&expected_note_oid, blob_id) == 0);
cl_git_pass(git_oid_fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha));
- cl_assert(git_oid_cmp(&expected_target_oid, &note_data->annotated_object_oid) == 0);
+ cl_assert(git_oid_cmp(&expected_target_oid, annotated_obj_id) == 0);
(*count)++;
@@ -115,11 +99,41 @@ void test_notes_notes__can_retrieve_a_list_of_notes_for_a_given_namespace(void)
create_note(&note_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n");
create_note(&note_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n");
- cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_cb, &retrieved_notes));
+ cl_git_pass(git_note_foreach
+(_repo, "refs/notes/i-can-see-dead-notes", note_list_cb, &retrieved_notes));
cl_assert_equal_i(4, retrieved_notes);
}
+static int note_cancel_cb(
+ const git_oid *blob_id, const git_oid *annotated_obj_id, void *payload)
+{
+ unsigned int *count = (unsigned int *)payload;
+
+ GIT_UNUSED(blob_id);
+ GIT_UNUSED(annotated_obj_id);
+
+ (*count)++;
+
+ return (*count > 2);
+}
+
+void test_notes_notes__can_cancel_foreach(void)
+{
+ git_oid note_oid1, note_oid2, note_oid3, note_oid4;
+ unsigned int retrieved_notes = 0;
+
+ create_note(&note_oid1, "refs/notes/i-can-see-dead-notes", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "I decorate a65f\n");
+ create_note(&note_oid2, "refs/notes/i-can-see-dead-notes", "c47800c7266a2be04c571c04d5a6614691ea99bd", "I decorate c478\n");
+ create_note(&note_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n");
+ create_note(&note_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n");
+
+ cl_assert_equal_i(
+ GIT_EUSER,
+ git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes",
+ note_cancel_cb, &retrieved_notes));
+}
+
void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_returns_ENOTFOUND(void)
{
int error;
@@ -131,3 +145,243 @@ void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_retur
cl_assert_equal_i(0, retrieved_notes);
}
+
+void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_default_namespace(void)
+{
+ git_oid note_oid, target_oid;
+ git_note *note, *default_namespace_note;
+ const char *default_ref;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
+ cl_git_pass(git_note_default_ref(&default_ref, _repo));
+
+ create_note(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
+
+ cl_git_pass(git_note_read(&note, _repo, NULL, &target_oid));
+ cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref, &target_oid));
+
+ assert_note_equal(note, "hello world\n", &note_oid);
+ assert_note_equal(default_namespace_note, "hello world\n", &note_oid);
+
+ git_note_free(note);
+ git_note_free(default_namespace_note);
+}
+
+void test_notes_notes__can_insert_a_note_with_a_custom_namespace(void)
+{
+ git_oid note_oid, target_oid;
+ git_note *note;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
+
+ create_note(&note_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n");
+
+ cl_git_pass(git_note_read(&note, _repo, "refs/notes/some/namespace", &target_oid));
+
+ assert_note_equal(note, "hello world on a custom namespace\n", &note_oid);
+
+ git_note_free(note);
+}
+
+/*
+ * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479
+ * 08b041783f40edfe12bb406c9c9a8a040177c125
+ */
+void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns_EEXISTS(void)
+{
+ int error;
+ git_oid note_oid, target_oid;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
+
+ create_note(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
+ error = git_note_create(&note_oid, _repo, _sig, _sig, NULL, &target_oid, "hello world\n", 0);
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_EEXISTS, error);
+
+ create_note(&note_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
+ error = git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &target_oid, "hello world\n", 0);
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_EEXISTS, error);
+}
+
+
+void test_notes_notes__creating_a_note_on_a_target_can_overwrite_existing_note(void)
+{
+ git_oid note_oid, target_oid;
+ git_note *note, *namespace_note;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
+
+ create_note(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n");
+ cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &target_oid, "hello new world\n", 1));
+
+ cl_git_pass(git_note_read(&note, _repo, NULL, &target_oid));
+ assert_note_equal(note, "hello new world\n", &note_oid);
+
+ create_note(&note_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n");
+ cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &target_oid, "hello new ref world\n", 1));
+
+ cl_git_pass(git_note_read(&namespace_note, _repo, "refs/notes/some/namespace", &target_oid));
+ assert_note_equal(namespace_note, "hello new ref world\n", &note_oid);
+
+ git_note_free(note);
+ git_note_free(namespace_note);
+}
+
+static char *messages[] = {
+ "08c041783f40edfe12bb406c9c9a8a040177c125",
+ "96c45fbe09ab7445fc7c60fd8d17f32494399343",
+ "48cc7e38dcfc1ec87e70ec03e08c3e83d7a16aa1",
+ "24c3eaafb681c3df668f9df96f58e7b8c756eb04",
+ "96ca1b6ccc7858ae94684777f85ac0e7447f7040",
+ "7ac2db4378a08bb244a427c357e0082ee0d57ac6",
+ "e6cba23dbf4ef84fe35e884f017f4e24dc228572",
+ "c8cf3462c7d8feba716deeb2ebe6583bd54589e2",
+ "39c16b9834c2d665ac5f68ad91dc5b933bad8549",
+ "f3c582b1397df6a664224ebbaf9d4cc952706597",
+ "29cec67037fe8e89977474988219016ae7f342a6",
+ "36c4cd238bf8e82e27b740e0741b025f2e8c79ab",
+ "f1c45a47c02e01d5a9a326f1d9f7f756373387f8",
+ "4aca84406f5daee34ab513a60717c8d7b1763ead",
+ "84ce167da452552f63ed8407b55d5ece4901845f",
+ NULL
+};
+
+#define MESSAGES_COUNT (sizeof(messages)/sizeof(messages[0])) - 1
+
+/*
+ * $ git ls-tree refs/notes/fanout
+ * 040000 tree 4b22b35d44b5a4f589edf3dc89196399771796ea 84
+ *
+ * $ git ls-tree 4b22b35
+ * 040000 tree d71aab4f9b04b45ce09bcaa636a9be6231474759 96
+ *
+ * $ git ls-tree d71aab4
+ * 100644 blob 08b041783f40edfe12bb406c9c9a8a040177c125 071c1b46c854b31185ea97743be6a8774479
+ */
+void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void)
+{
+ size_t i;
+ git_oid note_oid, target_oid;
+ git_note *_note;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
+
+ for (i = 0; i < MESSAGES_COUNT; i++) {
+ cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/fanout", &target_oid, messages[i], 0));
+ cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid));
+ git_note_free(_note);
+
+ git_oid_cpy(&target_oid, &note_oid);
+ }
+}
+
+/*
+ * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479
+ * 08b041783f40edfe12bb406c9c9a8a040177c125
+ */
+void test_notes_notes__can_read_a_note_in_an_existing_fanout(void)
+{
+ git_oid note_oid, target_oid;
+ git_note *note;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
+ cl_git_pass(git_note_read(&note, _repo, "refs/notes/fanout", &target_oid));
+
+ cl_git_pass(git_oid_fromstr(&note_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
+ cl_assert(!git_oid_cmp(git_note_oid(note), &note_oid));
+
+ git_note_free(note);
+}
+
+void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void)
+{
+ git_oid target_oid;
+ git_note *note;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
+ cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
+
+ cl_git_fail(git_note_read(&note, _repo, "refs/notes/fanout", &target_oid));
+}
+
+void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(void)
+{
+ int error;
+ git_oid target_oid;
+
+ cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
+ cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
+
+ error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid);
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+}
+
+void test_notes_notes__can_iterate_default_namespace(void)
+{
+ git_note_iterator *iter;
+ git_note *note;
+ git_oid note_id, annotated_id;
+ git_oid note_created[2];
+ const char* note_message[] = {
+ "I decorate a65f\n",
+ "I decorate c478\n"
+ };
+ int i, err;
+
+ create_note(&note_created[0], "refs/notes/commits",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]);
+ create_note(&note_created[1], "refs/notes/commits",
+ "c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]);
+
+ cl_git_pass(git_note_iterator_new(&iter, _repo, NULL));
+
+ for (i = 0; (err = git_note_next(&note_id, &annotated_id, iter)) >= 0; ++i) {
+ cl_git_pass(git_note_read(&note, _repo, NULL, &annotated_id));
+ cl_assert_equal_s(git_note_message(note), note_message[i]);
+ git_note_free(note);
+ }
+
+ cl_assert_equal_i(GIT_ITEROVER, err);
+ cl_assert_equal_i(2, i);
+ git_note_iterator_free(iter);
+}
+
+void test_notes_notes__can_iterate_custom_namespace(void)
+{
+ git_note_iterator *iter;
+ git_note *note;
+ git_oid note_id, annotated_id;
+ git_oid note_created[2];
+ const char* note_message[] = {
+ "I decorate a65f\n",
+ "I decorate c478\n"
+ };
+ int i, err;
+
+ create_note(&note_created[0], "refs/notes/beer",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]);
+ create_note(&note_created[1], "refs/notes/beer",
+ "c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]);
+
+ cl_git_pass(git_note_iterator_new(&iter, _repo, "refs/notes/beer"));
+
+ for (i = 0; (err = git_note_next(&note_id, &annotated_id, iter)) >= 0; ++i) {
+ cl_git_pass(git_note_read(&note, _repo, "refs/notes/beer", &annotated_id));
+ cl_assert_equal_s(git_note_message(note), note_message[i]);
+ git_note_free(note);
+ }
+
+ cl_assert_equal_i(GIT_ITEROVER, err);
+ cl_assert_equal_i(2, i);
+ git_note_iterator_free(iter);
+}
+
+void test_notes_notes__empty_iterate(void)
+{
+ git_note_iterator *iter;
+
+ cl_git_fail(git_note_iterator_new(&iter, _repo, "refs/notes/commits"));
+}
diff --git a/tests-clar/notes/notesref.c b/tests-clar/notes/notesref.c
index 79ad0afee..c89b71ba5 100644
--- a/tests-clar/notes/notesref.c
+++ b/tests-clar/notes/notesref.c
@@ -16,10 +16,17 @@ void test_notes_notesref__initialize(void)
void test_notes_notesref__cleanup(void)
{
git_note_free(_note);
+ _note = NULL;
+
git_signature_free(_sig);
+ _sig = NULL;
+
git_config_free(_cfg);
+ _cfg = NULL;
git_repository_free(_repo);
+ _repo = NULL;
+
cl_fixture_cleanup("testrepo.git");
}
@@ -35,23 +42,23 @@ void test_notes_notesref__config_corenotesref(void)
cl_git_pass(git_config_set_string(_cfg, "core.notesRef", "refs/notes/mydefaultnotesref"));
- cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "test123test\n"));
+ cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "test123test\n", 0));
cl_git_pass(git_note_read(&_note, _repo, NULL, &oid));
- cl_assert(!strcmp(git_note_message(_note), "test123test\n"));
+ cl_assert_equal_s("test123test\n", git_note_message(_note));
cl_assert(!git_oid_cmp(git_note_oid(_note), &note_oid));
git_note_free(_note);
cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid));
- cl_assert(!strcmp(git_note_message(_note), "test123test\n"));
+ cl_assert_equal_s("test123test\n", git_note_message(_note));
cl_assert(!git_oid_cmp(git_note_oid(_note), &note_oid));
cl_git_pass(git_note_default_ref(&default_ref, _repo));
- cl_assert(!strcmp(default_ref, "refs/notes/mydefaultnotesref"));
+ cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref);
- cl_git_pass(git_config_delete(_cfg, "core.notesRef"));
+ cl_git_pass(git_config_delete_entry(_cfg, "core.notesRef"));
cl_git_pass(git_note_default_ref(&default_ref, _repo));
- cl_assert(!strcmp(default_ref, GIT_NOTES_DEFAULT_REF));
+ cl_assert_equal_s(GIT_NOTES_DEFAULT_REF, default_ref);
}
diff --git a/tests-clar/object/blob/filter.c b/tests-clar/object/blob/filter.c
index 0b87b2b46..042bddab7 100644
--- a/tests-clar/object/blob/filter.c
+++ b/tests-clar/object/blob/filter.c
@@ -2,9 +2,10 @@
#include "posix.h"
#include "blob.h"
#include "filter.h"
+#include "buf_text.h"
static git_repository *g_repo = NULL;
-#define NUM_TEST_OBJECTS 6
+#define NUM_TEST_OBJECTS 8
static git_oid g_oids[NUM_TEST_OBJECTS];
static const char *g_raw[NUM_TEST_OBJECTS] = {
"",
@@ -12,16 +13,20 @@ static const char *g_raw[NUM_TEST_OBJECTS] = {
"foo\rbar\r",
"foo\r\nbar\r\n",
"foo\nbar\rboth\r\nreversed\n\ragain\nproblems\r",
- "123\n\000\001\002\003\004abc\255\254\253\r\n"
+ "123\n\000\001\002\003\004abc\255\254\253\r\n",
+ "\xEF\xBB\xBFThis is UTF-8\n",
+ "\xFE\xFF\x00T\x00h\x00i\x00s\x00!"
};
-static int g_len[NUM_TEST_OBJECTS] = { -1, -1, -1, -1, -1, 17 };
-static git_text_stats g_stats[NUM_TEST_OBJECTS] = {
- { 0, 0, 0, 0, 0, 0 },
- { 0, 0, 2, 0, 6, 0 },
- { 0, 2, 0, 0, 6, 0 },
- { 0, 2, 2, 2, 6, 0 },
- { 0, 4, 4, 1, 31, 0 },
- { 1, 1, 2, 1, 9, 5 }
+static git_off_t g_len[NUM_TEST_OBJECTS] = { -1, -1, -1, -1, -1, 17, -1, 12 };
+static git_buf_text_stats g_stats[NUM_TEST_OBJECTS] = {
+ { 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 2, 0, 6, 0 },
+ { 0, 0, 2, 0, 0, 6, 0 },
+ { 0, 0, 2, 2, 2, 6, 0 },
+ { 0, 0, 4, 4, 1, 31, 0 },
+ { 0, 1, 1, 2, 1, 9, 5 },
+ { GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
+ { GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
};
static git_buf g_crlf_filtered[NUM_TEST_OBJECTS] = {
{ "", 0, 0 },
@@ -29,7 +34,9 @@ static git_buf g_crlf_filtered[NUM_TEST_OBJECTS] = {
{ "foo\rbar\r", 0, 8 },
{ "foo\nbar\n", 0, 8 },
{ "foo\nbar\rboth\nreversed\n\ragain\nproblems\r", 0, 38 },
- { "123\n\000\001\002\003\004abc\255\254\253\n", 0, 16 }
+ { "123\n\000\001\002\003\004abc\255\254\253\n", 0, 16 },
+ { "\xEF\xBB\xBFThis is UTF-8\n", 0, 17 },
+ { "\xFE\xFF\x00T\x00h\x00i\x00s\x00!", 0, 12 }
};
void test_object_blob_filter__initialize(void)
@@ -43,7 +50,7 @@ void test_object_blob_filter__initialize(void)
for (i = 0; i < NUM_TEST_OBJECTS; i++) {
size_t len = (g_len[i] < 0) ? strlen(g_raw[i]) : (size_t)g_len[i];
- g_len[i] = (int)len;
+ g_len[i] = (git_off_t)len;
cl_git_pass(
git_blob_create_frombuffer(&g_oids[i], g_repo, g_raw[i], len)
@@ -65,8 +72,8 @@ void test_object_blob_filter__unfiltered(void)
for (i = 0; i < NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i]));
- cl_assert((size_t)g_len[i] == git_blob_rawsize(blob));
- cl_assert(memcmp(git_blob_rawcontent(blob), g_raw[i], g_len[i]) == 0);
+ cl_assert(g_len[i] == git_blob_rawsize(blob));
+ cl_assert(memcmp(git_blob_rawcontent(blob), g_raw[i], (size_t)g_len[i]) == 0);
git_blob_free(blob);
}
}
@@ -76,12 +83,12 @@ void test_object_blob_filter__stats(void)
int i;
git_blob *blob;
git_buf buf = GIT_BUF_INIT;
- git_text_stats stats;
+ git_buf_text_stats stats;
for (i = 0; i < NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i]));
cl_git_pass(git_blob__getbuf(&buf, blob));
- git_text_gather_stats(&stats, &buf);
+ git_buf_text_gather_stats(&stats, &buf, false);
cl_assert(memcmp(&g_stats[i], &stats, sizeof(stats)) == 0);
git_blob_free(blob);
}
diff --git a/tests-clar/object/blob/fromchunks.c b/tests-clar/object/blob/fromchunks.c
new file mode 100644
index 000000000..dc57d4fbe
--- /dev/null
+++ b/tests-clar/object/blob/fromchunks.c
@@ -0,0 +1,87 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "posix.h"
+#include "path.h"
+#include "fileops.h"
+
+static git_repository *repo;
+static char textual_content[] = "libgit2\n\r\n\0";
+
+void test_object_blob_fromchunks__initialize(void)
+{
+ repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_object_blob_fromchunks__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static int text_chunked_source_cb(char *content, size_t max_length, void *payload)
+{
+ int *count;
+
+ GIT_UNUSED(max_length);
+
+ count = (int *)payload;
+ (*count)--;
+
+ if (*count == 0)
+ return 0;
+
+ strcpy(content, textual_content);
+ return (int)strlen(textual_content);
+}
+
+void test_object_blob_fromchunks__can_create_a_blob_from_a_in_memory_chunk_provider(void)
+{
+ git_oid expected_oid, oid;
+ git_object *blob;
+ int howmany = 7;
+
+ cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9"));
+
+ cl_git_fail(git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY));
+
+ cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany));
+
+ cl_git_pass(git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY));
+ git_object_free(blob);
+}
+
+#define GITATTR "* text=auto\n" \
+ "*.txt text\n" \
+ "*.data binary\n"
+
+static void write_attributes(git_repository *repo)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "info"));
+ cl_git_pass(git_buf_joinpath(&buf, git_buf_cstr(&buf), "attributes"));
+
+ cl_git_pass(git_futils_mkpath2file(git_buf_cstr(&buf), 0777));
+ cl_git_rewritefile(git_buf_cstr(&buf), GITATTR);
+
+ git_buf_free(&buf);
+}
+
+static void assert_named_chunked_blob(const char *expected_sha, const char *fake_name)
+{
+ git_oid expected_oid, oid;
+ int howmany = 7;
+
+ cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha));
+
+ cl_git_pass(git_blob_create_fromchunks(&oid, repo, fake_name, text_chunked_source_cb, &howmany));
+ cl_assert(git_oid_cmp(&expected_oid, &oid) == 0);
+}
+
+void test_object_blob_fromchunks__creating_a_blob_from_chunks_honors_the_attributes_directives(void)
+{
+ write_attributes(repo);
+
+ assert_named_chunked_blob("321cbdf08803c744082332332838df6bd160f8f9", "dummy.data");
+ assert_named_chunked_blob("e9671e138a780833cb689753570fd10a55be84fb", "dummy.txt");
+ assert_named_chunked_blob("e9671e138a780833cb689753570fd10a55be84fb", "dummy.dunno");
+}
diff --git a/tests-clar/object/blob/write.c b/tests-clar/object/blob/write.c
index 722c7b956..203bc67c1 100644
--- a/tests-clar/object/blob/write.c
+++ b/tests-clar/object/blob/write.c
@@ -33,7 +33,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo
{
repo = cl_git_sandbox_init(WORKDIR);
- assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_fromfile);
+ assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_fromworkdir);
}
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
@@ -49,7 +49,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolut
assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
git_buf_free(&full_path);
- cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void)
@@ -65,5 +65,5 @@ void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_fi
assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
git_buf_free(&full_path);
- cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests-clar/object/commit/commitstagedfile.c b/tests-clar/object/commit/commitstagedfile.c
index a852458f4..9867ab418 100644
--- a/tests-clar/object/commit/commitstagedfile.c
+++ b/tests-clar/object/commit/commitstagedfile.c
@@ -13,16 +13,19 @@ void test_object_commit_commitstagedfile__initialize(void)
void test_object_commit_commitstagedfile__cleanup(void)
{
git_repository_free(repo);
+ repo = NULL;
+
cl_fixture_cleanup("treebuilder");
}
void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
{
git_index *index;
- git_index_entry *entry;
+ const git_index_entry *entry;
git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
git_signature *signature;
git_tree *tree;
+ char buffer[128];
/*
* The test below replicates the following git scenario
@@ -70,9 +73,9 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
*/
cl_git_mkfile("treebuilder/test.txt", "test\n");
cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_index_add(index, "test.txt", 0));
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
- entry = git_index_get(index, 0);
+ entry = git_index_get_byindex(index, 0);
cl_assert(git_oid_cmp(&expected_blob_oid, &entry->oid) == 0);
@@ -98,7 +101,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
/*
* Build the tree from the index
*/
- cl_git_pass(git_tree_create_fromindex(&tree_oid, index));
+ cl_git_pass(git_index_write_tree(&tree_oid, index));
cl_assert(git_oid_cmp(&expected_tree_oid, &tree_oid) == 0);
@@ -107,6 +110,9 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
*/
cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
+
+ cl_assert_equal_i(16, git_message_prettify(buffer, 128, "Initial commit", 0));
+
cl_git_pass(git_commit_create_v(
&commit_oid,
repo,
@@ -114,7 +120,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
signature,
signature,
NULL,
- "Initial commit",
+ buffer,
tree,
0));
diff --git a/tests-clar/object/lookup.c b/tests-clar/object/lookup.c
index 7cbcc6140..cfa6d4678 100644
--- a/tests-clar/object/lookup.c
+++ b/tests-clar/object/lookup.c
@@ -11,7 +11,8 @@ void test_object_lookup__initialize(void)
void test_object_lookup__cleanup(void)
{
- git_repository_free(g_repo);
+ git_repository_free(g_repo);
+ g_repo = NULL;
}
void test_object_lookup__lookup_wrong_type_returns_enotfound(void)
@@ -61,3 +62,4 @@ void test_object_lookup__lookup_wrong_type_eventually_returns_enotfound(void)
cl_assert_equal_i(
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_TAG));
}
+
diff --git a/tests-clar/object/message.c b/tests-clar/object/message.c
index cbdc80a64..7ef6374b3 100644
--- a/tests-clar/object/message.c
+++ b/tests-clar/object/message.c
@@ -6,7 +6,7 @@ static void assert_message_prettifying(char *expected_output, char *input, int s
{
git_buf prettified_message = GIT_BUF_INIT;
- git_message_prettify(&prettified_message, input, strip_comments);
+ git_message__prettify(&prettified_message, input, strip_comments);
cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message));
git_buf_free(&prettified_message);
@@ -169,3 +169,68 @@ void test_object_message__keep_comments(void)
assert_message_prettifying("# comment\n" ttt "\n", "# comment\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n" "# comment\n" ttt "\n", ttt "\n" "# comment\n" ttt "\n", 0);
}
+
+void test_object_message__message_prettify(void)
+{
+ char buffer[100];
+
+ cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 0) == 1);
+ cl_assert_equal_s(buffer, "");
+ cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 1) == 1);
+ cl_assert_equal_s(buffer, "");
+
+ cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 0));
+ cl_assert_equal_s("Short\n", buffer);
+ cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 1));
+ cl_assert_equal_s("Short\n", buffer);
+
+ cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 0) > 0);
+ cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n# with some comments still in\n");
+
+ cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 1) > 0);
+ cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n");
+
+ /* try out overflow */
+ cl_assert(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "12345678",
+ 0) > 0);
+ cl_assert_equal_s(buffer,
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
+
+ cl_assert(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "12345678\n",
+ 0) > 0);
+ cl_assert_equal_s(buffer,
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
+
+ cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "123456789",
+ 0));
+ cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "123456789\n",
+ 0));
+ cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890",
+ 0));
+ cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890""x",
+ 0));
+
+ cl_assert(git_message_prettify(buffer, sizeof(buffer),
+ "1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
+ "# 1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
+ "1234567890",
+ 1) > 0);
+
+ cl_assert(git_message_prettify(NULL, 0, "", 0) == 1);
+ cl_assert(git_message_prettify(NULL, 0, "Short test", 0) == 12);
+ cl_assert(git_message_prettify(NULL, 0, "Test\n# with\nComments", 1) == 15);
+}
diff --git a/tests-clar/object/peel.c b/tests-clar/object/peel.c
new file mode 100644
index 000000000..bb0bbd096
--- /dev/null
+++ b/tests-clar/object/peel.c
@@ -0,0 +1,110 @@
+#include "clar_libgit2.h"
+
+static git_repository *g_repo;
+
+void test_object_peel__initialize(void)
+{
+ cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
+}
+
+void test_object_peel__cleanup(void)
+{
+ git_repository_free(g_repo);
+ g_repo = NULL;
+}
+
+static void assert_peel(
+ const char *sha,
+ git_otype requested_type,
+ const char* expected_sha,
+ git_otype expected_type)
+{
+ git_oid oid, expected_oid;
+ git_object *obj;
+ git_object *peeled;
+
+ cl_git_pass(git_oid_fromstr(&oid, sha));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ cl_git_pass(git_object_peel(&peeled, obj, requested_type));
+
+ cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha));
+ cl_assert_equal_i(0, git_oid_cmp(&expected_oid, git_object_id(peeled)));
+
+ cl_assert_equal_i(expected_type, git_object_type(peeled));
+
+ git_object_free(peeled);
+ git_object_free(obj);
+}
+
+static void assert_peel_error(int error, const char *sha, git_otype requested_type)
+{
+ git_oid oid;
+ git_object *obj;
+ git_object *peeled;
+
+ cl_git_pass(git_oid_fromstr(&oid, sha));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ cl_assert_equal_i(error, git_object_peel(&peeled, obj, requested_type));
+
+ git_object_free(obj);
+}
+
+void test_object_peel__peeling_an_object_into_its_own_type_returns_another_instance_of_it(void)
+{
+ assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT,
+ "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT);
+ assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJ_TAG,
+ "7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJ_TAG);
+ assert_peel("53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_TREE,
+ "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_TREE);
+ assert_peel("0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJ_BLOB,
+ "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJ_BLOB);
+}
+
+void test_object_peel__can_peel_a_tag(void)
+{
+ assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJ_COMMIT,
+ "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT);
+ assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJ_TREE,
+ "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_TREE);
+}
+
+void test_object_peel__can_peel_a_commit(void)
+{
+ assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_TREE,
+ "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_TREE);
+}
+
+void test_object_peel__cannot_peel_a_tree(void)
+{
+ assert_peel_error(GIT_EAMBIGUOUS, "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_BLOB);
+}
+
+void test_object_peel__cannot_peel_a_blob(void)
+{
+ assert_peel_error(GIT_ENOTFOUND, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJ_COMMIT);
+}
+
+void test_object_peel__target_any_object_for_type_change(void)
+{
+ /* tag to commit */
+ assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJ_ANY,
+ "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT);
+
+ /* commit to tree */
+ assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_ANY,
+ "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_TREE);
+
+ /* fail to peel tree */
+ assert_peel_error(GIT_EAMBIGUOUS, "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_ANY);
+
+ /* fail to peel blob */
+ assert_peel_error(GIT_ENOTFOUND, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJ_ANY);
+}
+
+void test_object_peel__should_use_a_well_known_type(void)
+{
+ assert_peel_error(GIT_EINVALIDSPEC, "7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJ__EXT2);
+}
diff --git a/tests-clar/object/raw/convert.c b/tests-clar/object/raw/convert.c
index 7f310ddf0..74442c153 100644
--- a/tests-clar/object/raw/convert.c
+++ b/tests-clar/object/raw/convert.c
@@ -21,9 +21,9 @@ void test_object_raw_convert__succeed_on_oid_to_string_conversion(void)
str = git_oid_tostr(out, 0, &in);
cl_assert(str && *str == '\0' && str != out);
- /* NULL oid pointer, returns static empty string */
+ /* NULL oid pointer, sets existing buffer to empty string */
str = git_oid_tostr(out, sizeof(out), NULL);
- cl_assert(str && *str == '\0' && str != out);
+ cl_assert(str && *str == '\0' && str == out);
/* n == 1, returns out as an empty string */
str = git_oid_tostr(out, 1, &in);
diff --git a/tests-clar/object/raw/hash.c b/tests-clar/object/raw/hash.c
index 4b8b1b74c..ede31e145 100644
--- a/tests-clar/object/raw/hash.c
+++ b/tests-clar/object/raw/hash.c
@@ -8,11 +8,11 @@
static void hash_object_pass(git_oid *oid, git_rawobj *obj)
{
- cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
+ cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static void hash_object_fail(git_oid *oid, git_rawobj *obj)
{
- cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
+ cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
@@ -23,144 +23,144 @@ static char *bye_text = "bye world\n";
void test_object_raw_hash__hash_by_blocks(void)
{
- git_hash_ctx *ctx;
- git_oid id1, id2;
+ git_hash_ctx ctx;
+ git_oid id1, id2;
- cl_assert((ctx = git_hash_new_ctx()) != NULL);
+ cl_git_pass(git_hash_ctx_init(&ctx));
/* should already be init'd */
- git_hash_update(ctx, hello_text, strlen(hello_text));
- git_hash_final(&id2, ctx);
- cl_git_pass(git_oid_fromstr(&id1, hello_id));
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
+ cl_git_pass(git_hash_final(&id2, &ctx));
+ cl_git_pass(git_oid_fromstr(&id1, hello_id));
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
- git_hash_init(ctx);
- git_hash_update(ctx, bye_text, strlen(bye_text));
- git_hash_final(&id2, ctx);
- cl_git_pass(git_oid_fromstr(&id1, bye_id));
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_hash_init(&ctx));
+ cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
+ cl_git_pass(git_hash_final(&id2, &ctx));
+ cl_git_pass(git_oid_fromstr(&id1, bye_id));
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
- git_hash_free_ctx(ctx);
+ git_hash_ctx_cleanup(&ctx);
}
void test_object_raw_hash__hash_buffer_in_single_call(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, hello_id));
- git_hash_buf(&id2, hello_text, strlen(hello_text));
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, hello_id));
+ git_hash_buf(&id2, hello_text, strlen(hello_text));
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_vector(void)
{
- git_oid id1, id2;
- git_buf_vec vec[2];
+ git_oid id1, id2;
+ git_buf_vec vec[2];
- cl_git_pass(git_oid_fromstr(&id1, hello_id));
+ cl_git_pass(git_oid_fromstr(&id1, hello_id));
- vec[0].data = hello_text;
- vec[0].len = 4;
- vec[1].data = hello_text+4;
- vec[1].len = strlen(hello_text)-4;
+ vec[0].data = hello_text;
+ vec[0].len = 4;
+ vec[1].data = hello_text+4;
+ vec[1].len = strlen(hello_text)-4;
- git_hash_vec(&id2, vec, 2);
+ git_hash_vec(&id2, vec, 2);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_junk_data(void)
{
- git_oid id, id_zero;
+ git_oid id, id_zero;
- cl_git_pass(git_oid_fromstr(&id_zero, zero_id));
+ cl_git_pass(git_oid_fromstr(&id_zero, zero_id));
- /* invalid types: */
- junk_obj.data = some_data;
- hash_object_fail(&id, &junk_obj);
+ /* invalid types: */
+ junk_obj.data = some_data;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ__EXT1;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ__EXT1;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ__EXT2;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ__EXT2;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ_OFS_DELTA;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ_OFS_DELTA;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ_REF_DELTA;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ_REF_DELTA;
+ hash_object_fail(&id, &junk_obj);
- /* data can be NULL only if len is zero: */
- junk_obj.type = GIT_OBJ_BLOB;
- junk_obj.data = NULL;
- hash_object_pass(&id, &junk_obj);
- cl_assert(git_oid_cmp(&id, &id_zero) == 0);
+ /* data can be NULL only if len is zero: */
+ junk_obj.type = GIT_OBJ_BLOB;
+ junk_obj.data = NULL;
+ hash_object_pass(&id, &junk_obj);
+ cl_assert(git_oid_cmp(&id, &id_zero) == 0);
- junk_obj.len = 1;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.len = 1;
+ hash_object_fail(&id, &junk_obj);
}
void test_object_raw_hash__hash_commit_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, commit_id));
- hash_object_pass(&id2, &commit_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, commit_id));
+ hash_object_pass(&id2, &commit_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tree_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, tree_id));
- hash_object_pass(&id2, &tree_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, tree_id));
+ hash_object_pass(&id2, &tree_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tag_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, tag_id));
- hash_object_pass(&id2, &tag_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, tag_id));
+ hash_object_pass(&id2, &tag_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_zero_length_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, zero_id));
- hash_object_pass(&id2, &zero_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, zero_id));
+ hash_object_pass(&id2, &zero_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_one_byte_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, one_id));
- hash_object_pass(&id2, &one_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, one_id));
+ hash_object_pass(&id2, &one_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_two_byte_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, two_id));
- hash_object_pass(&id2, &two_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, two_id));
+ hash_object_pass(&id2, &two_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_multi_byte_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, some_id));
- hash_object_pass(&id2, &some_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, some_id));
+ hash_object_pass(&id2, &some_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
diff --git a/tests-clar/object/raw/short.c b/tests-clar/object/raw/short.c
index 14b1ae219..93c79b6a5 100644
--- a/tests-clar/object/raw/short.c
+++ b/tests-clar/object/raw/short.c
@@ -43,7 +43,7 @@ void test_object_raw_short__oid_shortener_stresstest_git_oid_shorten(void)
for (i = 0; i < MAX_OIDS; ++i) {
char *oid_text;
- sprintf(number_buffer, "%u", (unsigned int)i);
+ p_snprintf(number_buffer, 16, "%u", (unsigned int)i);
git_hash_buf(&oid, number_buffer, strlen(number_buffer));
oid_text = git__malloc(GIT_OID_HEXSZ + 1);
diff --git a/tests-clar/object/tag/list.c b/tests-clar/object/tag/list.c
new file mode 100644
index 000000000..6d5a24347
--- /dev/null
+++ b/tests-clar/object/tag/list.c
@@ -0,0 +1,115 @@
+#include "clar_libgit2.h"
+
+#include "tag.h"
+
+static git_repository *g_repo;
+
+#define MAX_USED_TAGS 6
+
+struct pattern_match_t
+{
+ const char* pattern;
+ const size_t expected_matches;
+ const char* expected_results[MAX_USED_TAGS];
+};
+
+// Helpers
+static void ensure_tag_pattern_match(git_repository *repo,
+ const struct pattern_match_t* data)
+{
+ int already_found[MAX_USED_TAGS] = { 0 };
+ git_strarray tag_list;
+ int error = 0;
+ size_t sucessfully_found = 0;
+ size_t i, j;
+
+ cl_assert(data->expected_matches <= MAX_USED_TAGS);
+
+ if ((error = git_tag_list_match(&tag_list, data->pattern, repo)) < 0)
+ goto exit;
+
+ if (tag_list.count != data->expected_matches)
+ {
+ error = GIT_ERROR;
+ goto exit;
+ }
+
+ // we have to be prepared that tags come in any order.
+ for (i = 0; i < tag_list.count; i++)
+ {
+ for (j = 0; j < data->expected_matches; j++)
+ {
+ if (!already_found[j] && !strcmp(data->expected_results[j], tag_list.strings[i]))
+ {
+ already_found[j] = 1;
+ sucessfully_found++;
+ break;
+ }
+ }
+ }
+ cl_assert_equal_i((int)sucessfully_found, (int)data->expected_matches);
+
+exit:
+ git_strarray_free(&tag_list);
+ cl_git_pass(error);
+}
+
+// Fixture setup and teardown
+void test_object_tag_list__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_object_tag_list__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_object_tag_list__list_all(void)
+{
+ // list all tag names from the repository
+ git_strarray tag_list;
+
+ cl_git_pass(git_tag_list(&tag_list, g_repo));
+
+ cl_assert_equal_i((int)tag_list.count, 6);
+
+ git_strarray_free(&tag_list);
+}
+
+static const struct pattern_match_t matches[] = {
+ // All tags, including a packed one and two namespaced ones.
+ { "", 6, { "e90810b", "point_to_blob", "test", "packed-tag", "foo/bar", "foo/foo/bar" } },
+
+ // beginning with
+ { "t*", 1, { "test" } },
+
+ // ending with
+ { "*b", 2, { "e90810b", "point_to_blob" } },
+
+ // exact match
+ { "e", 0 },
+ { "e90810b", 1, { "e90810b" } },
+
+ // either or
+ { "e90810[ab]", 1, { "e90810b" } },
+
+ // glob in the middle
+ { "foo/*/bar", 1, { "foo/foo/bar" } },
+
+ // The matching of '*' is based on plain string matching analog to the regular expression ".*"
+ // => a '/' in the tag name has no special meaning.
+ // Compare to `git tag -l "*bar"`
+ { "*bar", 2, { "foo/bar", "foo/foo/bar" } },
+
+ // End of list
+ { NULL }
+};
+
+void test_object_tag_list__list_by_pattern(void)
+{
+ // list all tag names from the repository matching a specified pattern
+ size_t i = 0;
+ while (matches[i].pattern)
+ ensure_tag_pattern_match(g_repo, &matches[i++]);
+}
diff --git a/tests-clar/object/tag/peel.c b/tests-clar/object/tag/peel.c
index 97c5a7dd3..e2cd8d6a8 100644
--- a/tests-clar/object/tag/peel.c
+++ b/tests-clar/object/tag/peel.c
@@ -14,8 +14,13 @@ void test_object_tag_peel__initialize(void)
void test_object_tag_peel__cleanup(void)
{
git_tag_free(tag);
+ tag = NULL;
+
git_object_free(target);
+ target = NULL;
+
git_repository_free(repo);
+ repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
diff --git a/tests-clar/object/tag/read.c b/tests-clar/object/tag/read.c
index 6a0ad8a23..c9787a413 100644
--- a/tests-clar/object/tag/read.c
+++ b/tests-clar/object/tag/read.c
@@ -7,124 +7,136 @@ static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
static const char *bad_tag_id = "eda9f45a2a98d4c17a09d681d88569fa4ea91755";
static const char *badly_tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
+static const char *short_tag_id = "5da7760512a953e3c7c4e47e4392c7a4338fb729";
+static const char *short_tagged_commit = "4a5ed60bafcf4638b7c8356bd4ce1916bfede93c";
+static const char *taggerless = "4a23e2e65ad4e31c4c9db7dc746650bfad082679";
static git_repository *g_repo;
-
-// Helpers
-static void ensure_tag_pattern_match(git_repository *repo,
- const char *pattern,
- const size_t expected_matches)
-{
- git_strarray tag_list;
- int error = 0;
-
- if ((error = git_tag_list_match(&tag_list, pattern, repo)) < 0)
- goto exit;
-
- if (tag_list.count != expected_matches)
- error = GIT_ERROR;
-
-exit:
- git_strarray_free(&tag_list);
- cl_git_pass(error);
-}
-
-
// Fixture setup and teardown
void test_object_tag_read__initialize(void)
{
- g_repo = cl_git_sandbox_init("testrepo");
+ g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tag_read__cleanup(void)
{
- cl_git_sandbox_cleanup();
+ cl_git_sandbox_cleanup();
}
void test_object_tag_read__parse(void)
{
- // read and parse a tag from the repository
- git_tag *tag1, *tag2;
- git_commit *commit;
- git_oid id1, id2, id_commit;
+ // read and parse a tag from the repository
+ git_tag *tag1, *tag2;
+ git_commit *commit;
+ git_oid id1, id2, id_commit;
- git_oid_fromstr(&id1, tag1_id);
- git_oid_fromstr(&id2, tag2_id);
- git_oid_fromstr(&id_commit, tagged_commit);
+ git_oid_fromstr(&id1, tag1_id);
+ git_oid_fromstr(&id2, tag2_id);
+ git_oid_fromstr(&id_commit, tagged_commit);
- cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
+ cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
- cl_assert_equal_s(git_tag_name(tag1), "test");
- cl_assert(git_tag_type(tag1) == GIT_OBJ_TAG);
+ cl_assert_equal_s(git_tag_name(tag1), "test");
+ cl_assert(git_tag_target_type(tag1) == GIT_OBJ_TAG);
- cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
- cl_assert(tag2 != NULL);
+ cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
+ cl_assert(tag2 != NULL);
- cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
+ cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
- cl_git_pass(git_tag_target((git_object **)&commit, tag2));
- cl_assert(commit != NULL);
+ cl_git_pass(git_tag_target((git_object **)&commit, tag2));
+ cl_assert(commit != NULL);
- cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+ cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
- git_tag_free(tag1);
- git_tag_free(tag2);
- git_commit_free(commit);
+ git_tag_free(tag1);
+ git_tag_free(tag2);
+ git_commit_free(commit);
}
-void test_object_tag_read__list(void)
+void test_object_tag_read__parse_without_tagger(void)
{
- // list all tag names from the repository
- git_strarray tag_list;
+ // read and parse a tag without a tagger field
+ git_repository *bad_tag_repo;
+ git_tag *bad_tag;
+ git_commit *commit;
+ git_oid id, id_commit;
+
+ // TODO: This is a little messy
+ cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
+
+ git_oid_fromstr(&id, bad_tag_id);
+ git_oid_fromstr(&id_commit, badly_tagged_commit);
+
+ cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
+ cl_assert(bad_tag != NULL);
- cl_git_pass(git_tag_list(&tag_list, g_repo));
+ cl_assert_equal_s(git_tag_name(bad_tag), "e90810b");
+ cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
+ cl_assert(bad_tag->tagger == NULL);
- cl_assert(tag_list.count == 3);
+ cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
+ cl_assert(commit != NULL);
- git_strarray_free(&tag_list);
+ cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+
+
+ git_tag_free(bad_tag);
+ git_commit_free(commit);
+ git_repository_free(bad_tag_repo);
}
-void test_object_tag_read__list_pattern(void)
+void test_object_tag_read__parse_without_message(void)
{
- // list all tag names from the repository matching a specified pattern
- ensure_tag_pattern_match(g_repo, "", 3);
- ensure_tag_pattern_match(g_repo, "*", 3);
- ensure_tag_pattern_match(g_repo, "t*", 1);
- ensure_tag_pattern_match(g_repo, "*b", 2);
- ensure_tag_pattern_match(g_repo, "e", 0);
- ensure_tag_pattern_match(g_repo, "e90810b", 1);
- ensure_tag_pattern_match(g_repo, "e90810[ab]", 1);
+ // read and parse a tag without a message field
+ git_repository *short_tag_repo;
+ git_tag *short_tag;
+ git_commit *commit;
+ git_oid id, id_commit;
+
+ // TODO: This is a little messy
+ cl_git_pass(git_repository_open(&short_tag_repo, cl_fixture("short_tag.git")));
+
+ git_oid_fromstr(&id, short_tag_id);
+ git_oid_fromstr(&id_commit, short_tagged_commit);
+
+ cl_git_pass(git_tag_lookup(&short_tag, short_tag_repo, &id));
+ cl_assert(short_tag != NULL);
+
+ cl_assert_equal_s(git_tag_name(short_tag), "no_description");
+ cl_assert(git_oid_cmp(&id, git_tag_id(short_tag)) == 0);
+ cl_assert(short_tag->message == NULL);
+
+ cl_git_pass(git_tag_target((git_object **)&commit, short_tag));
+ cl_assert(commit != NULL);
+
+ cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+
+ git_tag_free(short_tag);
+ git_commit_free(commit);
+ git_repository_free(short_tag_repo);
}
-void test_object_tag_read__parse_without_tagger(void)
+void test_object_tag_read__without_tagger_nor_message(void)
{
- // read and parse a tag without a tagger field
- git_repository *bad_tag_repo;
- git_tag *bad_tag;
- git_commit *commit;
- git_oid id, id_commit;
-
- // TODO: This is a little messy
- cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
+ git_tag *tag;
+ git_oid id;
+ git_repository *repo;
- git_oid_fromstr(&id, bad_tag_id);
- git_oid_fromstr(&id_commit, badly_tagged_commit);
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
- cl_assert(bad_tag != NULL);
+ cl_git_pass(git_oid_fromstr(&id, taggerless));
- cl_assert_equal_s(git_tag_name(bad_tag), "e90810b");
- cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
- cl_assert(bad_tag->tagger == NULL);
+ cl_git_pass(git_tag_lookup(&tag, repo, &id));
- cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
- cl_assert(commit != NULL);
+ cl_assert_equal_s(git_tag_name(tag), "taggerless");
+ cl_assert(git_tag_target_type(tag) == GIT_OBJ_COMMIT);
- cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+ cl_assert(tag->message == NULL);
+ cl_assert(tag->tagger == NULL);
- git_tag_free(bad_tag);
- git_commit_free(commit);
- git_repository_free(bad_tag_repo);
+ git_tag_free(tag);
+ git_repository_free(repo);
}
diff --git a/tests-clar/object/tag/write.c b/tests-clar/object/tag/write.c
index cb196b64e..cd69bea89 100644
--- a/tests-clar/object/tag/write.c
+++ b/tests-clar/object/tag/write.c
@@ -45,7 +45,7 @@ void test_object_tag_write__basic(void)
git_signature_free(tagger);
cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id));
- cl_assert(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0);
+ cl_assert(git_oid_cmp(git_tag_target_id(tag), &target_id) == 0);
/* Check attributes were set correctly */
tagger1 = git_tag_tagger(tag);
@@ -58,8 +58,9 @@ void test_object_tag_write__basic(void)
cl_assert_equal_s(git_tag_message(tag), tagger_message);
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag"));
- cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(ref_tag), &tag_id) == 0);
cl_git_pass(git_reference_delete(ref_tag));
+ git_reference_free(ref_tag);
git_tag_free(tag);
}
@@ -77,7 +78,7 @@ void test_object_tag_write__overwrite(void)
/* create signature */
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
- cl_git_fail(git_tag_create(
+ cl_assert_equal_i(GIT_EEXISTS, git_tag_create(
&tag_id, /* out id */
g_repo,
"e90810b",
@@ -88,7 +89,6 @@ void test_object_tag_write__overwrite(void)
git_object_free(target);
git_signature_free(tagger);
-
}
void test_object_tag_write__replace(void)
@@ -103,7 +103,7 @@ void test_object_tag_write__replace(void)
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
- git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag));
+ git_oid_cpy(&old_tag_id, git_reference_target(ref_tag));
git_reference_free(ref_tag);
/* create signature */
@@ -122,8 +122,8 @@ void test_object_tag_write__replace(void)
git_signature_free(tagger);
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
- cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
- cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &old_tag_id) != 0);
+ cl_assert(git_oid_cmp(git_reference_target(ref_tag), &tag_id) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(ref_tag), &old_tag_id) != 0);
git_reference_free(ref_tag);
}
@@ -150,7 +150,7 @@ void test_object_tag_write__lightweight(void)
cl_assert(git_oid_cmp(&object_id, &target_id) == 0);
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/light-tag"));
- cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &target_id) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(ref_tag), &target_id) == 0);
cl_git_pass(git_tag_delete(g_repo, "light-tag"));
@@ -166,7 +166,7 @@ void test_object_tag_write__lightweight_over_existing(void)
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
- cl_git_fail(git_tag_create_lightweight(
+ cl_assert_equal_i(GIT_EEXISTS, git_tag_create_lightweight(
&object_id,
g_repo,
"e90810b",
@@ -190,3 +190,33 @@ void test_object_tag_write__delete(void)
git_reference_free(ref_tag);
}
+
+void test_object_tag_write__creating_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ git_oid target_id, tag_id;
+ git_signature *tagger;
+ git_object *target;
+
+ git_oid_fromstr(&target_id, tagged_commit);
+ cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
+
+ cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_tag_create(&tag_id, g_repo,
+ "Inv@{id", target, tagger, tagger_message, 0)
+ );
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_tag_create_lightweight(&tag_id, g_repo,
+ "Inv@{id", target, 0)
+ );
+
+ git_object_free(target);
+ git_signature_free(tagger);
+}
+
+void test_object_tag_write__deleting_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_tag_delete(g_repo, "Inv@{id"));
+}
diff --git a/tests-clar/object/tree/attributes.c b/tests-clar/object/tree/attributes.c
new file mode 100644
index 000000000..cc93b45d2
--- /dev/null
+++ b/tests-clar/object/tree/attributes.c
@@ -0,0 +1,114 @@
+#include "clar_libgit2.h"
+#include "tree.h"
+
+static const char *blob_oid = "3d0970ec547fc41ef8a5882dde99c6adce65b021";
+static const char *tree_oid = "1b05fdaa881ee45b48cbaa5e9b037d667a47745e";
+
+void test_object_tree_attributes__ensure_correctness_of_attributes_on_insertion(void)
+{
+ git_treebuilder *builder;
+ git_oid oid;
+
+ cl_git_pass(git_oid_fromstr(&oid, blob_oid));
+
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "one.txt", &oid, (git_filemode_t)0777777));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "one.txt", &oid, (git_filemode_t)0100666));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "one.txt", &oid, (git_filemode_t)0000001));
+
+ git_treebuilder_free(builder);
+}
+
+void test_object_tree_attributes__group_writable_tree_entries_created_with_an_antique_git_version_can_still_be_accessed(void)
+{
+ git_repository *repo;
+ git_oid tid;
+ git_tree *tree;
+ const git_tree_entry *entry;
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("deprecated-mode.git")));
+
+ cl_git_pass(git_oid_fromstr(&tid, tree_oid));
+ cl_git_pass(git_tree_lookup(&tree, repo, &tid));
+
+ entry = git_tree_entry_byname(tree, "old_mode.txt");
+ cl_assert_equal_i(
+ GIT_FILEMODE_BLOB,
+ git_tree_entry_filemode(entry));
+
+ git_tree_free(tree);
+ git_repository_free(repo);
+}
+
+void test_object_tree_attributes__treebuilder_reject_invalid_filemode(void)
+{
+ git_treebuilder *builder;
+ git_oid bid;
+ const git_tree_entry *entry;
+
+ cl_git_pass(git_oid_fromstr(&bid, blob_oid));
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+
+ cl_git_fail(git_treebuilder_insert(
+ &entry,
+ builder,
+ "normalized.txt",
+ &bid,
+ GIT_FILEMODE_BLOB_GROUP_WRITABLE));
+
+ git_treebuilder_free(builder);
+}
+
+void test_object_tree_attributes__normalize_attributes_when_creating_a_tree_from_an_existing_one(void)
+{
+ git_repository *repo;
+ git_treebuilder *builder;
+ git_oid tid, tid2;
+ git_tree *tree;
+ const git_tree_entry *entry;
+
+ repo = cl_git_sandbox_init("deprecated-mode.git");
+
+ cl_git_pass(git_oid_fromstr(&tid, tree_oid));
+ cl_git_pass(git_tree_lookup(&tree, repo, &tid));
+
+ cl_git_pass(git_treebuilder_create(&builder, tree));
+
+ entry = git_treebuilder_get(builder, "old_mode.txt");
+ cl_assert_equal_i(
+ GIT_FILEMODE_BLOB,
+ git_tree_entry_filemode(entry));
+
+ cl_git_pass(git_treebuilder_write(&tid2, repo, builder));
+ git_treebuilder_free(builder);
+ git_tree_free(tree);
+
+ cl_git_pass(git_tree_lookup(&tree, repo, &tid2));
+ entry = git_tree_entry_byname(tree, "old_mode.txt");
+ cl_assert_equal_i(
+ GIT_FILEMODE_BLOB,
+ git_tree_entry_filemode(entry));
+
+ git_tree_free(tree);
+ cl_git_sandbox_cleanup();
+}
+
+void test_object_tree_attributes__normalize_600(void)
+{
+ git_oid id;
+ git_tree *tree;
+ git_repository *repo;
+ const git_tree_entry *entry;
+
+ repo = cl_git_sandbox_init("deprecated-mode.git");
+
+ git_oid_fromstr(&id, "0810fb7818088ff5ac41ee49199b51473b1bd6c7");
+ cl_git_pass(git_tree_lookup(&tree, repo, &id));
+
+ entry = git_tree_entry_byname(tree, "ListaTeste.xml");
+ cl_assert_equal_i(entry->attr, GIT_FILEMODE_BLOB);
+
+ git_tree_free(tree);
+ cl_git_sandbox_cleanup();
+}
diff --git a/tests-clar/object/tree/duplicateentries.c b/tests-clar/object/tree/duplicateentries.c
new file mode 100644
index 000000000..9262f9a1a
--- /dev/null
+++ b/tests-clar/object/tree/duplicateentries.c
@@ -0,0 +1,157 @@
+#include "clar_libgit2.h"
+#include "tree.h"
+
+static git_repository *_repo;
+
+void test_object_tree_duplicateentries__initialize(void) {
+ _repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_object_tree_duplicateentries__cleanup(void) {
+ cl_git_sandbox_cleanup();
+}
+
+/*
+ * $ git show --format=raw refs/heads/dir
+ * commit 144344043ba4d4a405da03de3844aa829ae8be0e
+ * tree d52a8fe84ceedf260afe4f0287bbfca04a117e83
+ * parent cf80f8de9f1185bf3a05f993f6121880dd0cfbc9
+ * author Ben Straub <bstraub@github.com> 1343755506 -0700
+ * committer Ben Straub <bstraub@github.com> 1343755506 -0700
+ *
+ * Change a file mode
+ *
+ * diff --git a/a/b.txt b/a/b.txt
+ * old mode 100644
+ * new mode 100755
+ *
+ * $ git ls-tree d52a8fe84ceedf260afe4f0287bbfca04a117e83
+ * 100644 blob a8233120f6ad708f843d861ce2b7228ec4e3dec6 README
+ * 040000 tree 4e0883eeeeebc1fb1735161cea82f7cb5fab7e63 a
+ * 100644 blob 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 branch_file.txt
+ * 100644 blob a71586c1dfe8a71c6cbf6c129f404c5642ff31bd new.txt
+ */
+
+static void tree_checker(
+ git_oid *tid,
+ const char *expected_sha,
+ git_filemode_t expected_filemode)
+{
+ git_tree *tree;
+ const git_tree_entry *entry;
+ git_oid oid;
+
+ cl_git_pass(git_tree_lookup(&tree, _repo, tid));
+ cl_assert_equal_i(1, (int)git_tree_entrycount(tree));
+ entry = git_tree_entry_byindex(tree, 0);
+
+ cl_git_pass(git_oid_fromstr(&oid, expected_sha));
+
+ cl_assert_equal_i(0, git_oid_cmp(&oid, git_tree_entry_id(entry)));
+ cl_assert_equal_i(expected_filemode, git_tree_entry_filemode(entry));
+
+ git_tree_free(tree);
+}
+
+static void tree_creator(git_oid *out, void (*fn)(git_treebuilder *))
+{
+ git_treebuilder *builder;
+
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+
+ fn(builder);
+
+ cl_git_pass(git_treebuilder_write(out, _repo, builder));
+ git_treebuilder_free(builder);
+}
+
+static void two_blobs(git_treebuilder *bld)
+{
+ git_oid oid;
+ const git_tree_entry *entry;
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */
+
+ cl_git_pass(git_treebuilder_insert(
+ &entry, bld, "duplicate", &oid,
+ GIT_FILEMODE_BLOB));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); /* blob oid (new.txt) */
+
+ cl_git_pass(git_treebuilder_insert(
+ &entry, bld, "duplicate", &oid,
+ GIT_FILEMODE_BLOB));
+}
+
+static void one_blob_and_one_tree(git_treebuilder *bld)
+{
+ git_oid oid;
+ const git_tree_entry *entry;
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */
+
+ cl_git_pass(git_treebuilder_insert(
+ &entry, bld, "duplicate", &oid,
+ GIT_FILEMODE_BLOB));
+
+ cl_git_pass(git_oid_fromstr(&oid,
+ "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63")); /* tree oid (a) */
+
+ cl_git_pass(git_treebuilder_insert(
+ &entry, bld, "duplicate", &oid,
+ GIT_FILEMODE_TREE));
+}
+
+void test_object_tree_duplicateentries__cannot_create_a_duplicate_entry_through_the_treebuilder(void)
+{
+ git_oid tid;
+
+ tree_creator(&tid, two_blobs);
+ tree_checker(&tid, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", GIT_FILEMODE_BLOB);
+
+ tree_creator(&tid, one_blob_and_one_tree);
+ tree_checker(&tid, "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63", GIT_FILEMODE_TREE);
+}
+
+static void add_fake_conflicts(git_index *index)
+{
+ git_index_entry ancestor_entry, our_entry, their_entry;
+
+ memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+ memset(&our_entry, 0x0, sizeof(git_index_entry));
+ memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+ ancestor_entry.path = "duplicate";
+ ancestor_entry.mode = GIT_FILEMODE_BLOB;
+ ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&ancestor_entry.oid, "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+
+ our_entry.path = "duplicate";
+ our_entry.mode = GIT_FILEMODE_BLOB;
+ ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&our_entry.oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
+
+ their_entry.path = "duplicate";
+ their_entry.mode = GIT_FILEMODE_BLOB;
+ ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
+ git_oid_fromstr(&their_entry.oid, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
+
+ cl_git_pass(git_index_conflict_add(index, &ancestor_entry, &our_entry, &their_entry));
+}
+
+void test_object_tree_duplicateentries__cannot_create_a_duplicate_entry_building_a_tree_from_a_index_with_conflicts(void)
+{
+ git_index *index;
+ git_oid tid;
+
+ cl_git_pass(git_repository_index(&index, _repo));
+
+ add_fake_conflicts(index);
+
+ cl_assert_equal_i(GIT_EUNMERGED, git_index_write_tree(&tid, index));
+
+ git_index_free(index);
+}
diff --git a/tests-clar/object/tree/frompath.c b/tests-clar/object/tree/frompath.c
index 06c69ac08..86ca47e94 100644
--- a/tests-clar/object/tree/frompath.c
+++ b/tests-clar/object/tree/frompath.c
@@ -1,15 +1,14 @@
#include "clar_libgit2.h"
static git_repository *repo;
-const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
static git_tree *tree;
void test_object_tree_frompath__initialize(void)
{
git_oid id;
+ const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_assert(repo != NULL);
cl_git_pass(git_oid_fromstr(&id, tree_with_subtrees_oid));
@@ -20,62 +19,50 @@ void test_object_tree_frompath__initialize(void)
void test_object_tree_frompath__cleanup(void)
{
git_tree_free(tree);
+ tree = NULL;
+
git_repository_free(repo);
- cl_fixture_cleanup("testrepo.git");
+ repo = NULL;
}
-static void assert_tree_from_path(git_tree *root, const char *path, int expected_result, const char *expected_raw_oid)
+static void assert_tree_from_path(
+ git_tree *root,
+ const char *path,
+ const char *expected_entry_name)
{
- git_tree *containing_tree = NULL;
-
- cl_assert(git_tree_get_subtree(&containing_tree, root, path) == expected_result);
-
- if (containing_tree == NULL && expected_result != 0)
- return;
-
- cl_assert(containing_tree != NULL && expected_result == 0);
-
- cl_git_pass(git_oid_streq(git_object_id((const git_object *)containing_tree), expected_raw_oid));
+ git_tree_entry *entry;
- git_tree_free(containing_tree);
-}
-
-static void assert_tree_from_path_klass(git_tree *root, const char *path, int expected_result, const char *expected_raw_oid)
-{
- assert_tree_from_path(root, path, GIT_ERROR, expected_raw_oid);
- cl_assert(giterr_last()->klass == expected_result);
+ cl_git_pass(git_tree_entry_bypath(&entry, root, path));
+ cl_assert_equal_s(git_tree_entry_name(entry), expected_entry_name);
+ git_tree_entry_free(entry);
}
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
{
- /* Will return self if given a one path segment... */
- assert_tree_from_path(tree, "README", 0, tree_with_subtrees_oid);
-
- /* ...even one that lead to a non existent tree entry. */
- assert_tree_from_path(tree, "i-do-not-exist.txt", 0, tree_with_subtrees_oid);
-
- /* Will return fgh tree oid given this following path... */
- assert_tree_from_path(tree, "ab/de/fgh/1.txt", 0, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
-
- /* ... and ab tree oid given this one. */
- assert_tree_from_path(tree, "ab/de", 0, "f1425cef211cc08caa31e7b545ffb232acb098c3");
+ git_tree_entry *e;
- /* Will succeed if given a valid path which leads to a tree entry which doesn't exist */
- assert_tree_from_path(tree, "ab/de/fgh/i-do-not-exist.txt", 0, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
-}
+ assert_tree_from_path(tree, "README", "README");
+ assert_tree_from_path(tree, "ab/de/fgh/1.txt", "1.txt");
+ assert_tree_from_path(tree, "ab/de/fgh", "fgh");
+ assert_tree_from_path(tree, "ab/de/fgh/", "fgh");
+ assert_tree_from_path(tree, "ab/de", "de");
+ assert_tree_from_path(tree, "ab/", "ab");
+ assert_tree_from_path(tree, "ab/de/", "de");
-void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void)
-{
- assert_tree_from_path(tree, "nope/de/fgh/1.txt", GIT_ENOTFOUND, NULL);
- assert_tree_from_path(tree, "ab/me-neither/fgh/2.txt", GIT_ENOTFOUND, NULL);
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "i-do-not-exist.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "README/"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/de/fgh/i-do-not-exist.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "nope/de/fgh/1.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/me-neither/fgh/2.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/me-neither/fgh/2.txt/"));
}
void test_object_tree_frompath__fail_when_processing_an_invalid_path(void)
{
- assert_tree_from_path_klass(tree, "/", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "/ab", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "/ab/de", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "ab/", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "ab//de", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "ab/de/", GITERR_INVALID, NULL);
+ git_tree_entry *e;
+
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "/"));
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "/ab"));
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "/ab/de"));
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "ab//de"));
}
diff --git a/tests-clar/object/tree/walk.c b/tests-clar/object/tree/walk.c
new file mode 100644
index 000000000..b7af4924d
--- /dev/null
+++ b/tests-clar/object/tree/walk.c
@@ -0,0 +1,103 @@
+#include "clar_libgit2.h"
+#include "tree.h"
+
+static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
+static git_repository *g_repo;
+
+void test_object_tree_walk__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_object_tree_walk__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static int treewalk_count_cb(
+ const char *root, const git_tree_entry *entry, void *payload)
+{
+ int *count = payload;
+
+ GIT_UNUSED(root);
+ GIT_UNUSED(entry);
+
+ (*count) += 1;
+
+ return 0;
+}
+
+void test_object_tree_walk__0(void)
+{
+ git_oid id;
+ git_tree *tree;
+ int ct;
+
+ git_oid_fromstr(&id, tree_oid);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
+
+ ct = 0;
+ cl_git_pass(git_tree_walk(tree, GIT_TREEWALK_PRE, treewalk_count_cb, &ct));
+ cl_assert_equal_i(3, ct);
+
+ ct = 0;
+ cl_git_pass(git_tree_walk(tree, GIT_TREEWALK_POST, treewalk_count_cb, &ct));
+ cl_assert_equal_i(3, ct);
+
+ git_tree_free(tree);
+}
+
+
+static int treewalk_stop_cb(
+ const char *root, const git_tree_entry *entry, void *payload)
+{
+ int *count = payload;
+
+ GIT_UNUSED(root);
+ GIT_UNUSED(entry);
+
+ (*count) += 1;
+
+ return (*count == 2) ? -1 : 0;
+}
+
+static int treewalk_stop_immediately_cb(
+ const char *root, const git_tree_entry *entry, void *payload)
+{
+ GIT_UNUSED(root);
+ GIT_UNUSED(entry);
+ GIT_UNUSED(payload);
+ return -100;
+}
+
+void test_object_tree_walk__1(void)
+{
+ git_oid id;
+ git_tree *tree;
+ int ct;
+
+ git_oid_fromstr(&id, tree_oid);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
+
+ ct = 0;
+ cl_assert_equal_i(
+ GIT_EUSER, git_tree_walk(tree, GIT_TREEWALK_PRE, treewalk_stop_cb, &ct));
+ cl_assert_equal_i(2, ct);
+
+ ct = 0;
+ cl_assert_equal_i(
+ GIT_EUSER, git_tree_walk(tree, GIT_TREEWALK_POST, treewalk_stop_cb, &ct));
+ cl_assert_equal_i(2, ct);
+
+ cl_assert_equal_i(
+ GIT_EUSER, git_tree_walk(
+ tree, GIT_TREEWALK_PRE, treewalk_stop_immediately_cb, NULL));
+
+ cl_assert_equal_i(
+ GIT_EUSER, git_tree_walk(
+ tree, GIT_TREEWALK_POST, treewalk_stop_immediately_cb, NULL));
+
+ git_tree_free(tree);
+}
diff --git a/tests-clar/object/tree/write.c b/tests-clar/object/tree/write.c
index 3911f6f0e..468c0ccd1 100644
--- a/tests-clar/object/tree/write.c
+++ b/tests-clar/object/tree/write.c
@@ -35,11 +35,22 @@ void test_object_tree_write__from_memory(void)
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_create(&builder, tree));
- cl_git_fail(git_treebuilder_insert(NULL, builder, "", &bid, 0100644));
- cl_git_fail(git_treebuilder_insert(NULL, builder, "/", &bid, 0100644));
- cl_git_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt", &bid, 0100644));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "",
+ &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "/",
+ &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, ".git",
+ &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "..",
+ &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, ".",
+ &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt",
+ &bid, GIT_FILEMODE_BLOB));
+
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "new.txt", &bid, GIT_FILEMODE_BLOB));
- cl_git_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
cl_git_pass(git_treebuilder_write(&rid, g_repo, builder));
cl_assert(git_oid_cmp(&rid, &id2) == 0);
@@ -63,14 +74,16 @@ void test_object_tree_write__subtree(void)
//create subtree
cl_git_pass(git_treebuilder_create(&builder, NULL));
- cl_git_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "new.txt", &bid, GIT_FILEMODE_BLOB)); //-V536
cl_git_pass(git_treebuilder_write(&subtree_id, g_repo, builder));
git_treebuilder_free(builder);
// create parent tree
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_create(&builder, tree));
- cl_git_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000));
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "new", &subtree_id, GIT_FILEMODE_TREE)); //-V536
cl_git_pass(git_treebuilder_write(&id_hiearar, g_repo, builder));
git_treebuilder_free(builder);
git_tree_free(tree);
@@ -82,3 +95,168 @@ void test_object_tree_write__subtree(void)
cl_assert(2 == git_tree_entrycount(tree));
git_tree_free(tree);
}
+
+/*
+ * And the Lord said: Is this tree properly sorted?
+ */
+void test_object_tree_write__sorted_subtrees(void)
+{
+ git_treebuilder *builder;
+ unsigned int i;
+ int position_c = -1, position_cake = -1, position_config = -1;
+
+ struct {
+ unsigned int attr;
+ const char *filename;
+ } entries[] = {
+ { GIT_FILEMODE_BLOB, ".gitattributes" },
+ { GIT_FILEMODE_BLOB, ".gitignore" },
+ { GIT_FILEMODE_BLOB, ".htaccess" },
+ { GIT_FILEMODE_BLOB, "Capfile" },
+ { GIT_FILEMODE_BLOB, "Makefile"},
+ { GIT_FILEMODE_BLOB, "README"},
+ { GIT_FILEMODE_TREE, "app"},
+ { GIT_FILEMODE_TREE, "cake"},
+ { GIT_FILEMODE_TREE, "config"},
+ { GIT_FILEMODE_BLOB, "c"},
+ { GIT_FILEMODE_BLOB, "git_test.txt"},
+ { GIT_FILEMODE_BLOB, "htaccess.htaccess"},
+ { GIT_FILEMODE_BLOB, "index.php"},
+ { GIT_FILEMODE_TREE, "plugins"},
+ { GIT_FILEMODE_TREE, "schemas"},
+ { GIT_FILEMODE_TREE, "ssl-certs"},
+ { GIT_FILEMODE_TREE, "vendors"}
+ };
+
+ git_oid blank_oid, tree_oid;
+
+ memset(&blank_oid, 0x0, sizeof(blank_oid));
+
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+
+ for (i = 0; i < ARRAY_SIZE(entries); ++i) {
+ cl_git_pass(git_treebuilder_insert(NULL,
+ builder, entries[i].filename, &blank_oid, entries[i].attr));
+ }
+
+ cl_git_pass(git_treebuilder_write(&tree_oid, g_repo, builder));
+
+ for (i = 0; i < builder->entries.length; ++i) {
+ git_tree_entry *entry = git_vector_get(&builder->entries, i);
+
+ if (strcmp(entry->filename, "c") == 0)
+ position_c = i;
+
+ if (strcmp(entry->filename, "cake") == 0)
+ position_cake = i;
+
+ if (strcmp(entry->filename, "config") == 0)
+ position_config = i;
+ }
+
+ cl_assert(position_c != -1);
+ cl_assert(position_cake != -1);
+ cl_assert(position_config != -1);
+
+ cl_assert(position_c < position_cake);
+ cl_assert(position_cake < position_config);
+
+ git_treebuilder_free(builder);
+}
+
+void test_object_tree_write__removing_and_re_adding_in_treebuilder(void)
+{
+ git_treebuilder *builder;
+ int i, aardvark_i, apple_i, apple_after_i, apple_extra_i, last_i;
+ git_oid blank_oid, tree_oid;
+ git_tree *tree;
+ struct {
+ unsigned int attr;
+ const char *filename;
+ } entries[] = {
+ { GIT_FILEMODE_BLOB, "aardvark" },
+ { GIT_FILEMODE_BLOB, ".first" },
+ { GIT_FILEMODE_BLOB, "apple" },
+ { GIT_FILEMODE_BLOB, "last"},
+ { GIT_FILEMODE_BLOB, "apple_after"},
+ { GIT_FILEMODE_BLOB, "after_aardvark"},
+ { 0, NULL },
+ };
+
+ memset(&blank_oid, 0x0, sizeof(blank_oid));
+
+ cl_git_pass(git_treebuilder_create(&builder, NULL));
+
+ cl_assert_equal_i(0, (int)git_treebuilder_entrycount(builder));
+
+ for (i = 0; entries[i].filename; ++i)
+ cl_git_pass(git_treebuilder_insert(NULL,
+ builder, entries[i].filename, &blank_oid, entries[i].attr));
+
+ cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
+
+ cl_git_pass(git_treebuilder_remove(builder, "apple"));
+ cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
+
+ cl_git_pass(git_treebuilder_remove(builder, "apple_after"));
+ cl_assert_equal_i(4, (int)git_treebuilder_entrycount(builder));
+
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "before_last", &blank_oid, GIT_FILEMODE_BLOB));
+ cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
+
+ /* reinsert apple_after */
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "apple_after", &blank_oid, GIT_FILEMODE_BLOB));
+ cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
+
+ cl_git_pass(git_treebuilder_remove(builder, "last"));
+ cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
+
+ /* reinsert last */
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "last", &blank_oid, GIT_FILEMODE_BLOB));
+ cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
+
+ cl_git_pass(git_treebuilder_insert(
+ NULL, builder, "apple_extra", &blank_oid, GIT_FILEMODE_BLOB));
+ cl_assert_equal_i(7, (int)git_treebuilder_entrycount(builder));
+
+ cl_git_pass(git_treebuilder_write(&tree_oid, g_repo, builder));
+
+ git_treebuilder_free(builder);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));
+
+ cl_assert_equal_i(7, (int)git_tree_entrycount(tree));
+
+ cl_assert(git_tree_entry_byname(tree, ".first") != NULL);
+ cl_assert(git_tree_entry_byname(tree, "apple") == NULL);
+ cl_assert(git_tree_entry_byname(tree, "apple_after") != NULL);
+ cl_assert(git_tree_entry_byname(tree, "apple_extra") != NULL);
+ cl_assert(git_tree_entry_byname(tree, "last") != NULL);
+
+ aardvark_i = apple_i = apple_after_i = apple_extra_i = last_i = -1;
+
+ for (i = 0; i < 7; ++i) {
+ const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
+
+ if (!strcmp(entry->filename, "aardvark"))
+ aardvark_i = i;
+ else if (!strcmp(entry->filename, "apple"))
+ apple_i = i;
+ else if (!strcmp(entry->filename, "apple_after"))
+ apple_after_i = i;
+ else if (!strcmp(entry->filename, "apple_extra"))
+ apple_extra_i = i;
+ else if (!strcmp(entry->filename, "last"))
+ last_i = i;
+ }
+
+ cl_assert_equal_i(-1, apple_i);
+ cl_assert_equal_i(6, last_i);
+ cl_assert(aardvark_i < apple_after_i);
+ cl_assert(apple_after_i < apple_extra_i);
+
+ git_tree_free(tree);
+}
diff --git a/tests-clar/odb/alternates.c b/tests-clar/odb/alternates.c
new file mode 100644
index 000000000..be7bfa9cd
--- /dev/null
+++ b/tests-clar/odb/alternates.c
@@ -0,0 +1,80 @@
+#include "clar_libgit2.h"
+#include "odb.h"
+#include "repository.h"
+
+static git_buf destpath, filepath;
+static const char *paths[] = {
+ "A.git", "B.git", "C.git", "D.git", "E.git", "F.git", "G.git"
+};
+static git_filebuf file;
+static git_repository *repo;
+
+void test_odb_alternates__cleanup(void)
+{
+ size_t i;
+
+ git_buf_free(&destpath);
+ git_buf_free(&filepath);
+
+ for (i = 0; i < ARRAY_SIZE(paths); i++)
+ cl_fixture_cleanup(paths[i]);
+}
+
+static void init_linked_repo(const char *path, const char *alternate)
+{
+ git_buf_clear(&destpath);
+ git_buf_clear(&filepath);
+
+ cl_git_pass(git_repository_init(&repo, path, 1));
+ cl_git_pass(git_path_prettify(&destpath, alternate, NULL));
+ cl_git_pass(git_buf_joinpath(&destpath, destpath.ptr, "objects"));
+ cl_git_pass(git_buf_joinpath(&filepath, git_repository_path(repo), "objects/info"));
+ cl_git_pass(git_futils_mkdir(filepath.ptr, NULL, 0755, GIT_MKDIR_PATH));
+ cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
+
+ cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0));
+ git_filebuf_printf(&file, "%s\n", git_buf_cstr(&destpath));
+ cl_git_pass(git_filebuf_commit(&file, 0644));
+
+ git_repository_free(repo);
+}
+
+void test_odb_alternates__chained(void)
+{
+ git_commit *commit;
+ git_oid oid;
+
+ /* Set the alternate A -> testrepo.git */
+ init_linked_repo(paths[0], cl_fixture("testrepo.git"));
+
+ /* Set the alternate B -> A */
+ init_linked_repo(paths[1], paths[0]);
+
+ /* Now load B and see if we can find an object from testrepo.git */
+ cl_git_pass(git_repository_open(&repo, paths[1]));
+ git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+ git_commit_free(commit);
+ git_repository_free(repo);
+}
+
+void test_odb_alternates__long_chain(void)
+{
+ git_commit *commit;
+ git_oid oid;
+ size_t i;
+
+ /* Set the alternate A -> testrepo.git */
+ init_linked_repo(paths[0], cl_fixture("testrepo.git"));
+
+ /* Set up the five-element chain */
+ for (i = 1; i < ARRAY_SIZE(paths); i++) {
+ init_linked_repo(paths[i], paths[i-1]);
+ }
+
+ /* Now load the last one and see if we can find an object from testrepo.git */
+ cl_git_pass(git_repository_open(&repo, paths[ARRAY_SIZE(paths)-1]));
+ git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ cl_git_fail(git_commit_lookup(&commit, repo, &oid));
+ git_repository_free(repo);
+}
diff --git a/tests-clar/odb/foreach.c b/tests-clar/odb/foreach.c
new file mode 100644
index 000000000..f643d9621
--- /dev/null
+++ b/tests-clar/odb/foreach.c
@@ -0,0 +1,80 @@
+#include "clar_libgit2.h"
+#include "odb.h"
+#include "git2/odb_backend.h"
+#include "pack.h"
+
+static git_odb *_odb;
+static git_repository *_repo;
+static int nobj;
+
+void test_odb_foreach__cleanup(void)
+{
+ git_odb_free(_odb);
+ git_repository_free(_repo);
+
+ _odb = NULL;
+ _repo = NULL;
+}
+
+static int foreach_cb(const git_oid *oid, void *data)
+{
+ GIT_UNUSED(data);
+ GIT_UNUSED(oid);
+
+ nobj++;
+
+ return 0;
+}
+
+/*
+ * $ git --git-dir tests-clar/resources/testrepo.git count-objects --verbose
+ * count: 47
+ * size: 4
+ * in-pack: 1640
+ * packs: 3
+ * size-pack: 425
+ * prune-packable: 0
+ * garbage: 0
+ */
+void test_odb_foreach__foreach(void)
+{
+ cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+ git_repository_odb(&_odb, _repo);
+
+ cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
+ cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */
+}
+
+void test_odb_foreach__one_pack(void)
+{
+ git_odb_backend *backend = NULL;
+
+ cl_git_pass(git_odb_new(&_odb));
+ cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
+ cl_git_pass(git_odb_add_backend(_odb, backend, 1));
+ _repo = NULL;
+
+ nobj = 0;
+ cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
+ cl_assert(nobj == 1628);
+}
+
+static int foreach_stop_cb(const git_oid *oid, void *data)
+{
+ GIT_UNUSED(data);
+ GIT_UNUSED(oid);
+
+ nobj++;
+
+ return (nobj == 1000);
+}
+
+void test_odb_foreach__interrupt_foreach(void)
+{
+ nobj = 0;
+ cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+ git_repository_odb(&_odb, _repo);
+
+ cl_assert_equal_i(GIT_EUSER, git_odb_foreach(_odb, foreach_stop_cb, NULL));
+ cl_assert(nobj == 1000);
+}
diff --git a/tests-clar/odb/mixed.c b/tests-clar/odb/mixed.c
index 0bd23e157..da0ed97d7 100644
--- a/tests-clar/odb/mixed.c
+++ b/tests-clar/odb/mixed.c
@@ -11,6 +11,7 @@ void test_odb_mixed__initialize(void)
void test_odb_mixed__cleanup(void)
{
git_odb_free(_odb);
+ _odb = NULL;
}
void test_odb_mixed__dup_oid(void) {
diff --git a/tests-clar/odb/pack_data_one.h b/tests-clar/odb/pack_data_one.h
new file mode 100644
index 000000000..13570ba78
--- /dev/null
+++ b/tests-clar/odb/pack_data_one.h
@@ -0,0 +1,19 @@
+/* Just a few to make sure it's working, the rest is tested already */
+static const char *packed_objects_one[] = {
+ "9fcf811e00fa469688943a9152c16d4ee90fb9a9",
+ "a93f42a5b5e9de40fa645a9ff1e276a021c9542b",
+ "12bf5f3e3470d90db177ccf1b5e8126409377fc6",
+ "ed1ea164cdbe3c4b200fb4fa19861ea90eaee222",
+ "dfae6ed8f6dd8acc3b40a31811ea316239223559",
+ "aefe66d192771201e369fde830530f4475beec30",
+ "775e4b4c1296e9e3104f2a36ca9cf9356a130959",
+ "412ec4e4a6a7419bc1be00561fe474e54cb499fe",
+ "236e7579fed7763be77209efb8708960982f3cb3",
+ "09fe9364461cf60dd1c46b0e9545b1e47bb1a297",
+ "d76d8a6390d1cf32138d98a91b1eb7e0275a12f5",
+ "d0fdf2dcff2f548952eec536ccc6d266550041bc",
+ "a20d733a9fa79fa5b4cbb9639864f93325ec27a6",
+ "785d3fe8e7db5ade2c2242fecd46c32a7f4dc59f",
+ "4d8d0fd9cb6045075385701c3f933ec13345e9c4",
+ "0cfd861bd547b6520d1fc2e190e8359e0a9c9b90"
+};
diff --git a/tests-clar/odb/packed.c b/tests-clar/odb/packed.c
index 4bce41ba0..90e9f3abd 100644
--- a/tests-clar/odb/packed.c
+++ b/tests-clar/odb/packed.c
@@ -12,6 +12,7 @@ void test_odb_packed__initialize(void)
void test_odb_packed__cleanup(void)
{
git_odb_free(_odb);
+ _odb = NULL;
}
void test_odb_packed__mass_read(void)
diff --git a/tests-clar/odb/packed_one.c b/tests-clar/odb/packed_one.c
new file mode 100644
index 000000000..e9d246c23
--- /dev/null
+++ b/tests-clar/odb/packed_one.c
@@ -0,0 +1,59 @@
+#include "clar_libgit2.h"
+#include "odb.h"
+#include "pack_data_one.h"
+#include "pack.h"
+
+static git_odb *_odb;
+
+void test_odb_packed_one__initialize(void)
+{
+ git_odb_backend *backend = NULL;
+
+ cl_git_pass(git_odb_new(&_odb));
+ cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
+ cl_git_pass(git_odb_add_backend(_odb, backend, 1));
+}
+
+void test_odb_packed_one__cleanup(void)
+{
+ git_odb_free(_odb);
+ _odb = NULL;
+}
+
+void test_odb_packed_one__mass_read(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(packed_objects_one); ++i) {
+ git_oid id;
+ git_odb_object *obj;
+
+ cl_git_pass(git_oid_fromstr(&id, packed_objects_one[i]));
+ cl_assert(git_odb_exists(_odb, &id) == 1);
+ cl_git_pass(git_odb_read(&obj, _odb, &id));
+
+ git_odb_object_free(obj);
+ }
+}
+
+void test_odb_packed_one__read_header_0(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(packed_objects_one); ++i) {
+ git_oid id;
+ git_odb_object *obj;
+ size_t len;
+ git_otype type;
+
+ cl_git_pass(git_oid_fromstr(&id, packed_objects_one[i]));
+
+ cl_git_pass(git_odb_read(&obj, _odb, &id));
+ cl_git_pass(git_odb_read_header(&len, &type, _odb, &id));
+
+ cl_assert(obj->raw.len == len);
+ cl_assert(obj->raw.type == type);
+
+ git_odb_object_free(obj);
+ }
+}
diff --git a/tests-clar/odb/sorting.c b/tests-clar/odb/sorting.c
index bf64f6af4..b4f9e44bc 100644
--- a/tests-clar/odb/sorting.c
+++ b/tests-clar/odb/sorting.c
@@ -11,11 +11,11 @@ static git_odb_backend *new_backend(int position)
{
fake_backend *b;
- b = git__malloc(sizeof(fake_backend));
+ b = git__calloc(1, sizeof(fake_backend));
if (b == NULL)
return NULL;
- memset(b, 0x0, sizeof(fake_backend));
+ b->base.version = GIT_ODB_BACKEND_VERSION;
b->position = position;
return (git_odb_backend *)b;
}
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
new file mode 100644
index 000000000..c1a9a9a88
--- /dev/null
+++ b/tests-clar/online/clone.c
@@ -0,0 +1,200 @@
+#include "clar_libgit2.h"
+
+#include "git2/clone.h"
+#include "git2/cred_helpers.h"
+#include "repository.h"
+
+#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
+#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
+#define BB_REPO_URL "https://libgit2@bitbucket.org/libgit2/testgitrepository.git"
+#define BB_REPO_URL_WITH_PASS "https://libgit2:libgit2@bitbucket.org/libgit2/testgitrepository.git"
+#define BB_REPO_URL_WITH_WRONG_PASS "https://libgit2:wrong@bitbucket.org/libgit2/testgitrepository.git"
+
+static git_repository *g_repo;
+static git_clone_options g_options;
+
+void test_online_clone__initialize(void)
+{
+ git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
+
+ g_repo = NULL;
+
+ memset(&g_options, 0, sizeof(git_clone_options));
+ g_options.version = GIT_CLONE_OPTIONS_VERSION;
+ g_options.checkout_opts = dummy_opts;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+}
+
+void test_online_clone__cleanup(void)
+{
+ if (g_repo) {
+ git_repository_free(g_repo);
+ g_repo = NULL;
+ }
+ cl_fixture_cleanup("./foo");
+}
+
+void test_online_clone__network_full(void)
+{
+ git_remote *origin;
+
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
+ cl_assert(!git_repository_is_bare(g_repo));
+ cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
+
+ git_remote_free(origin);
+}
+
+void test_online_clone__network_bare(void)
+{
+ git_remote *origin;
+
+ g_options.bare = true;
+
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
+ cl_assert(git_repository_is_bare(g_repo));
+ cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
+
+ git_remote_free(origin);
+}
+
+void test_online_clone__empty_repository(void)
+{
+ git_reference *head;
+
+ cl_git_pass(git_clone(&g_repo, LIVE_EMPTYREPO_URL, "./foo", &g_options));
+
+ cl_assert_equal_i(true, git_repository_is_empty(g_repo));
+ cl_assert_equal_i(true, git_repository_head_orphan(g_repo));
+
+ cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
+ cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
+
+ git_reference_free(head);
+}
+
+static void checkout_progress(const char *path, size_t cur, size_t tot, void *payload)
+{
+ bool *was_called = (bool*)payload;
+ GIT_UNUSED(path); GIT_UNUSED(cur); GIT_UNUSED(tot);
+ (*was_called) = true;
+}
+
+static int fetch_progress(const git_transfer_progress *stats, void *payload)
+{
+ bool *was_called = (bool*)payload;
+ GIT_UNUSED(stats);
+ (*was_called) = true;
+ return 0;
+}
+
+void test_online_clone__can_checkout_a_cloned_repo(void)
+{
+ git_buf path = GIT_BUF_INIT;
+ git_reference *head;
+ bool checkout_progress_cb_was_called = false,
+ fetch_progress_cb_was_called = false;
+
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_options.checkout_opts.progress_cb = &checkout_progress;
+ g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
+ g_options.fetch_progress_cb = &fetch_progress;
+ g_options.fetch_progress_payload = &fetch_progress_cb_was_called;
+
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
+ cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path)));
+
+ cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
+ cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
+ cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
+
+ cl_assert_equal_i(true, checkout_progress_cb_was_called);
+ cl_assert_equal_i(true, fetch_progress_cb_was_called);
+
+ git_reference_free(head);
+ git_buf_free(&path);
+}
+
+static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *payload)
+{
+ int *callcount = (int*)payload;
+ GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b);
+ *callcount = *callcount + 1;
+ return 0;
+}
+
+void test_online_clone__custom_remote_callbacks(void)
+{
+ git_remote_callbacks remote_callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ int callcount = 0;
+
+ g_options.remote_callbacks = &remote_callbacks;
+ remote_callbacks.update_tips = update_tips;
+ remote_callbacks.payload = &callcount;
+
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
+ cl_assert(callcount > 0);
+}
+
+void test_online_clone__credentials(void)
+{
+ /* Remote URL environment variable must be set. User and password are optional. */
+ const char *remote_url = cl_getenv("GITTEST_REMOTE_URL");
+ git_cred_userpass_payload user_pass = {
+ cl_getenv("GITTEST_REMOTE_USER"),
+ cl_getenv("GITTEST_REMOTE_PASS")
+ };
+
+ if (!remote_url) return;
+
+ g_options.cred_acquire_cb = git_cred_userpass;
+ g_options.cred_acquire_payload = &user_pass;
+
+ cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
+ git_repository_free(g_repo); g_repo = NULL;
+ cl_fixture_cleanup("./foo");
+}
+
+void test_online_clone__bitbucket_style(void)
+{
+ git_cred_userpass_payload user_pass = {
+ "libgit2", "libgit2"
+ };
+
+ g_options.cred_acquire_cb = git_cred_userpass;
+ g_options.cred_acquire_payload = &user_pass;
+
+ cl_git_pass(git_clone(&g_repo, BB_REPO_URL, "./foo", &g_options));
+ git_repository_free(g_repo); g_repo = NULL;
+ cl_fixture_cleanup("./foo");
+
+ /* User and pass from URL */
+ user_pass.password = "wrong";
+ cl_git_pass(git_clone(&g_repo, BB_REPO_URL_WITH_PASS, "./foo", &g_options));
+ git_repository_free(g_repo); g_repo = NULL;
+ cl_fixture_cleanup("./foo");
+
+ /* Wrong password in URL, fall back to user_pass */
+ user_pass.password = "libgit2";
+ cl_git_pass(git_clone(&g_repo, BB_REPO_URL_WITH_WRONG_PASS, "./foo", &g_options));
+ git_repository_free(g_repo); g_repo = NULL;
+ cl_fixture_cleanup("./foo");
+}
+
+static int cancel_at_half(const git_transfer_progress *stats, void *payload)
+{
+ GIT_UNUSED(payload);
+
+ if (stats->received_objects > (stats->total_objects/2))
+ return 1;
+ return 0;
+}
+
+void test_online_clone__can_cancel(void)
+{
+ g_options.fetch_progress_cb = cancel_at_half;
+ cl_git_fail_with(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), GIT_EUSER);
+}
diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c
new file mode 100644
index 000000000..bfa1eb972
--- /dev/null
+++ b/tests-clar/online/fetch.c
@@ -0,0 +1,163 @@
+#include "clar_libgit2.h"
+
+static git_repository *_repo;
+static int counter;
+
+void test_online_fetch__initialize(void)
+{
+ cl_git_pass(git_repository_init(&_repo, "./fetch", 0));
+}
+
+void test_online_fetch__cleanup(void)
+{
+ git_repository_free(_repo);
+ _repo = NULL;
+
+ cl_fixture_cleanup("./fetch");
+}
+
+static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
+{
+ GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b); GIT_UNUSED(data);
+
+ ++counter;
+
+ return 0;
+}
+
+static int progress(const git_transfer_progress *stats, void *payload)
+{
+ size_t *bytes_received = (size_t *)payload;
+ *bytes_received = stats->received_bytes;
+ return 0;
+}
+
+static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
+{
+ git_remote *remote;
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ size_t bytes_received = 0;
+
+ callbacks.update_tips = update_tips;
+ counter = 0;
+
+ cl_git_pass(git_remote_create(&remote, _repo, "test", url));
+ git_remote_set_callbacks(remote, &callbacks);
+ git_remote_set_autotag(remote, flag);
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_download(remote, progress, &bytes_received));
+ cl_git_pass(git_remote_update_tips(remote));
+ git_remote_disconnect(remote);
+ cl_assert_equal_i(counter, n);
+ cl_assert(bytes_received > 0);
+
+ git_remote_free(remote);
+}
+
+void test_online_fetch__default_git(void)
+{
+ do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
+}
+
+void test_online_fetch__default_http(void)
+{
+ do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
+}
+
+void test_online_fetch__no_tags_git(void)
+{
+ do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
+}
+
+void test_online_fetch__no_tags_http(void)
+{
+ do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
+}
+
+static int transferProgressCallback(const git_transfer_progress *stats, void *payload)
+{
+ bool *invoked = (bool *)payload;
+
+ GIT_UNUSED(stats);
+ *invoked = true;
+ return 0;
+}
+
+void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date(void)
+{
+ git_repository *_repository;
+ bool invoked = false;
+ git_remote *remote;
+ git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
+ opts.bare = true;
+
+ cl_git_pass(git_clone(&_repository, "https://github.com/libgit2/TestGitRepository.git",
+ "./fetch/lg2", &opts));
+ git_repository_free(_repository);
+
+ cl_git_pass(git_repository_open(&_repository, "./fetch/lg2"));
+
+ cl_git_pass(git_remote_load(&remote, _repository, "origin"));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+
+ cl_assert_equal_i(false, invoked);
+
+ cl_git_pass(git_remote_download(remote, &transferProgressCallback, &invoked));
+
+ cl_assert_equal_i(false, invoked);
+
+ cl_git_pass(git_remote_update_tips(remote));
+ git_remote_disconnect(remote);
+
+ git_remote_free(remote);
+ git_repository_free(_repository);
+}
+
+static int cancel_at_half(const git_transfer_progress *stats, void *payload)
+{
+ GIT_UNUSED(payload);
+
+ if (stats->received_objects > (stats->total_objects/2))
+ return -1;
+ return 0;
+}
+
+void test_online_fetch__can_cancel(void)
+{
+ git_remote *remote;
+ size_t bytes_received = 0;
+
+ cl_git_pass(git_remote_create(&remote, _repo, "test",
+ "http://github.com/libgit2/TestGitRepository.git"));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_fail_with(git_remote_download(remote, cancel_at_half, &bytes_received), GIT_EUSER);
+ git_remote_disconnect(remote);
+ git_remote_free(remote);
+}
+
+int ls_cb(git_remote_head *rhead, void *payload)
+{
+ int *nr = payload;
+ GIT_UNUSED(rhead);
+
+ (*nr)++;
+
+ return 0;
+}
+
+void test_online_fetch__ls_disconnected(void)
+{
+ git_remote *remote;
+ int nr_before = 0, nr_after = 0;
+
+ cl_git_pass(git_remote_create(&remote, _repo, "test",
+ "http://github.com/libgit2/TestGitRepository.git"));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_ls(remote, ls_cb, &nr_before));
+ git_remote_disconnect(remote);
+ cl_git_pass(git_remote_ls(remote, ls_cb, &nr_after));
+
+ cl_assert_equal_i(nr_before, nr_after);
+
+ git_remote_free(remote);
+}
diff --git a/tests-clar/online/fetchhead.c b/tests-clar/online/fetchhead.c
new file mode 100644
index 000000000..a8a5bb918
--- /dev/null
+++ b/tests-clar/online/fetchhead.c
@@ -0,0 +1,87 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "fetchhead.h"
+#include "../fetchhead/fetchhead_data.h"
+#include "git2/clone.h"
+
+#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
+
+static git_repository *g_repo;
+static git_clone_options g_options;
+
+void test_online_fetchhead__initialize(void)
+{
+ g_repo = NULL;
+
+ memset(&g_options, 0, sizeof(git_clone_options));
+ g_options.version = GIT_CLONE_OPTIONS_VERSION;
+}
+
+void test_online_fetchhead__cleanup(void)
+{
+ if (g_repo) {
+ git_repository_free(g_repo);
+ g_repo = NULL;
+ }
+
+ cl_fixture_cleanup("./foo");
+}
+
+static void fetchhead_test_clone(void)
+{
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
+}
+
+static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead)
+{
+ git_remote *remote;
+ git_buf fetchhead_buf = GIT_BUF_INIT;
+ int equals = 0;
+
+ cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
+ git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
+
+ if(fetchspec != NULL)
+ git_remote_set_fetchspec(remote, fetchspec);
+
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote));
+ git_remote_disconnect(remote);
+ git_remote_free(remote);
+
+ cl_git_pass(git_futils_readbuffer(&fetchhead_buf, "./foo/.git/FETCH_HEAD"));
+
+ equals = (strcmp(fetchhead_buf.ptr, expected_fetchhead) == 0);
+
+ git_buf_free(&fetchhead_buf);
+
+ cl_assert(equals);
+}
+
+void test_online_fetchhead__wildcard_spec(void)
+{
+ fetchhead_test_clone();
+ fetchhead_test_fetch(NULL, FETCH_HEAD_WILDCARD_DATA);
+}
+
+void test_online_fetchhead__explicit_spec(void)
+{
+ fetchhead_test_clone();
+ fetchhead_test_fetch("refs/heads/first-merge:refs/remotes/origin/first-merge", FETCH_HEAD_EXPLICIT_DATA);
+}
+
+void test_online_fetchhead__no_merges(void)
+{
+ git_config *config;
+
+ fetchhead_test_clone();
+
+ cl_git_pass(git_repository_config(&config, g_repo));
+ cl_git_pass(git_config_delete_entry(config, "branch.master.remote"));
+ cl_git_pass(git_config_delete_entry(config, "branch.master.merge"));
+ git_config_free(config);
+
+ fetchhead_test_fetch(NULL, FETCH_HEAD_NO_MERGE_DATA);
+}
diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c
new file mode 100644
index 000000000..907d6d29f
--- /dev/null
+++ b/tests-clar/online/push.c
@@ -0,0 +1,710 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "posix.h"
+#include "vector.h"
+#include "../submodule/submodule_helpers.h"
+#include "push_util.h"
+#include "refspec.h"
+#include "remote.h"
+
+static git_repository *_repo;
+
+static char *_remote_url;
+static char *_remote_user;
+static char *_remote_pass;
+
+static git_remote *_remote;
+static bool _cred_acquire_called;
+static record_callbacks_data _record_cbs_data = {{ 0 }};
+static git_remote_callbacks _record_cbs = RECORD_CALLBACKS_INIT(&_record_cbs_data);
+
+static git_oid _oid_b6;
+static git_oid _oid_b5;
+static git_oid _oid_b4;
+static git_oid _oid_b3;
+static git_oid _oid_b2;
+static git_oid _oid_b1;
+
+static git_oid _tag_commit;
+static git_oid _tag_tree;
+static git_oid _tag_blob;
+static git_oid _tag_lightweight;
+
+static int cred_acquire_cb(
+ git_cred **cred,
+ const char *url,
+ const char *user_from_url,
+ unsigned int allowed_types,
+ void *payload)
+{
+ GIT_UNUSED(url);
+ GIT_UNUSED(user_from_url);
+
+ *((bool*)payload) = true;
+
+ if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
+ git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass) < 0)
+ return -1;
+
+ return 0;
+}
+
+typedef struct {
+ const char *ref;
+ const char *msg;
+} push_status;
+
+/**
+ * git_push_status_foreach callback that records status entries.
+ * @param data (git_vector *) of push_status instances
+ */
+static int record_push_status_cb(const char *ref, const char *msg, void *data)
+{
+ git_vector *statuses = (git_vector *)data;
+ push_status *s;
+
+ cl_assert(s = git__malloc(sizeof(*s)));
+ s->ref = ref;
+ s->msg = msg;
+
+ git_vector_insert(statuses, s);
+
+ return 0;
+}
+
+static void do_verify_push_status(git_push *push, const push_status expected[], const size_t expected_len)
+{
+ git_vector actual = GIT_VECTOR_INIT;
+ push_status *iter;
+ bool failed = false;
+ size_t i;
+
+ git_push_status_foreach(push, record_push_status_cb, &actual);
+
+ if (expected_len != actual.length)
+ failed = true;
+ else
+ git_vector_foreach(&actual, i, iter)
+ if (strcmp(expected[i].ref, iter->ref) ||
+ (expected[i].msg && !iter->msg) ||
+ (!expected[i].msg && iter->msg) ||
+ (expected[i].msg && iter->msg && strcmp(expected[i].msg, iter->msg))) {
+ failed = true;
+ break;
+ }
+
+ if (failed) {
+ git_buf msg = GIT_BUF_INIT;
+
+ git_buf_puts(&msg, "Expected and actual push statuses differ:\nEXPECTED:\n");
+
+ for(i = 0; i < expected_len; i++) {
+ git_buf_printf(&msg, "%s: %s\n",
+ expected[i].ref,
+ expected[i].msg ? expected[i].msg : "<NULL>");
+ }
+
+ git_buf_puts(&msg, "\nACTUAL:\n");
+
+ git_vector_foreach(&actual, i, iter)
+ git_buf_printf(&msg, "%s: %s\n", iter->ref, iter->msg);
+
+ cl_fail(git_buf_cstr(&msg));
+
+ git_buf_free(&msg);
+ }
+
+ git_vector_foreach(&actual, i, iter)
+ git__free(iter);
+
+ git_vector_free(&actual);
+}
+
+/**
+ * Verifies that after git_push_finish(), refs on a remote have the expected
+ * names, oids, and order.
+ *
+ * @param remote remote to verify
+ * @param expected_refs expected remote refs after push
+ * @param expected_refs_len length of expected_refs
+ */
+static void verify_refs(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
+{
+ git_vector actual_refs = GIT_VECTOR_INIT;
+
+ git_remote_ls(remote, record_ref_cb, &actual_refs);
+ verify_remote_refs(&actual_refs, expected_refs, expected_refs_len);
+
+ git_vector_free(&actual_refs);
+}
+
+static int tracking_branch_list_cb(const char *branch_name, git_branch_t branch_type, void *payload)
+{
+ git_vector *tracking = (git_vector *)payload;
+
+ if (branch_type == GIT_BRANCH_REMOTE)
+ git_vector_insert(tracking, git__strdup(branch_name));
+ else
+ GIT_UNUSED(branch_name);
+
+ return 0;
+}
+
+/**
+ * Verifies that after git_push_update_tips(), remote tracking branches have the expected
+ * names and oids.
+ *
+ * @param remote remote to verify
+ * @param expected_refs expected remote refs after push
+ * @param expected_refs_len length of expected_refs
+ */
+static void verify_tracking_branches(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
+{
+ git_refspec *fetch_spec = &remote->fetch;
+ size_t i, j;
+ git_buf msg = GIT_BUF_INIT;
+ git_buf ref_name = GIT_BUF_INIT;
+ git_buf canonical_ref_name = GIT_BUF_INIT;
+ git_vector actual_refs = GIT_VECTOR_INIT;
+ char *actual_ref;
+ git_oid oid;
+ int failed = 0;
+
+ /* Get current remote branches */
+ cl_git_pass(git_branch_foreach(remote->repo, GIT_BRANCH_REMOTE, tracking_branch_list_cb, &actual_refs));
+
+ /* Loop through expected refs, make sure they exist */
+ for (i = 0; i < expected_refs_len; i++) {
+
+ /* Convert remote reference name into tracking branch name.
+ * If the spec is not under refs/heads/, then skip.
+ */
+ if (!git_refspec_src_matches(fetch_spec, expected_refs[i].name))
+ continue;
+
+ cl_git_pass(git_refspec_transform_r(&ref_name, fetch_spec, expected_refs[i].name));
+
+ /* Find matching remote branch */
+ git_vector_foreach(&actual_refs, j, actual_ref) {
+
+ /* Construct canonical ref name from the actual_ref name */
+ git_buf_clear(&canonical_ref_name);
+ cl_git_pass(git_buf_printf(&canonical_ref_name, "refs/remotes/%s", actual_ref));
+ if (!strcmp(git_buf_cstr(&ref_name), git_buf_cstr(&canonical_ref_name)))
+ break;
+ }
+
+ if (j == actual_refs.length) {
+ git_buf_printf(&msg, "Did not find expected tracking branch '%s'.", git_buf_cstr(&ref_name));
+ failed = 1;
+ goto failed;
+ }
+
+ /* Make sure tracking branch is at expected commit ID */
+ cl_git_pass(git_reference_name_to_id(&oid, remote->repo, git_buf_cstr(&canonical_ref_name)));
+
+ if (git_oid_cmp(expected_refs[i].oid, &oid) != 0) {
+ git_buf_puts(&msg, "Tracking branch commit does not match expected ID.");
+ failed = 1;
+ goto failed;
+ }
+
+ git__free(actual_ref);
+ cl_git_pass(git_vector_remove(&actual_refs, j));
+ }
+
+ /* Make sure there are no extra branches */
+ if (actual_refs.length > 0) {
+ git_buf_puts(&msg, "Unexpected remote tracking branches exist.");
+ failed = 1;
+ goto failed;
+ }
+
+failed:
+
+ if(failed)
+ cl_fail(git_buf_cstr(&msg));
+
+ git_vector_foreach(&actual_refs, i, actual_ref)
+ git__free(actual_ref);
+
+ git_vector_free(&actual_refs);
+ git_buf_free(&msg);
+ git_buf_free(&canonical_ref_name);
+ git_buf_free(&ref_name);
+ return;
+}
+
+void test_online_push__initialize(void)
+{
+ git_vector delete_specs = GIT_VECTOR_INIT;
+ size_t i;
+ char *curr_del_spec;
+ _cred_acquire_called = false;
+
+ _repo = cl_git_sandbox_init("push_src");
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_rename("push_src/submodule/.gitted", "push_src/submodule/.git");
+
+ rewrite_gitmodules(git_repository_workdir(_repo));
+
+ /* git log --format=oneline --decorate --graph
+ * *-. 951bbbb90e2259a4c8950db78946784fb53fcbce (HEAD, b6) merge b3, b4, and b5 to b6
+ * |\ \
+ * | | * fa38b91f199934685819bea316186d8b008c52a2 (b5) added submodule named 'submodule' pointing to '../testrepo.git'
+ * | * | 27b7ce66243eb1403862d05f958c002312df173d (b4) edited fold\b.txt
+ * | |/
+ * * | d9b63a88223d8367516f50bd131a5f7349b7f3e4 (b3) edited a.txt
+ * |/
+ * * a78705c3b2725f931d3ee05348d83cc26700f247 (b2, b1) added fold and fold/b.txt
+ * * 5c0bb3d1b9449d1cc69d7519fd05166f01840915 added a.txt
+ */
+ git_oid_fromstr(&_oid_b6, "951bbbb90e2259a4c8950db78946784fb53fcbce");
+ git_oid_fromstr(&_oid_b5, "fa38b91f199934685819bea316186d8b008c52a2");
+ git_oid_fromstr(&_oid_b4, "27b7ce66243eb1403862d05f958c002312df173d");
+ git_oid_fromstr(&_oid_b3, "d9b63a88223d8367516f50bd131a5f7349b7f3e4");
+ git_oid_fromstr(&_oid_b2, "a78705c3b2725f931d3ee05348d83cc26700f247");
+ git_oid_fromstr(&_oid_b1, "a78705c3b2725f931d3ee05348d83cc26700f247");
+
+ git_oid_fromstr(&_tag_commit, "805c54522e614f29f70d2413a0470247d8b424ac");
+ git_oid_fromstr(&_tag_tree, "ff83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e");
+ git_oid_fromstr(&_tag_blob, "b483ae7ba66decee9aee971f501221dea84b1498");
+ git_oid_fromstr(&_tag_lightweight, "951bbbb90e2259a4c8950db78946784fb53fcbce");
+
+ /* Remote URL environment variable must be set. User and password are optional. */
+ _remote_url = cl_getenv("GITTEST_REMOTE_URL");
+ _remote_user = cl_getenv("GITTEST_REMOTE_USER");
+ _remote_pass = cl_getenv("GITTEST_REMOTE_PASS");
+ _remote = NULL;
+
+ if (_remote_url) {
+ cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url));
+
+ git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &_cred_acquire_called);
+ record_callbacks_data_clear(&_record_cbs_data);
+ git_remote_set_callbacks(_remote, &_record_cbs);
+
+ cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH));
+
+ /* Clean up previously pushed branches. Fails if receive.denyDeletes is
+ * set on the remote. Also, on Git 1.7.0 and newer, you must run
+ * 'git config receive.denyDeleteCurrent ignore' in the remote repo in
+ * order to delete the remote branch pointed to by HEAD (usually master).
+ * See: https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.0.txt
+ */
+ cl_git_pass(git_remote_ls(_remote, delete_ref_cb, &delete_specs));
+ if (delete_specs.length) {
+ git_push *push;
+
+ cl_git_pass(git_push_new(&push, _remote));
+
+ git_vector_foreach(&delete_specs, i, curr_del_spec) {
+ git_push_add_refspec(push, curr_del_spec);
+ git__free(curr_del_spec);
+ }
+
+ cl_git_pass(git_push_finish(push));
+ git_push_free(push);
+ }
+
+ git_remote_disconnect(_remote);
+ git_vector_free(&delete_specs);
+
+ /* Now that we've deleted everything, fetch from the remote */
+ cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_download(_remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(_remote));
+ git_remote_disconnect(_remote);
+ } else
+ printf("GITTEST_REMOTE_URL unset; skipping push test\n");
+}
+
+void test_online_push__cleanup(void)
+{
+ if (_remote)
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ /* Freed by cl_git_sandbox_cleanup */
+ _repo = NULL;
+
+ record_callbacks_data_clear(&_record_cbs_data);
+
+ cl_fixture_cleanup("testrepo.git");
+ cl_git_sandbox_cleanup();
+}
+
+/**
+ * Calls push and relists refs on remote to verify success.
+ *
+ * @param refspecs refspecs to push
+ * @param refspecs_len length of refspecs
+ * @param expected_refs expected remote refs after push
+ * @param expected_refs_len length of expected_refs
+ * @param expected_ret expected return value from git_push_finish()
+ */
+static void do_push(const char *refspecs[], size_t refspecs_len,
+ push_status expected_statuses[], size_t expected_statuses_len,
+ expected_ref expected_refs[], size_t expected_refs_len, int expected_ret)
+{
+ git_push *push;
+ git_push_options opts = GIT_PUSH_OPTIONS_INIT;
+ size_t i;
+ int ret;
+
+ if (_remote) {
+ /* Auto-detect the number of threads to use */
+ opts.pb_parallelism = 0;
+
+ cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH));
+
+ cl_git_pass(git_push_new(&push, _remote));
+ cl_git_pass(git_push_set_options(push, &opts));
+
+ for (i = 0; i < refspecs_len; i++)
+ cl_git_pass(git_push_add_refspec(push, refspecs[i]));
+
+ if (expected_ret < 0) {
+ cl_git_fail(ret = git_push_finish(push));
+ cl_assert_equal_i(0, git_push_unpack_ok(push));
+ }
+ else {
+ cl_git_pass(ret = git_push_finish(push));
+ cl_assert_equal_i(1, git_push_unpack_ok(push));
+ }
+
+ do_verify_push_status(push, expected_statuses, expected_statuses_len);
+
+ cl_assert_equal_i(expected_ret, ret);
+
+ verify_refs(_remote, expected_refs, expected_refs_len);
+
+ cl_git_pass(git_push_update_tips(push));
+ verify_tracking_branches(_remote, expected_refs, expected_refs_len);
+
+ git_push_free(push);
+
+ git_remote_disconnect(_remote);
+ }
+}
+
+/* Call push_finish() without ever calling git_push_add_refspec() */
+void test_online_push__noop(void)
+{
+ do_push(NULL, 0, NULL, 0, NULL, 0, 0);
+}
+
+void test_online_push__b1(void)
+{
+ const char *specs[] = { "refs/heads/b1:refs/heads/b1" };
+ push_status exp_stats[] = { { "refs/heads/b1", NULL } };
+ expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__b2(void)
+{
+ const char *specs[] = { "refs/heads/b2:refs/heads/b2" };
+ push_status exp_stats[] = { { "refs/heads/b2", NULL } };
+ expected_ref exp_refs[] = { { "refs/heads/b2", &_oid_b2 } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__b3(void)
+{
+ const char *specs[] = { "refs/heads/b3:refs/heads/b3" };
+ push_status exp_stats[] = { { "refs/heads/b3", NULL } };
+ expected_ref exp_refs[] = { { "refs/heads/b3", &_oid_b3 } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__b4(void)
+{
+ const char *specs[] = { "refs/heads/b4:refs/heads/b4" };
+ push_status exp_stats[] = { { "refs/heads/b4", NULL } };
+ expected_ref exp_refs[] = { { "refs/heads/b4", &_oid_b4 } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__b5(void)
+{
+ const char *specs[] = { "refs/heads/b5:refs/heads/b5" };
+ push_status exp_stats[] = { { "refs/heads/b5", NULL } };
+ expected_ref exp_refs[] = { { "refs/heads/b5", &_oid_b5 } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__multi(void)
+{
+ const char *specs[] = {
+ "refs/heads/b1:refs/heads/b1",
+ "refs/heads/b2:refs/heads/b2",
+ "refs/heads/b3:refs/heads/b3",
+ "refs/heads/b4:refs/heads/b4",
+ "refs/heads/b5:refs/heads/b5"
+ };
+ push_status exp_stats[] = {
+ { "refs/heads/b1", NULL },
+ { "refs/heads/b2", NULL },
+ { "refs/heads/b3", NULL },
+ { "refs/heads/b4", NULL },
+ { "refs/heads/b5", NULL }
+ };
+ expected_ref exp_refs[] = {
+ { "refs/heads/b1", &_oid_b1 },
+ { "refs/heads/b2", &_oid_b2 },
+ { "refs/heads/b3", &_oid_b3 },
+ { "refs/heads/b4", &_oid_b4 },
+ { "refs/heads/b5", &_oid_b5 }
+ };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__implicit_tgt(void)
+{
+ const char *specs1[] = { "refs/heads/b1:" };
+ push_status exp_stats1[] = { { "refs/heads/b1", NULL } };
+ expected_ref exp_refs1[] = { { "refs/heads/b1", &_oid_b1 } };
+
+ const char *specs2[] = { "refs/heads/b2:" };
+ push_status exp_stats2[] = { { "refs/heads/b2", NULL } };
+ expected_ref exp_refs2[] = {
+ { "refs/heads/b1", &_oid_b1 },
+ { "refs/heads/b2", &_oid_b2 }
+ };
+
+ do_push(specs1, ARRAY_SIZE(specs1),
+ exp_stats1, ARRAY_SIZE(exp_stats1),
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ do_push(specs2, ARRAY_SIZE(specs2),
+ exp_stats2, ARRAY_SIZE(exp_stats2),
+ exp_refs2, ARRAY_SIZE(exp_refs2), 0);
+}
+
+void test_online_push__fast_fwd(void)
+{
+ /* Fast forward b1 in tgt from _oid_b1 to _oid_b6. */
+
+ const char *specs_init[] = { "refs/heads/b1:refs/heads/b1" };
+ push_status exp_stats_init[] = { { "refs/heads/b1", NULL } };
+ expected_ref exp_refs_init[] = { { "refs/heads/b1", &_oid_b1 } };
+
+ const char *specs_ff[] = { "refs/heads/b6:refs/heads/b1" };
+ push_status exp_stats_ff[] = { { "refs/heads/b1", NULL } };
+ expected_ref exp_refs_ff[] = { { "refs/heads/b1", &_oid_b6 } };
+
+ /* Do a force push to reset b1 in target back to _oid_b1 */
+ const char *specs_reset[] = { "+refs/heads/b1:refs/heads/b1" };
+ /* Force should have no effect on a fast forward push */
+ const char *specs_ff_force[] = { "+refs/heads/b6:refs/heads/b1" };
+
+ do_push(specs_init, ARRAY_SIZE(specs_init),
+ exp_stats_init, ARRAY_SIZE(exp_stats_init),
+ exp_refs_init, ARRAY_SIZE(exp_refs_init), 0);
+
+ do_push(specs_ff, ARRAY_SIZE(specs_ff),
+ exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
+ exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0);
+
+ do_push(specs_reset, ARRAY_SIZE(specs_reset),
+ exp_stats_init, ARRAY_SIZE(exp_stats_init),
+ exp_refs_init, ARRAY_SIZE(exp_refs_init), 0);
+
+ do_push(specs_ff_force, ARRAY_SIZE(specs_ff_force),
+ exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
+ exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0);
+}
+
+void test_online_push__tag_commit(void)
+{
+ const char *specs[] = { "refs/tags/tag-commit:refs/tags/tag-commit" };
+ push_status exp_stats[] = { { "refs/tags/tag-commit", NULL } };
+ expected_ref exp_refs[] = { { "refs/tags/tag-commit", &_tag_commit } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__tag_tree(void)
+{
+ const char *specs[] = { "refs/tags/tag-tree:refs/tags/tag-tree" };
+ push_status exp_stats[] = { { "refs/tags/tag-tree", NULL } };
+ expected_ref exp_refs[] = { { "refs/tags/tag-tree", &_tag_tree } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__tag_blob(void)
+{
+ const char *specs[] = { "refs/tags/tag-blob:refs/tags/tag-blob" };
+ push_status exp_stats[] = { { "refs/tags/tag-blob", NULL } };
+ expected_ref exp_refs[] = { { "refs/tags/tag-blob", &_tag_blob } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__tag_lightweight(void)
+{
+ const char *specs[] = { "refs/tags/tag-lightweight:refs/tags/tag-lightweight" };
+ push_status exp_stats[] = { { "refs/tags/tag-lightweight", NULL } };
+ expected_ref exp_refs[] = { { "refs/tags/tag-lightweight", &_tag_lightweight } };
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+}
+
+void test_online_push__force(void)
+{
+ const char *specs1[] = {"refs/heads/b3:refs/heads/tgt"};
+ push_status exp_stats1[] = { { "refs/heads/tgt", NULL } };
+ expected_ref exp_refs1[] = { { "refs/heads/tgt", &_oid_b3 } };
+
+ const char *specs2[] = {"refs/heads/b4:refs/heads/tgt"};
+
+ const char *specs2_force[] = {"+refs/heads/b4:refs/heads/tgt"};
+ push_status exp_stats2_force[] = { { "refs/heads/tgt", NULL } };
+ expected_ref exp_refs2_force[] = { { "refs/heads/tgt", &_oid_b4 } };
+
+ do_push(specs1, ARRAY_SIZE(specs1),
+ exp_stats1, ARRAY_SIZE(exp_stats1),
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+
+ do_push(specs2, ARRAY_SIZE(specs2),
+ NULL, 0,
+ exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD);
+
+ /* Non-fast-forward update with force should pass. */
+ do_push(specs2_force, ARRAY_SIZE(specs2_force),
+ exp_stats2_force, ARRAY_SIZE(exp_stats2_force),
+ exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0);
+}
+
+void test_online_push__delete(void)
+{
+ const char *specs1[] = {
+ "refs/heads/b1:refs/heads/tgt1",
+ "refs/heads/b1:refs/heads/tgt2"
+ };
+ push_status exp_stats1[] = {
+ { "refs/heads/tgt1", NULL },
+ { "refs/heads/tgt2", NULL }
+ };
+ expected_ref exp_refs1[] = {
+ { "refs/heads/tgt1", &_oid_b1 },
+ { "refs/heads/tgt2", &_oid_b1 }
+ };
+
+ const char *specs_del_fake[] = { ":refs/heads/fake" };
+ /* Force has no effect for delete. */
+ const char *specs_del_fake_force[] = { "+:refs/heads/fake" };
+ push_status exp_stats_fake[] = { { "refs/heads/fake", NULL } };
+
+ const char *specs_delete[] = { ":refs/heads/tgt1" };
+ push_status exp_stats_delete[] = { { "refs/heads/tgt1", NULL } };
+ expected_ref exp_refs_delete[] = { { "refs/heads/tgt2", &_oid_b1 } };
+ /* Force has no effect for delete. */
+ const char *specs_delete_force[] = { "+:refs/heads/tgt1" };
+
+ do_push(specs1, ARRAY_SIZE(specs1),
+ exp_stats1, ARRAY_SIZE(exp_stats1),
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+
+ /* When deleting a non-existent branch, the git client sends zero for both
+ * the old and new commit id. This should succeed on the server with the
+ * same status report as if the branch were actually deleted. The server
+ * returns a warning on the side-band iff the side-band is supported.
+ * Since libgit2 doesn't support the side-band yet, there are no warnings.
+ */
+ do_push(specs_del_fake, ARRAY_SIZE(specs_del_fake),
+ exp_stats_fake, 1,
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ do_push(specs_del_fake_force, ARRAY_SIZE(specs_del_fake_force),
+ exp_stats_fake, 1,
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+
+ /* Delete one of the pushed branches. */
+ do_push(specs_delete, ARRAY_SIZE(specs_delete),
+ exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
+ exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0);
+
+ /* Re-push branches and retry delete with force. */
+ do_push(specs1, ARRAY_SIZE(specs1),
+ exp_stats1, ARRAY_SIZE(exp_stats1),
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ do_push(specs_delete_force, ARRAY_SIZE(specs_delete_force),
+ exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
+ exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0);
+}
+
+void test_online_push__bad_refspecs(void)
+{
+ /* All classes of refspecs that should be rejected by
+ * git_push_add_refspec() should go in this test.
+ */
+ git_push *push;
+
+ if (_remote) {
+// cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_push_new(&push, _remote));
+
+ /* Unexpanded branch names not supported */
+ cl_git_fail(git_push_add_refspec(push, "b6:b6"));
+
+ git_push_free(push);
+ }
+}
+
+void test_online_push__expressions(void)
+{
+ /* TODO: Expressions in refspecs doesn't actually work yet */
+ const char *specs_left_expr[] = { "refs/heads/b2~1:refs/heads/b2" };
+
+ const char *specs_right_expr[] = { "refs/heads/b2:refs/heads/b2~1" };
+ push_status exp_stats_right_expr[] = { { "refs/heads/b2~1", "funny refname" } };
+
+ /* TODO: Find a more precise way of checking errors than a exit code of -1. */
+ do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr),
+ NULL, 0,
+ NULL, 0, -1);
+
+ do_push(specs_right_expr, ARRAY_SIZE(specs_right_expr),
+ exp_stats_right_expr, ARRAY_SIZE(exp_stats_right_expr),
+ NULL, 0, 0);
+}
+
+void test_online_push__notes(void)
+{
+ git_oid note_oid, *target_oid, expected_oid;
+ git_signature *signature;
+ const char *specs[] = { "refs/notes/commits:refs/notes/commits" };
+ push_status exp_stats[] = { { "refs/notes/commits", NULL } };
+ expected_ref exp_refs[] = { { "refs/notes/commits", &expected_oid } };
+ git_oid_fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb");
+
+ target_oid = &_oid_b6;
+
+ /* Create note to push */
+ cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
+ cl_git_pass(git_note_create(&note_oid, _repo, signature, signature, NULL, target_oid, "hello world\n", 0));
+
+ do_push(specs, ARRAY_SIZE(specs),
+ exp_stats, ARRAY_SIZE(exp_stats),
+ exp_refs, ARRAY_SIZE(exp_refs), 0);
+
+ git_signature_free(signature);
+}
diff --git a/tests-clar/online/push_util.c b/tests-clar/online/push_util.c
new file mode 100644
index 000000000..2e457844d
--- /dev/null
+++ b/tests-clar/online/push_util.c
@@ -0,0 +1,126 @@
+
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "vector.h"
+#include "push_util.h"
+
+const git_oid OID_ZERO = {{ 0 }};
+
+void updated_tip_free(updated_tip *t)
+{
+ git__free(t->name);
+ git__free(t->old_oid);
+ git__free(t->new_oid);
+ git__free(t);
+}
+
+void record_callbacks_data_clear(record_callbacks_data *data)
+{
+ size_t i;
+ updated_tip *tip;
+
+ git_vector_foreach(&data->updated_tips, i, tip)
+ updated_tip_free(tip);
+
+ git_vector_free(&data->updated_tips);
+}
+
+int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
+{
+ updated_tip *t;
+ record_callbacks_data *record_data = (record_callbacks_data *)data;
+
+ cl_assert(t = git__malloc(sizeof(*t)));
+
+ cl_assert(t->name = git__strdup(refname));
+ cl_assert(t->old_oid = git__malloc(sizeof(*t->old_oid)));
+ git_oid_cpy(t->old_oid, a);
+
+ cl_assert(t->new_oid = git__malloc(sizeof(*t->new_oid)));
+ git_oid_cpy(t->new_oid, b);
+
+ git_vector_insert(&record_data->updated_tips, t);
+
+ return 0;
+}
+
+int delete_ref_cb(git_remote_head *head, void *payload)
+{
+ git_vector *delete_specs = (git_vector *)payload;
+ git_buf del_spec = GIT_BUF_INIT;
+
+ /* Ignore malformed ref names (which also saves us from tag^{} */
+ if (!git_reference_is_valid_name(head->name))
+ return 0;
+
+ /* Create a refspec that deletes a branch in the remote */
+ if (strcmp(head->name, "refs/heads/master")) {
+ cl_git_pass(git_buf_putc(&del_spec, ':'));
+ cl_git_pass(git_buf_puts(&del_spec, head->name));
+ cl_git_pass(git_vector_insert(delete_specs, git_buf_detach(&del_spec)));
+ }
+
+ return 0;
+}
+
+int record_ref_cb(git_remote_head *head, void *payload)
+{
+ git_vector *refs = (git_vector *) payload;
+ return git_vector_insert(refs, head);
+}
+
+void verify_remote_refs(git_vector *actual_refs, const expected_ref expected_refs[], size_t expected_refs_len)
+{
+ size_t i, j = 0;
+ git_buf msg = GIT_BUF_INIT;
+ git_remote_head *actual;
+ char *oid_str;
+ bool master_present = false;
+
+ /* We don't care whether "master" is present on the other end or not */
+ git_vector_foreach(actual_refs, i, actual) {
+ if (!strcmp(actual->name, "refs/heads/master")) {
+ master_present = true;
+ break;
+ }
+ }
+
+ if (expected_refs_len + (master_present ? 1 : 0) != actual_refs->length)
+ goto failed;
+
+ git_vector_foreach(actual_refs, i, actual) {
+ if (master_present && !strcmp(actual->name, "refs/heads/master"))
+ continue;
+
+ if (strcmp(expected_refs[j].name, actual->name) ||
+ git_oid_cmp(expected_refs[j].oid, &actual->oid))
+ goto failed;
+
+ j++;
+ }
+
+ return;
+
+failed:
+ git_buf_puts(&msg, "Expected and actual refs differ:\nEXPECTED:\n");
+
+ for(i = 0; i < expected_refs_len; i++) {
+ cl_assert(oid_str = git_oid_allocfmt(expected_refs[i].oid));
+ cl_git_pass(git_buf_printf(&msg, "%s = %s\n", expected_refs[i].name, oid_str));
+ git__free(oid_str);
+ }
+
+ git_buf_puts(&msg, "\nACTUAL:\n");
+ git_vector_foreach(actual_refs, i, actual) {
+ if (master_present && !strcmp(actual->name, "refs/heads/master"))
+ continue;
+
+ cl_assert(oid_str = git_oid_allocfmt(&actual->oid));
+ cl_git_pass(git_buf_printf(&msg, "%s = %s\n", actual->name, oid_str));
+ git__free(oid_str);
+ }
+
+ cl_fail(git_buf_cstr(&msg));
+
+ git_buf_free(&msg);
+}
diff --git a/tests-clar/online/push_util.h b/tests-clar/online/push_util.h
new file mode 100644
index 000000000..759122aa6
--- /dev/null
+++ b/tests-clar/online/push_util.h
@@ -0,0 +1,69 @@
+#ifndef INCLUDE_cl_push_util_h__
+#define INCLUDE_cl_push_util_h__
+
+#include "git2/oid.h"
+
+/* Constant for zero oid */
+extern const git_oid OID_ZERO;
+
+/**
+ * Macro for initializing git_remote_callbacks to use test helpers that
+ * record data in a record_callbacks_data instance.
+ * @param data pointer to a record_callbacks_data instance
+ */
+#define RECORD_CALLBACKS_INIT(data) \
+ { GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, record_update_tips_cb, data }
+
+typedef struct {
+ char *name;
+ git_oid *old_oid;
+ git_oid *new_oid;
+} updated_tip;
+
+typedef struct {
+ git_vector updated_tips;
+} record_callbacks_data;
+
+typedef struct {
+ const char *name;
+ const git_oid *oid;
+} expected_ref;
+
+void updated_tip_free(updated_tip *t);
+
+void record_callbacks_data_clear(record_callbacks_data *data);
+
+/**
+ * Callback for git_remote_update_tips that records updates
+ *
+ * @param data (git_vector *) of updated_tip instances
+ */
+int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data);
+
+/**
+ * Callback for git_remote_list that adds refspecs to delete each ref
+ *
+ * @param head a ref on the remote
+ * @param payload a git_push instance
+ */
+int delete_ref_cb(git_remote_head *head, void *payload);
+
+/**
+ * Callback for git_remote_list that adds refspecs to vector
+ *
+ * @param head a ref on the remote
+ * @param payload (git_vector *) of git_remote_head instances
+ */
+int record_ref_cb(git_remote_head *head, void *payload);
+
+/**
+ * Verifies that refs on remote stored by record_ref_cb match the expected
+ * names, oids, and order.
+ *
+ * @param actual_refs actual refs stored by record_ref_cb()
+ * @param expected_refs expected remote refs
+ * @param expected_refs_len length of expected_refs
+ */
+void verify_remote_refs(git_vector *actual_refs, const expected_ref expected_refs[], size_t expected_refs_len);
+
+#endif /* INCLUDE_cl_push_util_h__ */
diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c
new file mode 100644
index 000000000..764fba213
--- /dev/null
+++ b/tests-clar/pack/packbuilder.c
@@ -0,0 +1,148 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "hash.h"
+#include "iterator.h"
+#include "vector.h"
+#include "posix.h"
+
+static git_repository *_repo;
+static git_revwalk *_revwalker;
+static git_packbuilder *_packbuilder;
+static git_indexer_stream *_indexer;
+static git_vector _commits;
+static int _commits_is_initialized;
+
+void test_pack_packbuilder__initialize(void)
+{
+ _repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_revwalk_new(&_revwalker, _repo));
+ cl_git_pass(git_packbuilder_new(&_packbuilder, _repo));
+ cl_git_pass(git_vector_init(&_commits, 0, NULL));
+ _commits_is_initialized = 1;
+}
+
+void test_pack_packbuilder__cleanup(void)
+{
+ git_oid *o;
+ unsigned int i;
+
+ if (_commits_is_initialized) {
+ _commits_is_initialized = 0;
+ git_vector_foreach(&_commits, i, o) {
+ git__free(o);
+ }
+ git_vector_free(&_commits);
+ }
+
+ git_packbuilder_free(_packbuilder);
+ _packbuilder = NULL;
+
+ git_revwalk_free(_revwalker);
+ _revwalker = NULL;
+
+ git_indexer_stream_free(_indexer);
+ _indexer = NULL;
+
+ cl_git_sandbox_cleanup();
+ _repo = NULL;
+}
+
+static void seed_packbuilder(void)
+{
+ git_oid oid, *o;
+ unsigned int i;
+
+ git_revwalk_sorting(_revwalker, GIT_SORT_TIME);
+ cl_git_pass(git_revwalk_push_ref(_revwalker, "HEAD"));
+
+ while (git_revwalk_next(&oid, _revwalker) == 0) {
+ o = git__malloc(GIT_OID_RAWSZ);
+ cl_assert(o != NULL);
+ git_oid_cpy(o, &oid);
+ cl_git_pass(git_vector_insert(&_commits, o));
+ }
+
+ git_vector_foreach(&_commits, i, o) {
+ cl_git_pass(git_packbuilder_insert(_packbuilder, o, NULL));
+ }
+
+ git_vector_foreach(&_commits, i, o) {
+ git_object *obj;
+ cl_git_pass(git_object_lookup(&obj, _repo, o, GIT_OBJ_COMMIT));
+ cl_git_pass(git_packbuilder_insert_tree(_packbuilder,
+ git_commit_tree_id((git_commit *)obj)));
+ git_object_free(obj);
+ }
+}
+
+static int feed_indexer(void *ptr, size_t len, void *payload)
+{
+ git_transfer_progress *stats = (git_transfer_progress *)payload;
+
+ return git_indexer_stream_add(_indexer, ptr, len, stats);
+}
+
+void test_pack_packbuilder__create_pack(void)
+{
+ git_transfer_progress stats;
+ git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_hash_ctx ctx;
+ git_oid hash;
+ char hex[41]; hex[40] = '\0';
+
+ seed_packbuilder();
+
+ cl_git_pass(git_indexer_stream_new(&_indexer, ".", NULL, NULL));
+ cl_git_pass(git_packbuilder_foreach(_packbuilder, feed_indexer, &stats));
+ cl_git_pass(git_indexer_stream_finalize(_indexer, &stats));
+
+ git_oid_fmt(hex, git_indexer_stream_hash(_indexer));
+ git_buf_printf(&path, "pack-%s.pack", hex);
+
+ /*
+ * By default, packfiles are created with only one thread.
+ * Therefore we can predict the object ordering and make sure
+ * we create exactly the same pack as git.git does when *not*
+ * reusing existing deltas (as libgit2).
+ *
+ * $ cd tests-clar/resources/testrepo.git
+ * $ git rev-list --objects HEAD | \
+ * git pack-objects -q --no-reuse-delta --threads=1 pack
+ * $ sha1sum git-80e61eb315239ef3c53033e37fee43b744d57122.pack
+ * 5d410bdf97cf896f9007681b92868471d636954b
+ *
+ */
+
+ cl_git_pass(git_futils_readbuffer(&buf, git_buf_cstr(&path)));
+
+ cl_git_pass(git_hash_ctx_init(&ctx));
+ cl_git_pass(git_hash_update(&ctx, buf.ptr, buf.size));
+ cl_git_pass(git_hash_final(&hash, &ctx));
+ git_hash_ctx_cleanup(&ctx);
+
+ git_buf_free(&path);
+ git_buf_free(&buf);
+
+ git_oid_fmt(hex, &hash);
+
+ cl_assert_equal_s(hex, "5d410bdf97cf896f9007681b92868471d636954b");
+}
+
+static git_transfer_progress stats;
+static int foreach_cb(void *buf, size_t len, void *payload)
+{
+ git_indexer_stream *idx = (git_indexer_stream *) payload;
+ cl_git_pass(git_indexer_stream_add(idx, buf, len, &stats));
+ return 0;
+}
+
+void test_pack_packbuilder__foreach(void)
+{
+ git_indexer_stream *idx;
+
+ seed_packbuilder();
+ cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL));
+ cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx));
+ cl_git_pass(git_indexer_stream_finalize(idx, &stats));
+ git_indexer_stream_free(idx);
+}
diff --git a/tests-clar/refdb/inmemory.c b/tests-clar/refdb/inmemory.c
new file mode 100644
index 000000000..6f5651964
--- /dev/null
+++ b/tests-clar/refdb/inmemory.c
@@ -0,0 +1,213 @@
+#include "clar_libgit2.h"
+#include "refdb.h"
+#include "repository.h"
+#include "testdb.h"
+
+#define TEST_REPO_PATH "testrepo"
+
+static git_repository *repo;
+static git_refdb *refdb;
+static git_refdb_backend *refdb_backend;
+
+int unlink_ref(void *payload, git_buf *file)
+{
+ GIT_UNUSED(payload);
+ return p_unlink(git_buf_cstr(file));
+}
+
+int empty(void *payload, git_buf *file)
+{
+ GIT_UNUSED(payload);
+ GIT_UNUSED(file);
+ return -1;
+}
+
+int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *filename))
+{
+ const char *repo_path;
+ git_buf repo_refs_dir = GIT_BUF_INIT;
+ int error = 0;
+
+ repo_path = git_repository_path(repo);
+
+ git_buf_joinpath(&repo_refs_dir, repo_path, "HEAD");
+ if (git_path_exists(git_buf_cstr(&repo_refs_dir)) &&
+ cb(NULL, &repo_refs_dir) < 0)
+ return -1;
+
+ git_buf_joinpath(&repo_refs_dir, repo_path, "refs");
+ git_buf_joinpath(&repo_refs_dir, git_buf_cstr(&repo_refs_dir), "heads");
+ if (git_path_direach(&repo_refs_dir, cb, NULL) != 0)
+ return -1;
+
+ git_buf_joinpath(&repo_refs_dir, repo_path, "packed-refs");
+ if (git_path_exists(git_buf_cstr(&repo_refs_dir)) &&
+ cb(NULL, &repo_refs_dir) < 0)
+ return -1;
+
+ git_buf_free(&repo_refs_dir);
+
+ return error;
+}
+
+void test_refdb_inmemory__initialize(void)
+{
+ git_buf repo_refs_dir = GIT_BUF_INIT;
+
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+
+ cl_git_pass(git_repository_refdb(&refdb, repo));
+ cl_git_pass(refdb_backend_test(&refdb_backend, repo));
+ cl_git_pass(git_refdb_set_backend(refdb, refdb_backend));
+
+
+ ref_file_foreach(repo, unlink_ref);
+
+ git_buf_free(&repo_refs_dir);
+}
+
+void test_refdb_inmemory__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refdb_inmemory__doesnt_write_ref_file(void)
+{
+ git_reference *ref;
+ git_oid oid;
+
+ cl_git_pass(git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ cl_git_pass(git_reference_create(&ref, repo, GIT_REFS_HEADS_DIR "test1", &oid, 0));
+
+ ref_file_foreach(repo, empty);
+
+ git_reference_free(ref);
+}
+
+void test_refdb_inmemory__read(void)
+{
+ git_reference *write1, *write2, *write3, *read1, *read2, *read3;
+ git_oid oid1, oid2, oid3;
+
+ cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
+
+ cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
+ cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
+
+ cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
+ cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
+
+
+ cl_git_pass(git_reference_lookup(&read1, repo, GIT_REFS_HEADS_DIR "test1"));
+ cl_assert(strcmp(git_reference_name(read1), git_reference_name(write1)) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(read1), git_reference_target(write1)) == 0);
+
+ cl_git_pass(git_reference_lookup(&read2, repo, GIT_REFS_HEADS_DIR "test2"));
+ cl_assert(strcmp(git_reference_name(read2), git_reference_name(write2)) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(read2), git_reference_target(write2)) == 0);
+
+ cl_git_pass(git_reference_lookup(&read3, repo, GIT_REFS_HEADS_DIR "test3"));
+ cl_assert(strcmp(git_reference_name(read3), git_reference_name(write3)) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(read3), git_reference_target(write3)) == 0);
+
+ git_reference_free(write1);
+ git_reference_free(write2);
+ git_reference_free(write3);
+
+ git_reference_free(read1);
+ git_reference_free(read2);
+ git_reference_free(read3);
+}
+
+int foreach_test(const char *ref_name, void *payload)
+{
+ git_reference *ref;
+ git_oid expected;
+ size_t *i = payload;
+
+ cl_git_pass(git_reference_lookup(&ref, repo, ref_name));
+
+ if (*i == 0)
+ cl_git_pass(git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ else if (*i == 1)
+ cl_git_pass(git_oid_fromstr(&expected, "e90810b8df3e80c413d903f631643c716887138d"));
+ else if (*i == 2)
+ cl_git_pass(git_oid_fromstr(&expected, "763d71aadf09a7951596c9746c024e7eece7c7af"));
+
+ cl_assert(git_oid_cmp(&expected, &ref->target.oid) == 0);
+
+ ++(*i);
+
+ git_reference_free(ref);
+
+ return 0;
+}
+
+void test_refdb_inmemory__foreach(void)
+{
+ git_reference *write1, *write2, *write3;
+ git_oid oid1, oid2, oid3;
+ size_t i = 0;
+
+ cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
+
+ cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
+ cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
+
+ cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
+ cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
+
+ cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, foreach_test, &i));
+ cl_assert_equal_i(i, 3);
+
+ git_reference_free(write1);
+ git_reference_free(write2);
+ git_reference_free(write3);
+}
+
+int delete_test(const char *ref_name, void *payload)
+{
+ git_reference *ref;
+ git_oid expected;
+ size_t *i = payload;
+
+ cl_git_pass(git_reference_lookup(&ref, repo, ref_name));
+
+ cl_git_pass(git_oid_fromstr(&expected, "e90810b8df3e80c413d903f631643c716887138d"));
+ cl_assert(git_oid_cmp(&expected, &ref->target.oid) == 0);
+
+ ++(*i);
+
+ git_reference_free(ref);
+
+ return 0;
+}
+
+void test_refdb_inmemory__delete(void)
+{
+ git_reference *write1, *write2, *write3;
+ git_oid oid1, oid2, oid3;
+ size_t i = 0;
+
+ cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
+
+ cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
+ cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
+
+ cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
+ cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
+
+ git_reference_delete(write1);
+ git_reference_free(write1);
+
+ git_reference_delete(write3);
+ git_reference_free(write3);
+
+ cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, delete_test, &i));
+ cl_assert_equal_i(i, 1);
+
+ git_reference_free(write2);
+}
diff --git a/tests-clar/refdb/testdb.c b/tests-clar/refdb/testdb.c
new file mode 100644
index 000000000..a8e7ba5fe
--- /dev/null
+++ b/tests-clar/refdb/testdb.c
@@ -0,0 +1,217 @@
+#include "common.h"
+#include "vector.h"
+#include "util.h"
+#include <git2/refdb.h>
+#include <git2/refdb_backend.h>
+#include <git2/errors.h>
+#include <git2/repository.h>
+
+typedef struct refdb_test_backend {
+ git_refdb_backend parent;
+
+ git_repository *repo;
+ git_refdb *refdb;
+ git_vector refs;
+} refdb_test_backend;
+
+typedef struct refdb_test_entry {
+ char *name;
+ git_ref_t type;
+
+ union {
+ git_oid oid;
+ char *symbolic;
+ } target;
+} refdb_test_entry;
+
+static int ref_name_cmp(const void *a, const void *b)
+{
+ return strcmp(git_reference_name((git_reference *)a),
+ git_reference_name((git_reference *)b));
+}
+
+static int refdb_test_backend__exists(
+ int *exists,
+ git_refdb_backend *_backend,
+ const char *ref_name)
+{
+ refdb_test_backend *backend;
+ refdb_test_entry *entry;
+ size_t i;
+
+ assert(_backend);
+ backend = (refdb_test_backend *)_backend;
+
+ *exists = 0;
+
+ git_vector_foreach(&backend->refs, i, entry) {
+ if (strcmp(entry->name, ref_name) == 0) {
+ *exists = 1;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int refdb_test_backend__write(
+ git_refdb_backend *_backend,
+ const git_reference *ref)
+{
+ refdb_test_backend *backend;
+ refdb_test_entry *entry;
+
+ assert(_backend);
+ backend = (refdb_test_backend *)_backend;
+
+ entry = git__calloc(1, sizeof(refdb_test_entry));
+ GITERR_CHECK_ALLOC(entry);
+
+ entry->name = git__strdup(git_reference_name(ref));
+ GITERR_CHECK_ALLOC(entry->name);
+
+ entry->type = git_reference_type(ref);
+
+ if (entry->type == GIT_REF_OID)
+ git_oid_cpy(&entry->target.oid, git_reference_target(ref));
+ else {
+ entry->target.symbolic = git__strdup(git_reference_symbolic_target(ref));
+ GITERR_CHECK_ALLOC(entry->target.symbolic);
+ }
+
+ git_vector_insert(&backend->refs, entry);
+
+ return 0;
+}
+
+static int refdb_test_backend__lookup(
+ git_reference **out,
+ git_refdb_backend *_backend,
+ const char *ref_name)
+{
+ refdb_test_backend *backend;
+ refdb_test_entry *entry;
+ size_t i;
+
+ assert(_backend);
+ backend = (refdb_test_backend *)_backend;
+
+ git_vector_foreach(&backend->refs, i, entry) {
+ if (strcmp(entry->name, ref_name) == 0) {
+ const git_oid *oid =
+ entry->type == GIT_REF_OID ? &entry->target.oid : NULL;
+ const char *symbolic =
+ entry->type == GIT_REF_SYMBOLIC ? entry->target.symbolic : NULL;
+
+ if ((*out = git_reference__alloc(backend->refdb, ref_name, oid, symbolic)) == NULL)
+ return -1;
+
+ return 0;
+ }
+ }
+
+ return GIT_ENOTFOUND;
+}
+
+static int refdb_test_backend__foreach(
+ git_refdb_backend *_backend,
+ unsigned int list_flags,
+ git_reference_foreach_cb callback,
+ void *payload)
+{
+ refdb_test_backend *backend;
+ refdb_test_entry *entry;
+ size_t i;
+
+ assert(_backend);
+ backend = (refdb_test_backend *)_backend;
+
+ git_vector_foreach(&backend->refs, i, entry) {
+ if (entry->type == GIT_REF_OID && (list_flags & GIT_REF_OID) == 0)
+ continue;
+
+ if (entry->type == GIT_REF_SYMBOLIC && (list_flags & GIT_REF_SYMBOLIC) == 0)
+ continue;
+
+ if (callback(entry->name, payload) != 0)
+ return GIT_EUSER;
+ }
+
+ return 0;
+}
+
+static void refdb_test_entry_free(refdb_test_entry *entry)
+{
+ if (entry->type == GIT_REF_SYMBOLIC)
+ git__free(entry->target.symbolic);
+
+ git__free(entry->name);
+ git__free(entry);
+}
+
+static int refdb_test_backend__delete(
+ git_refdb_backend *_backend,
+ const git_reference *ref)
+{
+ refdb_test_backend *backend;
+ refdb_test_entry *entry;
+ size_t i;
+
+ assert(_backend);
+ backend = (refdb_test_backend *)_backend;
+
+ git_vector_foreach(&backend->refs, i, entry) {
+ if (strcmp(entry->name, git_reference_name(ref)) == 0) {
+ git_vector_remove(&backend->refs, i);
+ refdb_test_entry_free(entry);
+ }
+ }
+
+ return GIT_ENOTFOUND;
+}
+
+static void refdb_test_backend__free(git_refdb_backend *_backend)
+{
+ refdb_test_backend *backend;
+ refdb_test_entry *entry;
+ size_t i;
+
+ assert(_backend);
+ backend = (refdb_test_backend *)_backend;
+
+ git_vector_foreach(&backend->refs, i, entry)
+ refdb_test_entry_free(entry);
+
+ git_vector_free(&backend->refs);
+ git__free(backend);
+}
+
+int refdb_backend_test(
+ git_refdb_backend **backend_out,
+ git_repository *repo)
+{
+ refdb_test_backend *backend;
+ git_refdb *refdb;
+ int error = 0;
+
+ if ((error = git_repository_refdb(&refdb, repo)) < 0)
+ return error;
+
+ backend = git__calloc(1, sizeof(refdb_test_backend));
+ GITERR_CHECK_ALLOC(backend);
+
+ git_vector_init(&backend->refs, 0, ref_name_cmp);
+
+ backend->repo = repo;
+ backend->refdb = refdb;
+
+ backend->parent.exists = &refdb_test_backend__exists;
+ backend->parent.lookup = &refdb_test_backend__lookup;
+ backend->parent.foreach = &refdb_test_backend__foreach;
+ backend->parent.write = &refdb_test_backend__write;
+ backend->parent.delete = &refdb_test_backend__delete;
+ backend->parent.free = &refdb_test_backend__free;
+
+ *backend_out = (git_refdb_backend *)backend;
+ return 0;
+}
diff --git a/tests-clar/refdb/testdb.h b/tests-clar/refdb/testdb.h
new file mode 100644
index 000000000..e38abd967
--- /dev/null
+++ b/tests-clar/refdb/testdb.h
@@ -0,0 +1,3 @@
+int refdb_backend_test(
+ git_refdb_backend **backend_out,
+ git_repository *repo);
diff --git a/tests-clar/refs/branches/create.c b/tests-clar/refs/branches/create.c
index ad7e1fd2c..693a592a3 100644
--- a/tests-clar/refs/branches/create.c
+++ b/tests-clar/refs/branches/create.c
@@ -1,36 +1,43 @@
#include "clar_libgit2.h"
#include "refs.h"
-#include "branch.h"
static git_repository *repo;
-static git_oid branch_target_oid;
-static git_object *target;
+static git_commit *target;
+static git_reference *branch;
void test_refs_branches_create__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ branch = NULL;
}
void test_refs_branches_create__cleanup(void)
{
- git_object_free(target);
+ git_reference_free(branch);
+ branch = NULL;
+
+ git_commit_free(target);
+ target = NULL;
+
git_repository_free(repo);
+ repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
-static void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha)
+static void retrieve_target_from_oid(git_commit **out, git_repository *repo, const char *sha)
{
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, sha));
- cl_git_pass(git_object_lookup(object_out, repo, &oid, GIT_OBJ_ANY));
+ cl_git_pass(git_commit_lookup(out, repo, &oid));
}
-static void retrieve_known_commit(git_object **object, git_repository *repo)
+static void retrieve_known_commit(git_commit **commit, git_repository *repo)
{
- retrieve_target_from_oid(object, repo, "e90810b8df3e80c413d903f631643c716887138d");
+ retrieve_target_from_oid(commit, repo, "e90810b8df3e80c413d903f631643c716887138d");
}
#define NEW_BRANCH_NAME "new-branch-on-the-block"
@@ -39,75 +46,31 @@ void test_refs_branches_create__can_create_a_local_branch(void)
{
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
- cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
-}
-
-void test_refs_branches_create__creating_a_local_branch_triggers_the_creation_of_a_new_direct_reference(void)
-{
- git_reference *branch;
-
- retrieve_known_commit(&target, repo);
-
- cl_git_fail(git_reference_lookup(&branch, repo, GIT_REFS_HEADS_DIR NEW_BRANCH_NAME));
-
- cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
-
- cl_git_pass(git_reference_lookup(&branch, repo, GIT_REFS_HEADS_DIR NEW_BRANCH_NAME));
- cl_assert(git_reference_type(branch) == GIT_REF_OID);
-
- git_reference_free(branch);
+ cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
+ cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
}
void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with_an_existing_one(void)
{
retrieve_known_commit(&target, repo);
- cl_git_fail(git_branch_create(&branch_target_oid, repo, "br2", target, 0));
+ cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0));
}
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch_target_oid, repo, "br2", target, 1));
- cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
+ cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1));
+ cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
+ cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
}
-void test_refs_branches_create__can_not_create_a_branch_pointing_at_an_object_unknown_from_the_repository(void)
-{
- git_repository *repo2;
-
- /* Open another instance of the same repository */
- cl_git_pass(git_repository_open(&repo2, cl_fixture("testrepo.git")));
-
- /* Retrieve a commit object from this different repository */
- retrieve_known_commit(&target, repo2);
-
- cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
-
- git_repository_free(repo2);
-}
-
-void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_it_to_its_commit(void)
-{
- /* b25fa35 is a tag, pointing to another tag which points to a commit */
- retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
-
- cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
- cl_git_pass(git_oid_streq(&branch_target_oid, "e90810b8df3e80c413d903f631643c716887138d"));
-}
-void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit_object(void)
+void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
- /* 53fc32d is the tree of commit e90810b */
- retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
-
- cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
- git_object_free(target);
-
- /* 521d87c is an annotated tag pointing to a blob */
- retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
+ retrieve_known_commit(&target, repo);
- cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
-}
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_branch_create(&branch, repo, "inv@{id", target, 0));
+} \ No newline at end of file
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 03d3c56d7..7af5a3e86 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "refs.h"
-#include "branch.h"
+#include "repo/repo_helpers.h"
+#include "config/config_helpers.h"
static git_repository *repo;
static git_reference *fake_remote;
@@ -13,79 +14,104 @@ void test_refs_branches_delete__initialize(void)
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
- cl_git_pass(git_reference_create_oid(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0));
+ cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0));
}
void test_refs_branches_delete__cleanup(void)
{
git_reference_free(fake_remote);
+ fake_remote = NULL;
+
git_repository_free(repo);
+ repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
-void test_refs_branches_delete__can_not_delete_a_non_existing_branch(void)
-{
- cl_git_fail(git_branch_delete(repo, "i-am-not-a-local-branch", GIT_BRANCH_LOCAL));
- cl_git_fail(git_branch_delete(repo, "neither/a-remote-one", GIT_BRANCH_REMOTE));
-}
-
void test_refs_branches_delete__can_not_delete_a_branch_pointed_at_by_HEAD(void)
{
git_reference *head;
+ git_reference *branch;
/* Ensure HEAD targets the local master branch */
cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
- cl_assert(strcmp("refs/heads/master", git_reference_target(head)) == 0);
+ cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
git_reference_free(head);
- cl_git_fail(git_branch_delete(repo, "master", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
+ cl_git_fail(git_branch_delete(branch));
+ git_reference_free(branch);
}
-void test_refs_branches_delete__can_not_delete_a_branch_if_HEAD_is_missing(void)
+void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void)
{
git_reference *head;
+ git_reference *branch;
cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
git_reference_delete(head);
+ git_reference_free(head);
- cl_git_fail(git_branch_delete(repo, "br2", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+ git_reference_free(branch);
+}
+
+void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void)
+{
+ git_reference *branch;
+
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+ git_reference_free(branch);
}
void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void)
{
- git_reference *master, *head;
+ git_reference *head, *branch;
- /* Detach HEAD and make it target the commit that "master" points to */
- cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
- cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", git_reference_oid(master), 1));
+ cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
+ cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
git_reference_free(head);
- git_reference_free(master);
- cl_git_pass(git_branch_delete(repo, "master", GIT_BRANCH_LOCAL));
+ /* Detach HEAD and make it target the commit that "master" points to */
+ git_repository_detach_head(repo);
+
+ cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+ git_reference_free(branch);
}
void test_refs_branches_delete__can_delete_a_local_branch(void)
{
- cl_git_pass(git_branch_delete(repo, "br2", GIT_BRANCH_LOCAL));
+ git_reference *branch;
+ cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+ git_reference_free(branch);
}
void test_refs_branches_delete__can_delete_a_remote_branch(void)
{
- cl_git_pass(git_branch_delete(repo, "nulltoken/master", GIT_BRANCH_REMOTE));
+ git_reference *branch;
+ cl_git_pass(git_branch_lookup(&branch, repo, "nulltoken/master", GIT_BRANCH_REMOTE));
+ cl_git_pass(git_branch_delete(branch));
+ git_reference_free(branch);
}
-static void assert_non_exisitng_branch_removal(const char *branch_name, git_branch_t branch_type)
+void test_refs_branches_delete__deleting_a_branch_removes_related_configuration_data(void)
{
- int error;
- error = git_branch_delete(repo, branch_name, branch_type);
+ git_reference *branch;
- cl_git_fail(error);
- cl_assert_equal_i(GIT_ENOTFOUND, error);
-}
+ assert_config_entry_existence(repo, "branch.track-local.remote", true);
+ assert_config_entry_existence(repo, "branch.track-local.merge", true);
-void test_refs_branches_delete__deleting_a_non_existing_branch_returns_ENOTFOUND(void)
-{
- assert_non_exisitng_branch_removal("i-do-not-locally-exist", GIT_BRANCH_LOCAL);
- assert_non_exisitng_branch_removal("neither/remotely", GIT_BRANCH_REMOTE);
+ cl_git_pass(git_branch_lookup(&branch, repo, "track-local", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+ git_reference_free(branch);
+
+ assert_config_entry_existence(repo, "branch.track-local.remote", false);
+ assert_config_entry_existence(repo, "branch.track-local.merge", false);
}
diff --git a/tests-clar/refs/branches/foreach.c b/tests-clar/refs/branches/foreach.c
new file mode 100644
index 000000000..96a5bc2b9
--- /dev/null
+++ b/tests-clar/refs/branches/foreach.c
@@ -0,0 +1,155 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_reference *fake_remote;
+
+void test_refs_branches_foreach__initialize(void)
+{
+ git_oid id;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
+ cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0));
+}
+
+void test_refs_branches_foreach__cleanup(void)
+{
+ git_reference_free(fake_remote);
+ fake_remote = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_fixture_cleanup("testrepo.git");
+}
+
+static int count_branch_list_cb(const char *branch_name, git_branch_t branch_type, void *payload)
+{
+ int *count;
+
+ GIT_UNUSED(branch_type);
+ GIT_UNUSED(branch_name);
+
+ count = (int *)payload;
+ (*count)++;
+
+ return 0;
+}
+
+static void assert_retrieval(unsigned int flags, unsigned int expected_count)
+{
+ int count = 0;
+
+ cl_git_pass(git_branch_foreach(repo, flags, count_branch_list_cb, &count));
+
+ cl_assert_equal_i(expected_count, count);
+}
+
+void test_refs_branches_foreach__retrieve_all_branches(void)
+{
+ assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 14);
+}
+
+void test_refs_branches_foreach__retrieve_remote_branches(void)
+{
+ assert_retrieval(GIT_BRANCH_REMOTE, 2);
+}
+
+void test_refs_branches_foreach__retrieve_local_branches(void)
+{
+ assert_retrieval(GIT_BRANCH_LOCAL, 12);
+}
+
+struct expectations {
+ const char *branch_name;
+ int encounters;
+};
+
+static void assert_branch_has_been_found(struct expectations *findings, const char* expected_branch_name)
+{
+ int pos = 0;
+
+ while (findings[pos].branch_name)
+ {
+ if (strcmp(expected_branch_name, findings[pos].branch_name) == 0) {
+ cl_assert_equal_i(1, findings[pos].encounters);
+ return;
+ }
+
+ pos++;
+ }
+
+ cl_fail("expected branch not found in list.");
+}
+
+static int contains_branch_list_cb(const char *branch_name, git_branch_t branch_type, void *payload)
+{
+ int pos = 0;
+ struct expectations *exp;
+
+ GIT_UNUSED(branch_type);
+
+ exp = (struct expectations *)payload;
+
+ while (exp[pos].branch_name)
+ {
+ if (strcmp(branch_name, exp[pos].branch_name) == 0)
+ exp[pos].encounters++;
+
+ pos++;
+ }
+
+ return 0;
+}
+
+/*
+ * $ git branch -r
+ * nulltoken/HEAD -> nulltoken/master
+ * nulltoken/master
+ */
+void test_refs_branches_foreach__retrieve_remote_symbolic_HEAD_when_present(void)
+{
+ struct expectations exp[] = {
+ { "nulltoken/HEAD", 0 },
+ { "nulltoken/master", 0 },
+ { NULL, 0 }
+ };
+
+ git_reference_free(fake_remote);
+ cl_git_pass(git_reference_symbolic_create(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0));
+
+ assert_retrieval(GIT_BRANCH_REMOTE, 3);
+
+ cl_git_pass(git_branch_foreach(repo, GIT_BRANCH_REMOTE, contains_branch_list_cb, &exp));
+
+ assert_branch_has_been_found(exp, "nulltoken/HEAD");
+ assert_branch_has_been_found(exp, "nulltoken/HEAD");
+}
+
+static int branch_list_interrupt_cb(
+ const char *branch_name, git_branch_t branch_type, void *payload)
+{
+ int *count;
+
+ GIT_UNUSED(branch_type);
+ GIT_UNUSED(branch_name);
+
+ count = (int *)payload;
+ (*count)++;
+
+ return (*count == 5);
+}
+
+void test_refs_branches_foreach__can_cancel(void)
+{
+ int count = 0;
+
+ cl_assert_equal_i(GIT_EUSER,
+ git_branch_foreach(repo, GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE,
+ branch_list_interrupt_cb, &count));
+
+ cl_assert_equal_i(5, count);
+}
diff --git a/tests-clar/refs/branches/ishead.c b/tests-clar/refs/branches/ishead.c
new file mode 100644
index 000000000..dfcf1b5f1
--- /dev/null
+++ b/tests-clar/refs/branches/ishead.c
@@ -0,0 +1,116 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "repo/repo_helpers.h"
+
+static git_repository *repo;
+static git_reference *branch;
+
+void test_refs_branches_ishead__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+}
+
+void test_refs_branches_ishead__cleanup(void)
+{
+ git_reference_free(branch);
+ branch = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+}
+
+void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
+
+ cl_assert_equal_i(true, git_branch_is_head(branch));
+}
+
+void test_refs_branches_ishead__can_properly_handle_orphaned_HEAD(void)
+{
+ git_repository_free(repo);
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
+
+ cl_assert_equal_i(false, git_branch_is_head(branch));
+
+ cl_git_sandbox_cleanup();
+ repo = NULL;
+}
+
+void test_refs_branches_ishead__can_properly_handle_missing_HEAD(void)
+{
+ git_repository_free(repo);
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ delete_head(repo);
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
+
+ cl_assert_equal_i(false, git_branch_is_head(branch));
+
+ cl_git_sandbox_cleanup();
+ repo = NULL;
+}
+
+void test_refs_branches_ishead__can_tell_if_a_branch_is_not_pointed_at_by_HEAD(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/br2"));
+
+ cl_assert_equal_i(false, git_branch_is_head(branch));
+}
+
+void test_refs_branches_ishead__wont_be_fooled_by_a_non_branch(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/tags/e90810b"));
+
+ cl_assert_equal_i(false, git_branch_is_head(branch));
+}
+
+/*
+ * $ git init .
+ * Initialized empty Git repository in d:/temp/tempee/.git/
+ *
+ * $ touch a && git add a
+ * $ git commit -m" boom"
+ * [master (root-commit) b47b758] boom
+ * 0 files changed
+ * create mode 100644 a
+ *
+ * $ echo "ref: refs/heads/master" > .git/refs/heads/linked
+ * $ echo "ref: refs/heads/linked" > .git/refs/heads/super
+ * $ echo "ref: refs/heads/super" > .git/HEAD
+ *
+ * $ git branch
+ * linked -> master
+ * * master
+ * super -> master
+ */
+void test_refs_branches_ishead__only_direct_references_are_considered(void)
+{
+ git_reference *linked, *super, *head;
+
+ git_repository_free(repo);
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_reference_symbolic_create(&linked, repo, "refs/heads/linked", "refs/heads/master", 0));
+ cl_git_pass(git_reference_symbolic_create(&super, repo, "refs/heads/super", "refs/heads/linked", 0));
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/heads/super", 1));
+
+ cl_assert_equal_i(false, git_branch_is_head(linked));
+ cl_assert_equal_i(false, git_branch_is_head(super));
+
+ cl_git_pass(git_repository_head(&branch, repo));
+ cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
+
+ git_reference_free(linked);
+ git_reference_free(super);
+ git_reference_free(head);
+ cl_git_sandbox_cleanup();
+ repo = NULL;
+}
diff --git a/tests-clar/refs/branches/listall.c b/tests-clar/refs/branches/listall.c
deleted file mode 100644
index 0a5634fb4..000000000
--- a/tests-clar/refs/branches/listall.c
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "clar_libgit2.h"
-#include "refs.h"
-#include "branch.h"
-
-static git_repository *repo;
-static git_strarray branch_list;
-static git_reference *fake_remote;
-
-void test_refs_branches_listall__initialize(void)
-{
- git_oid id;
-
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
-
- cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
- cl_git_pass(git_reference_create_oid(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0));
-}
-
-void test_refs_branches_listall__cleanup(void)
-{
- git_strarray_free(&branch_list);
- git_reference_free(fake_remote);
- git_repository_free(repo);
-
- cl_fixture_cleanup("testrepo.git");
-}
-
-static void assert_retrieval(unsigned int flags, unsigned int expected_count)
-{
- cl_git_pass(git_branch_list(&branch_list, repo, flags));
-
- cl_assert_equal_i(expected_count, branch_list.count);
-}
-
-void test_refs_branches_listall__retrieve_all_branches(void)
-{
- assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 6 + 1);
-}
-
-void test_refs_branches_listall__retrieve_remote_branches(void)
-{
- assert_retrieval(GIT_BRANCH_REMOTE, 1);
-}
-
-void test_refs_branches_listall__retrieve_local_branches(void)
-{
- assert_retrieval(GIT_BRANCH_LOCAL, 6);
-}
-
-static void assert_branch_list_contains(git_strarray *branches, const char* expected_branch_name)
-{
- unsigned int i;
-
- for (i = 0; i < branches->count; i++) {
- if (strcmp(expected_branch_name, branches->strings[i]) == 0)
- return;
- }
-
- cl_fail("expected branch not found in list.");
-}
-
-/*
- * $ git branch -r
- * nulltoken/HEAD -> nulltoken/master
- * nulltoken/master
- */
-void test_refs_branches_listall__retrieve_remote_symbolic_HEAD_when_present(void)
-{
- git_reference_free(fake_remote);
- cl_git_pass(git_reference_create_symbolic(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0));
-
- cl_git_pass(git_branch_list(&branch_list, repo, GIT_BRANCH_REMOTE));
-
- cl_assert_equal_i(2, branch_list.count);
- assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/HEAD");
- assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/master");
-}
diff --git a/tests-clar/refs/branches/lookup.c b/tests-clar/refs/branches/lookup.c
new file mode 100644
index 000000000..95d49a4b3
--- /dev/null
+++ b/tests-clar/refs/branches/lookup.c
@@ -0,0 +1,45 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_reference *branch;
+
+void test_refs_branches_lookup__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ branch = NULL;
+}
+
+void test_refs_branches_lookup__cleanup(void)
+{
+ git_reference_free(branch);
+ branch = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+}
+
+void test_refs_branches_lookup__can_retrieve_a_local_branch(void)
+{
+ cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
+}
+
+void test_refs_branches_lookup__can_retrieve_a_remote_tracking_branch(void)
+{
+ cl_git_pass(git_branch_lookup(&branch, repo, "test/master", GIT_BRANCH_REMOTE));
+}
+
+void test_refs_branches_lookup__trying_to_retrieve_an_unknown_branch_returns_ENOTFOUND(void)
+{
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "where/are/you", GIT_BRANCH_LOCAL));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "over/here", GIT_BRANCH_REMOTE));
+}
+
+void test_refs_branches_lookup__trying_to_retrieve_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_branch_lookup(&branch, repo, "are/you/inv@{id", GIT_BRANCH_LOCAL));
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_branch_lookup(&branch, repo, "yes/i am", GIT_BRANCH_REMOTE));
+}
diff --git a/tests-clar/refs/branches/move.c b/tests-clar/refs/branches/move.c
index 242e5cd01..7267f941d 100644
--- a/tests-clar/refs/branches/move.c
+++ b/tests-clar/refs/branches/move.c
@@ -1,72 +1,146 @@
#include "clar_libgit2.h"
-#include "branch.h"
+#include "refs.h"
+#include "config/config_helpers.h"
static git_repository *repo;
void test_refs_branches_move__initialize(void)
{
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ repo = cl_git_sandbox_init("testrepo.git");
}
void test_refs_branches_move__cleanup(void)
{
- git_repository_free(repo);
-
- cl_fixture_cleanup("testrepo.git");
+ cl_git_sandbox_cleanup();
}
#define NEW_BRANCH_NAME "new-branch-on-the-block"
void test_refs_branches_move__can_move_a_local_branch(void)
{
- cl_git_pass(git_branch_move(repo, "br2", NEW_BRANCH_NAME, 0));
+ git_reference *original_ref, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
+
+ cl_git_pass(git_branch_move(&new_ref, original_ref, NEW_BRANCH_NAME, 0));
+ cl_assert_equal_s(GIT_REFS_HEADS_DIR NEW_BRANCH_NAME, git_reference_name(new_ref));
+
+ git_reference_free(original_ref);
+ git_reference_free(new_ref);
}
void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(void)
{
+ git_reference *original_ref, *new_ref, *newer_ref;
+
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
+
/* Downward */
- cl_git_pass(git_branch_move(repo, "br2", "somewhere/" NEW_BRANCH_NAME, 0));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, "somewhere/" NEW_BRANCH_NAME, 0));
+ git_reference_free(original_ref);
/* Upward */
- cl_git_pass(git_branch_move(repo, "somewhere/" NEW_BRANCH_NAME, "br2", 0));
+ cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0));
+ git_reference_free(new_ref);
+
+ git_reference_free(newer_ref);
}
void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_namespace(void)
{
+ git_reference *original_ref, *new_ref, *newer_ref;
+
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
+
/* Downward */
- cl_git_pass(git_branch_move(repo, "br2", "br2/" NEW_BRANCH_NAME, 0));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, "br2/" NEW_BRANCH_NAME, 0));
+ git_reference_free(original_ref);
/* Upward */
- cl_git_pass(git_branch_move(repo, "br2/" NEW_BRANCH_NAME, "br2", 0));
+ cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0));
+ git_reference_free(new_ref);
+
+ git_reference_free(newer_ref);
}
void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
{
- cl_git_fail(git_branch_move(repo, "br2", "master", 0));
+ git_reference *original_ref, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
+
+ cl_assert_equal_i(GIT_EEXISTS, git_branch_move(&new_ref, original_ref, "master", 0));
+
+ git_reference_free(original_ref);
}
-void test_refs_branches_move__can_not_move_a_non_existing_branch(void)
+void test_refs_branches_move__moving_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
- cl_git_fail(git_branch_move(repo, "i-am-no-branch", NEW_BRANCH_NAME, 0));
+ git_reference *original_ref, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_branch_move(&new_ref, original_ref, "Inv@{id", 0));
+
+ git_reference_free(original_ref);
+}
+
+void test_refs_branches_move__can_not_move_a_non_branch(void)
+{
+ git_reference *tag, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&tag, repo, "refs/tags/e90810b"));
+ cl_git_fail(git_branch_move(&new_ref, tag, NEW_BRANCH_NAME, 0));
+
+ git_reference_free(tag);
}
void test_refs_branches_move__can_force_move_over_an_existing_branch(void)
{
- cl_git_pass(git_branch_move(repo, "br2", "master", 1));
+ git_reference *original_ref, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
+
+ cl_git_pass(git_branch_move(&new_ref, original_ref, "master", 1));
+
+ git_reference_free(original_ref);
+ git_reference_free(new_ref);
}
-void test_refs_branches_move__can_not_move_a_branch_through_its_canonical_name(void)
+void test_refs_branches_move__moving_a_branch_moves_related_configuration_data(void)
{
- cl_git_fail(git_branch_move(repo, "refs/heads/br2", NEW_BRANCH_NAME, 1));
+ git_reference *branch;
+ git_reference *new_branch;
+
+ cl_git_pass(git_branch_lookup(&branch, repo, "track-local", GIT_BRANCH_LOCAL));
+
+ assert_config_entry_existence(repo, "branch.track-local.remote", true);
+ assert_config_entry_existence(repo, "branch.track-local.merge", true);
+ assert_config_entry_existence(repo, "branch.moved.remote", false);
+ assert_config_entry_existence(repo, "branch.moved.merge", false);
+
+ cl_git_pass(git_branch_move(&new_branch, branch, "moved", 0));
+ git_reference_free(branch);
+
+ assert_config_entry_existence(repo, "branch.track-local.remote", false);
+ assert_config_entry_existence(repo, "branch.track-local.merge", false);
+ assert_config_entry_existence(repo, "branch.moved.remote", true);
+ assert_config_entry_existence(repo, "branch.moved.merge", true);
+
+ git_reference_free(new_branch);
}
-void test_refs_branches_move__moving_a_non_exisiting_branch_returns_ENOTFOUND(void)
+void test_refs_branches_move__moving_the_branch_pointed_at_by_HEAD_updates_HEAD(void)
{
- int error;
+ git_reference *branch;
+ git_reference *new_branch;
- error = git_branch_move(repo, "where/am/I", NEW_BRANCH_NAME, 0);
- cl_git_fail(error);
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
+ cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
+ git_reference_free(branch);
+ git_reference_free(new_branch);
- cl_assert_equal_i(GIT_ENOTFOUND, error);
+ cl_git_pass(git_repository_head(&branch, repo));
+ cl_assert_equal_s("refs/heads/master2", git_reference_name(branch));
+ git_reference_free(branch);
}
diff --git a/tests-clar/refs/branches/name.c b/tests-clar/refs/branches/name.c
new file mode 100644
index 000000000..176f836a4
--- /dev/null
+++ b/tests-clar/refs/branches/name.c
@@ -0,0 +1,45 @@
+#include "clar_libgit2.h"
+#include "branch.h"
+
+static git_repository *repo;
+static git_reference *ref;
+
+void test_refs_branches_name__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+}
+
+void test_refs_branches_name__cleanup(void)
+{
+ git_reference_free(ref);
+ ref = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+}
+
+void test_refs_branches_name__can_get_local_branch_name(void)
+{
+ const char *name;
+
+ cl_git_pass(git_branch_lookup(&ref,repo,"master",GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_name(&name,ref));
+ cl_assert_equal_s("master",name);
+}
+
+void test_refs_branches_name__can_get_remote_branch_name(void)
+{
+ const char *name;
+
+ cl_git_pass(git_branch_lookup(&ref,repo,"test/master",GIT_BRANCH_REMOTE));
+ cl_git_pass(git_branch_name(&name,ref));
+ cl_assert_equal_s("test/master",name);
+}
+
+void test_refs_branches_name__error_when_ref_is_no_branch(void)
+{
+ const char *name;
+
+ cl_git_pass(git_reference_lookup(&ref,repo,"refs/notes/fanout"));
+ cl_git_fail(git_branch_name(&name,ref));
+}
diff --git a/tests-clar/refs/branches/remote.c b/tests-clar/refs/branches/remote.c
new file mode 100644
index 000000000..2beef3724
--- /dev/null
+++ b/tests-clar/refs/branches/remote.c
@@ -0,0 +1,79 @@
+#include "clar_libgit2.h"
+#include "branch.h"
+#include "remote.h"
+
+static git_repository *g_repo;
+static const char *remote_tracking_branch_name = "refs/remotes/test/master";
+static const char *expected_remote_name = "test";
+static int expected_remote_name_length;
+
+void test_refs_branches_remote__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+
+ expected_remote_name_length = (int)strlen(expected_remote_name) + 1;
+}
+
+void test_refs_branches_remote__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_branches_remote__can_get_remote_for_branch(void)
+{
+ char remotename[1024] = {0};
+
+ cl_assert_equal_i(expected_remote_name_length,
+ git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name));
+
+ cl_assert_equal_i(expected_remote_name_length,
+ git_branch_remote_name(remotename, expected_remote_name_length, g_repo,
+ remote_tracking_branch_name));
+
+ cl_assert_equal_s("test", remotename);
+}
+
+void test_refs_branches_remote__insufficient_buffer_returns_error(void)
+{
+ char remotename[1024] = {0};
+
+ cl_assert_equal_i(expected_remote_name_length,
+ git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name));
+
+ cl_git_fail_with(git_branch_remote_name(remotename,
+ expected_remote_name_length - 1, g_repo, remote_tracking_branch_name),
+ expected_remote_name_length);
+}
+
+void test_refs_branches_remote__no_matching_remote_returns_error(void)
+{
+ const char *unknown = "refs/remotes/nonexistent/master";
+
+ cl_git_fail_with(git_branch_remote_name(
+ NULL, 0, g_repo, unknown), GIT_ENOTFOUND);
+}
+
+void test_refs_branches_remote__local_remote_returns_error(void)
+{
+ const char *local = "refs/heads/master";
+
+ cl_git_fail_with(git_branch_remote_name(
+ NULL, 0, g_repo, local), GIT_ERROR);
+}
+
+void test_refs_branches_remote__ambiguous_remote_returns_error(void)
+{
+ git_remote *remote;
+
+ /* Create the remote */
+ cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2"));
+
+ /* Update the remote fetch spec */
+ cl_git_pass(git_remote_set_fetchspec(remote, "refs/heads/*:refs/remotes/test/*"));
+ cl_git_pass(git_remote_save(remote));
+
+ git_remote_free(remote);
+
+ cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo,
+ remote_tracking_branch_name), GIT_EAMBIGUOUS);
+}
diff --git a/tests-clar/refs/branches/upstream.c b/tests-clar/refs/branches/upstream.c
new file mode 100644
index 000000000..2d0ebd240
--- /dev/null
+++ b/tests-clar/refs/branches/upstream.c
@@ -0,0 +1,130 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_reference *branch, *upstream;
+
+void test_refs_branches_upstream__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ branch = NULL;
+ upstream = NULL;
+}
+
+void test_refs_branches_upstream__cleanup(void)
+{
+ git_reference_free(upstream);
+ git_reference_free(branch);
+ branch = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+}
+
+void test_refs_branches_upstream__can_retrieve_the_remote_tracking_reference_of_a_local_branch(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
+
+ cl_git_pass(git_branch_upstream(&upstream, branch));
+
+ cl_assert_equal_s("refs/remotes/test/master", git_reference_name(upstream));
+}
+
+void test_refs_branches_upstream__can_retrieve_the_local_upstream_reference_of_a_local_branch(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/track-local"));
+
+ cl_git_pass(git_branch_upstream(&upstream, branch));
+
+ cl_assert_equal_s("refs/heads/master", git_reference_name(upstream));
+}
+
+void test_refs_branches_upstream__cannot_retrieve_a_remote_upstream_reference_from_a_non_branch(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/tags/e90810b"));
+
+ cl_git_fail(git_branch_upstream(&upstream, branch));
+}
+
+void test_refs_branches_upstream__trying_to_retrieve_a_remote_tracking_reference_from_a_plain_local_branch_returns_GIT_ENOTFOUND(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/subtrees"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
+}
+
+void test_refs_branches_upstream__trying_to_retrieve_a_remote_tracking_reference_from_a_branch_with_no_fetchspec_returns_GIT_ENOTFOUND(void)
+{
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/cannot-fetch"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
+}
+
+static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name)
+{
+ git_reference *branch;
+
+ cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type((git_object*)target));
+ cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
+
+ git_reference_free(branch);
+}
+
+void test_refs_branches_upstream__retrieve_a_remote_tracking_reference_from_a_branch_with_no_remote_returns_GIT_ENOTFOUND(void)
+{
+ git_reference *head;
+ git_repository *repository;
+ git_commit *target;
+
+ repository = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_repository_head(&head, repository));
+ cl_git_pass(git_reference_peel(((git_object **)&target), head, GIT_OBJ_COMMIT));
+ git_reference_free(head);
+
+ assert_merge_and_or_remote_key_missing(repository, target, "remoteless");
+ assert_merge_and_or_remote_key_missing(repository, target, "mergeless");
+ assert_merge_and_or_remote_key_missing(repository, target, "mergeandremoteless");
+
+ git_commit_free(target);
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_branches_upstream__set_unset_upstream(void)
+{
+ git_reference *branch;
+ git_repository *repository;
+ const char *value;
+ git_config *config;
+
+ repository = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
+ cl_git_pass(git_branch_set_upstream(branch, "test/master"));
+
+ cl_git_pass(git_repository_config(&config, repository));
+ cl_git_pass(git_config_get_string(&value, config, "branch.test.remote"));
+ cl_assert_equal_s(value, "test");
+ cl_git_pass(git_config_get_string(&value, config, "branch.test.merge"));
+ cl_assert_equal_s(value, "refs/heads/master");
+
+ cl_git_pass(git_branch_set_upstream(branch, NULL));
+ cl_git_fail_with(git_config_get_string(&value, config, "branch.test.merge"), GIT_ENOTFOUND);
+ cl_git_fail_with(git_config_get_string(&value, config, "branch.test.remote"), GIT_ENOTFOUND);
+
+ git_reference_free(branch);
+
+ cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/master"));
+ cl_git_pass(git_branch_set_upstream(branch, NULL));
+ cl_git_fail_with(git_config_get_string(&value, config, "branch.master.merge"), GIT_ENOTFOUND);
+ cl_git_fail_with(git_config_get_string(&value, config, "branch.master.remote"), GIT_ENOTFOUND);
+
+ git_reference_free(branch);
+
+ git_config_free(config);
+ cl_git_sandbox_cleanup();
+}
diff --git a/tests-clar/refs/branches/upstreamname.c b/tests-clar/refs/branches/upstreamname.c
new file mode 100644
index 000000000..f05607d44
--- /dev/null
+++ b/tests-clar/refs/branches/upstreamname.c
@@ -0,0 +1,42 @@
+#include "clar_libgit2.h"
+#include "branch.h"
+
+static git_repository *repo;
+static git_buf upstream_name;
+
+void test_refs_branches_upstreamname__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ git_buf_init(&upstream_name, 0);
+}
+
+void test_refs_branches_upstreamname__cleanup(void)
+{
+ git_buf_free(&upstream_name);
+
+ git_repository_free(repo);
+ repo = NULL;
+}
+
+void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference_name_of_a_local_branch(void)
+{
+ cl_git_pass(git_branch_upstream__name(
+ &upstream_name, repo, "refs/heads/master"));
+
+ cl_assert_equal_s("refs/remotes/test/master", git_buf_cstr(&upstream_name));
+}
+
+void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_name_of_a_local_branch(void)
+{
+ cl_git_pass(git_branch_upstream__name(
+ &upstream_name, repo, "refs/heads/track-local"));
+
+ cl_assert_equal_s("refs/heads/master", git_buf_cstr(&upstream_name));
+}
+
+void test_refs_branches_upstreamname__can_return_the_size_of_thelocal_upstream_reference_name_of_a_local_branch(void)
+{
+ cl_assert_equal_i((int)strlen("refs/heads/master") + 1,
+ git_branch_upstream_name(NULL, 0, repo, "refs/heads/track-local"));
+}
diff --git a/tests-clar/refs/crashes.c b/tests-clar/refs/crashes.c
index e1b289ace..5a1885a7a 100644
--- a/tests-clar/refs/crashes.c
+++ b/tests-clar/refs/crashes.c
@@ -7,11 +7,14 @@ void test_refs_crashes__double_free(void)
const char *REFNAME = "refs/heads/xxx";
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_reference_create_symbolic(&ref, repo, REFNAME, "refs/heads/master", 0));
+ cl_git_pass(git_reference_symbolic_create(&ref, repo, REFNAME, "refs/heads/master", 0));
cl_git_pass(git_reference_lookup(&ref2, repo, REFNAME));
cl_git_pass(git_reference_delete(ref));
+ git_reference_free(ref);
+ git_reference_free(ref2);
+
/* reference is gone from disk, so reloading it will fail */
- cl_git_fail(git_reference_reload(ref2));
+ cl_git_fail(git_reference_lookup(&ref2, repo, REFNAME));
git_repository_free(repo);
}
diff --git a/tests-clar/refs/create.c b/tests-clar/refs/create.c
index dde4c5745..85ff05aa9 100644
--- a/tests-clar/refs/create.c
+++ b/tests-clar/refs/create.c
@@ -3,8 +3,9 @@
#include "repository.h"
#include "git2/reflog.h"
#include "reflog.h"
+#include "ref_helpers.h"
-static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
+static const char *current_master_tip = "099fabac3a9ea935598528c27f866e34089c2eff";
static const char *current_head_target = "refs/heads/master";
static git_repository *g_repo;
@@ -25,23 +26,18 @@ void test_refs_create__symbolic(void)
git_reference *new_reference, *looked_up_ref, *resolved_ref;
git_repository *repo2;
git_oid id;
- git_buf ref_path = GIT_BUF_INIT;
- const char *new_head_tracker = "another-head-tracker";
+ const char *new_head_tracker = "ANOTHER_HEAD_TRACKER";
git_oid_fromstr(&id, current_master_tip);
- /* Retrieve the physical path to the symbolic ref for further cleaning */
- cl_git_pass(git_buf_joinpath(&ref_path, g_repo->path_repository, new_head_tracker));
- git_buf_free(&ref_path);
-
/* Create and write the new symbolic reference */
- cl_git_pass(git_reference_create_symbolic(&new_reference, g_repo, new_head_tracker, current_head_target, 0));
+ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0));
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker));
cl_assert(git_reference_type(looked_up_ref) & GIT_REF_SYMBOLIC);
- cl_assert(git_reference_is_packed(looked_up_ref) == 0);
+ cl_assert(reference_is_packed(looked_up_ref) == 0);
cl_assert_equal_s(looked_up_ref->name, new_head_tracker);
/* ...peeled.. */
@@ -49,7 +45,7 @@ void test_refs_create__symbolic(void)
cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID);
/* ...and that it points to the current master tip */
- cl_assert(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0);
+ cl_assert(git_oid_cmp(&id, git_reference_target(resolved_ref)) == 0);
git_reference_free(looked_up_ref);
git_reference_free(resolved_ref);
@@ -58,7 +54,7 @@ void test_refs_create__symbolic(void)
cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker));
cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
- cl_assert(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0);
+ cl_assert(git_oid_cmp(&id, git_reference_target(resolved_ref)) == 0);
git_repository_free(repo2);
@@ -72,22 +68,19 @@ void test_refs_create__deep_symbolic(void)
// create a deep symbolic reference
git_reference *new_reference, *looked_up_ref, *resolved_ref;
git_oid id;
- git_buf ref_path = GIT_BUF_INIT;
const char *new_head_tracker = "deep/rooted/tracker";
git_oid_fromstr(&id, current_master_tip);
- cl_git_pass(git_buf_joinpath(&ref_path, g_repo->path_repository, new_head_tracker));
- cl_git_pass(git_reference_create_symbolic(&new_reference, g_repo, new_head_tracker, current_head_target, 0));
+ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0));
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker));
cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
- cl_assert(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0);
+ cl_assert(git_oid_cmp(&id, git_reference_target(resolved_ref)) == 0);
git_reference_free(new_reference);
git_reference_free(looked_up_ref);
git_reference_free(resolved_ref);
- git_buf_free(&ref_path);
}
void test_refs_create__oid(void)
@@ -96,39 +89,34 @@ void test_refs_create__oid(void)
git_reference *new_reference, *looked_up_ref;
git_repository *repo2;
git_oid id;
- git_buf ref_path = GIT_BUF_INIT;
const char *new_head = "refs/heads/new-head";
git_oid_fromstr(&id, current_master_tip);
- /* Retrieve the physical path to the symbolic ref for further cleaning */
- cl_git_pass(git_buf_joinpath(&ref_path, g_repo->path_repository, new_head));
-
/* Create and write the new object id reference */
- cl_git_pass(git_reference_create_oid(&new_reference, g_repo, new_head, &id, 0));
+ cl_git_pass(git_reference_create(&new_reference, g_repo, new_head, &id, 0));
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head));
cl_assert(git_reference_type(looked_up_ref) & GIT_REF_OID);
- cl_assert(git_reference_is_packed(looked_up_ref) == 0);
+ cl_assert(reference_is_packed(looked_up_ref) == 0);
cl_assert_equal_s(looked_up_ref->name, new_head);
/* ...and that it points to the current master tip */
- cl_assert(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0);
+ cl_assert(git_oid_cmp(&id, git_reference_target(looked_up_ref)) == 0);
git_reference_free(looked_up_ref);
/* Similar test with a fresh new repository */
cl_git_pass(git_repository_open(&repo2, "testrepo"));
cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head));
- cl_assert(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0);
+ cl_assert(git_oid_cmp(&id, git_reference_target(looked_up_ref)) == 0);
git_repository_free(repo2);
git_reference_free(new_reference);
git_reference_free(looked_up_ref);
- git_buf_free(&ref_path);
}
void test_refs_create__oid_unknown(void)
@@ -142,8 +130,39 @@ void test_refs_create__oid_unknown(void)
git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644");
/* Create and write the new object id reference */
- cl_git_fail(git_reference_create_oid(&new_reference, g_repo, new_head, &id, 0));
+ cl_git_fail(git_reference_create(&new_reference, g_repo, new_head, &id, 0));
/* Ensure the reference can't be looked-up... */
cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, new_head));
}
+
+void test_refs_create__propagate_eexists(void)
+{
+ int error;
+ git_oid oid;
+ git_reference *ref;
+
+ /* Make sure it works for oid and for symbolic both */
+ git_oid_fromstr(&oid, current_master_tip);
+ error = git_reference_create(&ref, g_repo, current_head_target, &oid, false);
+ cl_assert(error == GIT_EEXISTS);
+
+ error = git_reference_symbolic_create(&ref, g_repo, "HEAD", current_head_target, false);
+ cl_assert(error == GIT_EEXISTS);
+}
+
+void test_refs_create__creating_a_reference_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ git_reference *new_reference;
+ git_oid id;
+
+ const char *name = "refs/heads/inv@{id";
+
+ git_oid_fromstr(&id, current_master_tip);
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_create(
+ &new_reference, g_repo, name, &id, 0));
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create(
+ &new_reference, g_repo, name, current_head_target, 0));
+}
diff --git a/tests-clar/refs/delete.c b/tests-clar/refs/delete.c
index 912f41456..ac517d869 100644
--- a/tests-clar/refs/delete.c
+++ b/tests-clar/refs/delete.c
@@ -3,6 +3,7 @@
#include "repository.h"
#include "git2/reflog.h"
#include "reflog.h"
+#include "ref_helpers.h"
static const char *packed_test_head_name = "refs/heads/packed-test";
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
@@ -37,10 +38,11 @@ void test_refs_delete__packed_loose(void)
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name));
/* Ensure it's the loose version that has been found */
- cl_assert(git_reference_is_packed(looked_up_ref) == 0);
+ cl_assert(reference_is_packed(looked_up_ref) == 0);
/* Now that the reference is deleted... */
cl_git_pass(git_reference_delete(looked_up_ref));
+ git_reference_free(looked_up_ref);
/* Looking up the reference once again should not retrieve it */
cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name));
@@ -56,30 +58,34 @@ void test_refs_delete__packed_only(void)
{
// can delete a just packed reference
git_reference *ref;
+ git_refdb *refdb;
git_oid id;
const char *new_ref = "refs/heads/new_ref";
git_oid_fromstr(&id, current_master_tip);
/* Create and write the new object id reference */
- cl_git_pass(git_reference_create_oid(&ref, g_repo, new_ref, &id, 0));
+ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0));
git_reference_free(ref);
/* Lookup the reference */
cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref));
/* Ensure it's a loose reference */
- cl_assert(git_reference_is_packed(ref) == 0);
+ cl_assert(reference_is_packed(ref) == 0);
/* Pack all existing references */
- cl_git_pass(git_reference_packall(g_repo));
+ cl_git_pass(git_repository_refdb(&refdb, g_repo));
+ cl_git_pass(git_refdb_compress(refdb));
/* Reload the reference from disk */
- cl_git_pass(git_reference_reload(ref));
+ git_reference_free(ref);
+ cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref));
/* Ensure it's a packed reference */
- cl_assert(git_reference_is_packed(ref) == 1);
+ cl_assert(reference_is_packed(ref) == 1);
/* This should pass */
cl_git_pass(git_reference_delete(ref));
+ git_reference_free(ref);
}
diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c
new file mode 100644
index 000000000..4da1a15dd
--- /dev/null
+++ b/tests-clar/refs/foreachglob.c
@@ -0,0 +1,95 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_reference *fake_remote;
+
+void test_refs_foreachglob__initialize(void)
+{
+ git_oid id;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
+ cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0));
+}
+
+void test_refs_foreachglob__cleanup(void)
+{
+ git_reference_free(fake_remote);
+ fake_remote = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_fixture_cleanup("testrepo.git");
+}
+
+static int count_cb(const char *reference_name, void *payload)
+{
+ int *count = (int *)payload;
+
+ GIT_UNUSED(reference_name);
+
+ (*count)++;
+
+ return 0;
+}
+
+static void assert_retrieval(const char *glob, unsigned int flags, int expected_count)
+{
+ int count = 0;
+
+ cl_git_pass(git_reference_foreach_glob(repo, glob, flags, count_cb, &count));
+
+ cl_assert_equal_i(expected_count, count);
+}
+
+void test_refs_foreachglob__retrieve_all_refs(void)
+{
+ /* 12 heads (including one packed head) + 1 note + 2 remotes + 7 tags */
+ assert_retrieval("*", GIT_REF_LISTALL, 22);
+}
+
+void test_refs_foreachglob__retrieve_remote_branches(void)
+{
+ assert_retrieval("refs/remotes/*", GIT_REF_LISTALL, 2);
+}
+
+void test_refs_foreachglob__retrieve_local_branches(void)
+{
+ assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 12);
+}
+
+void test_refs_foreachglob__retrieve_partially_named_references(void)
+{
+ /*
+ * refs/heads/packed-test, refs/heads/test
+ * refs/remotes/test/master, refs/tags/test
+ */
+
+ assert_retrieval("*test*", GIT_REF_LISTALL, 4);
+}
+
+
+static int interrupt_cb(const char *reference_name, void *payload)
+{
+ int *count = (int *)payload;
+
+ GIT_UNUSED(reference_name);
+
+ (*count)++;
+
+ return (*count == 11);
+}
+
+void test_refs_foreachglob__can_cancel(void)
+{
+ int count = 0;
+
+ cl_assert_equal_i(GIT_EUSER, git_reference_foreach_glob(
+ repo, "*", GIT_REF_LISTALL, interrupt_cb, &count) );
+
+ cl_assert_equal_i(11, count);
+}
diff --git a/tests-clar/refs/isvalidname.c b/tests-clar/refs/isvalidname.c
new file mode 100644
index 000000000..65c70ba4d
--- /dev/null
+++ b/tests-clar/refs/isvalidname.c
@@ -0,0 +1,31 @@
+#include "clar_libgit2.h"
+
+void test_refs_isvalidname__can_detect_invalid_formats(void)
+{
+ cl_assert_equal_i(false, git_reference_is_valid_name("refs/tags/0.17.0^{}"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("TWO/LEVELS"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("ONE.LEVEL"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("HEAD/"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("NO_TRAILING_UNDERSCORE_"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("_NO_LEADING_UNDERSCORE"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("HEAD/aa"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("lower_case"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("/stupid/name/master"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("/"));
+ cl_assert_equal_i(false, git_reference_is_valid_name("//"));
+ cl_assert_equal_i(false, git_reference_is_valid_name(""));
+ cl_assert_equal_i(false, git_reference_is_valid_name("refs/heads/sub.lock/webmatrix"));
+}
+
+void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
+{
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/tags/0.17.0"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/LEVELS"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("HEAD"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("ONE_LEVEL"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/stash"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/remotes/origin/bim_with_3d@11296"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/master{yesterday"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/master}yesterday"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/master{yesterday}"));
+}
diff --git a/tests-clar/refs/list.c b/tests-clar/refs/list.c
index 2a7b157ca..3948b2b7a 100644
--- a/tests-clar/refs/list.c
+++ b/tests-clar/refs/list.c
@@ -33,10 +33,10 @@ void test_refs_list__all(void)
printf("# %s\n", ref_list.strings[i]);
}*/
- /* We have exactly 9 refs in total if we include the packed ones:
+ /* We have exactly 12 refs in total if we include the packed ones:
* there is a reference that exists both in the packfile and as
* loose, but we only list it once */
- cl_assert(ref_list.count == 9);
+ cl_assert_equal_i((int)ref_list.count, 13);
git_strarray_free(&ref_list);
}
@@ -51,3 +51,18 @@ void test_refs_list__symbolic_only(void)
git_strarray_free(&ref_list);
}
+
+void test_refs_list__do_not_retrieve_references_which_name_end_with_a_lock_extension(void)
+{
+ git_strarray ref_list;
+
+ /* Create a fake locked reference */
+ cl_git_mkfile(
+ "./testrepo/.git/refs/heads/hanwen.lock",
+ "144344043ba4d4a405da03de3844aa829ae8be0e\n");
+
+ cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_LISTALL));
+ cl_assert_equal_i((int)ref_list.count, 13);
+
+ git_strarray_free(&ref_list);
+}
diff --git a/tests-clar/refs/listall.c b/tests-clar/refs/listall.c
index 7f1de74cc..8f4c3746b 100644
--- a/tests-clar/refs/listall.c
+++ b/tests-clar/refs/listall.c
@@ -34,3 +34,14 @@ void test_refs_listall__from_repository_opened_through_gitdir_path(void)
{
ensure_no_refname_starts_with_a_forward_slash(cl_fixture("testrepo.git"));
}
+
+void test_refs_listall__from_repository_with_no_trailing_newline(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("bad_tag.git")));
+ cl_git_pass(git_reference_list(&ref_list, repo, GIT_REF_LISTALL));
+
+ cl_assert(ref_list.count > 0);
+
+ git_strarray_free(&ref_list);
+ git_repository_free(repo);
+}
diff --git a/tests-clar/refs/lookup.c b/tests-clar/refs/lookup.c
index ab563ac2b..0dbebc5c2 100644
--- a/tests-clar/refs/lookup.c
+++ b/tests-clar/refs/lookup.c
@@ -25,18 +25,24 @@ void test_refs_lookup__with_resolve(void)
cl_assert(git_reference_cmp(a, b) == 0);
git_reference_free(b);
- cl_git_pass(git_reference_lookup_resolved(&b, g_repo, "head-tracker", 5));
+ cl_git_pass(git_reference_lookup_resolved(&b, g_repo, "HEAD_TRACKER", 5));
cl_assert(git_reference_cmp(a, b) == 0);
git_reference_free(b);
git_reference_free(a);
}
+void test_refs_lookup__invalid_name(void)
+{
+ git_oid oid;
+ cl_git_fail(git_reference_name_to_id(&oid, g_repo, "/refs/tags/point_to_blob"));
+}
+
void test_refs_lookup__oid(void)
{
git_oid tag, expected;
- cl_git_pass(git_reference_name_to_oid(&tag, g_repo, "refs/tags/point_to_blob"));
+ cl_git_pass(git_reference_name_to_id(&tag, g_repo, "refs/tags/point_to_blob"));
cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
cl_assert(git_oid_cmp(&tag, &expected) == 0);
}
diff --git a/tests-clar/refs/normalize.c b/tests-clar/refs/normalize.c
index 135d0a9b6..7f313ef38 100644
--- a/tests-clar/refs/normalize.c
+++ b/tests-clar/refs/normalize.c
@@ -4,104 +4,189 @@
#include "git2/reflog.h"
#include "reflog.h"
-
// Helpers
-static void ensure_refname_normalized(int is_oid_ref,
- const char *input_refname,
- const char *expected_refname)
+static void ensure_refname_normalized(
+ unsigned int flags,
+ const char *input_refname,
+ const char *expected_refname)
{
char buffer_out[GIT_REFNAME_MAX];
- if (is_oid_ref)
- cl_git_pass(git_reference__normalize_name_oid(buffer_out, sizeof(buffer_out), input_refname));
- else
- cl_git_pass(git_reference__normalize_name(buffer_out, sizeof(buffer_out), input_refname));
+ cl_git_pass(git_reference_normalize_name(buffer_out, sizeof(buffer_out), input_refname, flags));
- if (expected_refname)
- cl_assert(0 == strcmp(buffer_out, expected_refname));
+ cl_assert_equal_s(expected_refname, buffer_out);
}
-static void ensure_refname_invalid(int is_oid_ref, const char *input_refname)
+static void ensure_refname_invalid(unsigned int flags, const char *input_refname)
{
char buffer_out[GIT_REFNAME_MAX];
- if (is_oid_ref)
- cl_git_fail(git_reference__normalize_name_oid(buffer_out, sizeof(buffer_out), input_refname));
- else
- cl_git_fail(git_reference__normalize_name(buffer_out, sizeof(buffer_out), input_refname));
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC,
+ git_reference_normalize_name(buffer_out, sizeof(buffer_out), input_refname, flags));
}
-#define OID_REF 1
-#define SYM_REF 0
-
-
+void test_refs_normalize__can_normalize_a_direct_reference_name(void)
+{
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/dummy/a", "refs/dummy/a");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/stash", "refs/stash");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/tags/a", "refs/tags/a");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/a/b", "refs/heads/a/b");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/a./b", "refs/heads/a./b");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/v@ation", "refs/heads/v@ation");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs///heads///a", "refs/heads/a");
+}
-void test_refs_normalize__direct(void)
+void test_refs_normalize__cannot_normalize_any_direct_reference_name(void)
{
- // normalize a direct (OID) reference name
- ensure_refname_invalid(OID_REF, "a");
- ensure_refname_invalid(OID_REF, "");
- ensure_refname_invalid(OID_REF, "refs/heads/a/");
- ensure_refname_invalid(OID_REF, "refs/heads/a.");
- ensure_refname_invalid(OID_REF, "refs/heads/a.lock");
- ensure_refname_normalized(OID_REF, "refs/dummy/a", NULL);
- ensure_refname_normalized(OID_REF, "refs/stash", NULL);
- ensure_refname_normalized(OID_REF, "refs/tags/a", "refs/tags/a");
- ensure_refname_normalized(OID_REF, "refs/heads/a/b", "refs/heads/a/b");
- ensure_refname_normalized(OID_REF, "refs/heads/a./b", "refs/heads/a./b");
- ensure_refname_invalid(OID_REF, "refs/heads/foo?bar");
- ensure_refname_invalid(OID_REF, "refs/heads\foo");
- ensure_refname_normalized(OID_REF, "refs/heads/v@ation", "refs/heads/v@ation");
- ensure_refname_normalized(OID_REF, "refs///heads///a", "refs/heads/a");
- ensure_refname_invalid(OID_REF, "refs/heads/.a/b");
- ensure_refname_invalid(OID_REF, "refs/heads/foo/../bar");
- ensure_refname_invalid(OID_REF, "refs/heads/foo..bar");
- ensure_refname_invalid(OID_REF, "refs/heads/./foo");
- ensure_refname_invalid(OID_REF, "refs/heads/v@{ation");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "a");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "/a");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "//a");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "/refs/heads/a/");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/a/");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/a.");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/a.lock");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/foo?bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads\foo");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/v@ation", "refs/heads/v@ation");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "refs///heads///a", "refs/heads/a");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/.a/b");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/foo/../bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/foo..bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/./foo");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "refs/heads/v@{ation");
}
void test_refs_normalize__symbolic(void)
{
- // normalize a symbolic reference name
- ensure_refname_normalized(SYM_REF, "a", "a");
- ensure_refname_normalized(SYM_REF, "a/b", "a/b");
- ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a");
- ensure_refname_invalid(SYM_REF, "");
- ensure_refname_invalid(SYM_REF, "heads\foo");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "heads\foo");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "/");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "///");
+
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "ALL_CAPS_AND_UNDERSCORES", "ALL_CAPS_AND_UNDERSCORES");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/MixedCasing", "refs/MixedCasing");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs///heads///a", "refs/heads/a");
+
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "HEAD", "HEAD");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "MERGE_HEAD", "MERGE_HEAD");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "FETCH_HEAD", "FETCH_HEAD");
}
/* Ported from JGit, BSD licence.
- * See https://github.com/spearce/JGit/commit/e4bf8f6957bbb29362575d641d1e77a02d906739 */
+ * See https://github.com/spearce/JGit/commit/e4bf8f6957bbb29362575d641d1e77a02d906739
+ *
+ * Copyright (C) 2009, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
void test_refs_normalize__jgit_suite(void)
{
- // tests borrowed from JGit
+ // tests borrowed from JGit
/* EmptyString */
- ensure_refname_invalid(SYM_REF, "");
- ensure_refname_invalid(SYM_REF, "/");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "/");
/* MustHaveTwoComponents */
- ensure_refname_invalid(OID_REF, "master");
- ensure_refname_normalized(SYM_REF, "heads/master", "heads/master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_NORMAL, "master");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_NORMAL, "heads/master", "heads/master");
/* ValidHead */
-
- ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master");
- ensure_refname_normalized(SYM_REF, "refs/heads/pu", "refs/heads/pu");
- ensure_refname_normalized(SYM_REF, "refs/heads/z", "refs/heads/z");
- ensure_refname_normalized(SYM_REF, "refs/heads/FoO", "refs/heads/FoO");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master", "refs/heads/master");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/pu", "refs/heads/pu");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/z", "refs/heads/z");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/FoO", "refs/heads/FoO");
/* ValidTag */
- ensure_refname_normalized(SYM_REF, "refs/tags/v1.0", "refs/tags/v1.0");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/tags/v1.0", "refs/tags/v1.0");
/* NoLockSuffix */
- ensure_refname_invalid(SYM_REF, "refs/heads/master.lock");
+ ensure_refname_invalid(GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master.lock");
/* NoDirectorySuffix */
- ensure_refname_invalid(SYM_REF, "refs/heads/master/");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master/");
/* NoSpace */
- ensure_refname_invalid(SYM_REF, "refs/heads/i haz space");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/i haz space");
/* NoAsciiControlCharacters */
{
@@ -112,89 +197,207 @@ void test_refs_normalize__jgit_suite(void)
strncpy(buffer + 15, (const char *)&c, 1);
strncpy(buffer + 16, "er", 2);
buffer[18 - 1] = '\0';
- ensure_refname_invalid(SYM_REF, buffer);
+ ensure_refname_invalid(GIT_REF_FORMAT_ALLOW_ONELEVEL, buffer);
}
}
/* NoBareDot */
- ensure_refname_invalid(SYM_REF, "refs/heads/.");
- ensure_refname_invalid(SYM_REF, "refs/heads/..");
- ensure_refname_invalid(SYM_REF, "refs/heads/./master");
- ensure_refname_invalid(SYM_REF, "refs/heads/../master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/.");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/..");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/./master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/../master");
/* NoLeadingOrTrailingDot */
- ensure_refname_invalid(SYM_REF, ".");
- ensure_refname_invalid(SYM_REF, "refs/heads/.bar");
- ensure_refname_invalid(SYM_REF, "refs/heads/..bar");
- ensure_refname_invalid(SYM_REF, "refs/heads/bar.");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, ".");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/.bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/..bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/bar.");
/* ContainsDot */
- ensure_refname_normalized(SYM_REF, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r");
- ensure_refname_invalid(SYM_REF, "refs/heads/master..pu");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master..pu");
/* NoMagicRefCharacters */
- ensure_refname_invalid(SYM_REF, "refs/heads/master^");
- ensure_refname_invalid(SYM_REF, "refs/heads/^master");
- ensure_refname_invalid(SYM_REF, "^refs/heads/master");
-
- ensure_refname_invalid(SYM_REF, "refs/heads/master~");
- ensure_refname_invalid(SYM_REF, "refs/heads/~master");
- ensure_refname_invalid(SYM_REF, "~refs/heads/master");
-
- ensure_refname_invalid(SYM_REF, "refs/heads/master:");
- ensure_refname_invalid(SYM_REF, "refs/heads/:master");
- ensure_refname_invalid(SYM_REF, ":refs/heads/master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master^");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/^master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "^refs/heads/master");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master~");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/~master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "~refs/heads/master");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master:");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/:master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, ":refs/heads/master");
/* ShellGlob */
- ensure_refname_invalid(SYM_REF, "refs/heads/master?");
- ensure_refname_invalid(SYM_REF, "refs/heads/?master");
- ensure_refname_invalid(SYM_REF, "?refs/heads/master");
-
- ensure_refname_invalid(SYM_REF, "refs/heads/master[");
- ensure_refname_invalid(SYM_REF, "refs/heads/[master");
- ensure_refname_invalid(SYM_REF, "[refs/heads/master");
-
- ensure_refname_invalid(SYM_REF, "refs/heads/master*");
- ensure_refname_invalid(SYM_REF, "refs/heads/*master");
- ensure_refname_invalid(SYM_REF, "*refs/heads/master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master?");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/?master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "?refs/heads/master");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master[");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/[master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "[refs/heads/master");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master*");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/*master");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "*refs/heads/master");
/* ValidSpecialCharacters */
- ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!");
- ensure_refname_normalized(SYM_REF, "refs/heads/\"", "refs/heads/\"");
- ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#");
- ensure_refname_normalized(SYM_REF, "refs/heads/$", "refs/heads/$");
- ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%");
- ensure_refname_normalized(SYM_REF, "refs/heads/&", "refs/heads/&");
- ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'");
- ensure_refname_normalized(SYM_REF, "refs/heads/(", "refs/heads/(");
- ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)");
- ensure_refname_normalized(SYM_REF, "refs/heads/+", "refs/heads/+");
- ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,");
- ensure_refname_normalized(SYM_REF, "refs/heads/-", "refs/heads/-");
- ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;");
- ensure_refname_normalized(SYM_REF, "refs/heads/<", "refs/heads/<");
- ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/=");
- ensure_refname_normalized(SYM_REF, "refs/heads/>", "refs/heads/>");
- ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@");
- ensure_refname_normalized(SYM_REF, "refs/heads/]", "refs/heads/]");
- ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_");
- ensure_refname_normalized(SYM_REF, "refs/heads/`", "refs/heads/`");
- ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{");
- ensure_refname_normalized(SYM_REF, "refs/heads/|", "refs/heads/|");
- ensure_refname_normalized(SYM_REF, "refs/heads/}", "refs/heads/}");
+ ensure_refname_normalized
+ (GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/!", "refs/heads/!");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/\"", "refs/heads/\"");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/#", "refs/heads/#");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/$", "refs/heads/$");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/%", "refs/heads/%");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/&", "refs/heads/&");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/'", "refs/heads/'");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/(", "refs/heads/(");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/)", "refs/heads/)");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/+", "refs/heads/+");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/,", "refs/heads/,");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/-", "refs/heads/-");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/;", "refs/heads/;");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/<", "refs/heads/<");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/=", "refs/heads/=");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/>", "refs/heads/>");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/@", "refs/heads/@");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/]", "refs/heads/]");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/_", "refs/heads/_");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/`", "refs/heads/`");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/{", "refs/heads/{");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/|", "refs/heads/|");
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/}", "refs/heads/}");
// This is valid on UNIX, but not on Windows
// hence we make in invalid due to non-portability
//
- ensure_refname_invalid(SYM_REF, "refs/heads/\\");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/\\");
/* UnicodeNames */
/*
* Currently this fails.
- * ensure_refname_normalized(SYM_REF, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m");
+ * ensure_refname_normalized(GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m");
*/
/* RefLogQueryIsValidRef */
- ensure_refname_invalid(SYM_REF, "refs/heads/master@{1}");
- ensure_refname_invalid(SYM_REF, "refs/heads/master@{1.hour.ago}");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master@{1}");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_ALLOW_ONELEVEL, "refs/heads/master@{1.hour.ago}");
+}
+
+void test_refs_normalize__buffer_has_to_be_big_enough_to_hold_the_normalized_version(void)
+{
+ char buffer_out[21];
+
+ cl_git_pass(git_reference_normalize_name(
+ buffer_out, 21, "refs//heads///long///name", GIT_REF_FORMAT_NORMAL));
+ cl_git_fail(git_reference_normalize_name(
+ buffer_out, 20, "refs//heads///long///name", GIT_REF_FORMAT_NORMAL));
+}
+
+#define ONE_LEVEL_AND_REFSPEC \
+ GIT_REF_FORMAT_ALLOW_ONELEVEL \
+ | GIT_REF_FORMAT_REFSPEC_PATTERN
+
+void test_refs_normalize__refspec_pattern(void)
+{
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "heads/*foo/bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "heads/foo*/bar");
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "heads/f*o/bar");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "foo");
+ ensure_refname_normalized(
+ ONE_LEVEL_AND_REFSPEC, "FOO", "FOO");
+
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "foo/bar", "foo/bar");
+ ensure_refname_normalized(
+ ONE_LEVEL_AND_REFSPEC, "foo/bar", "foo/bar");
+
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "*/foo", "*/foo");
+ ensure_refname_normalized(
+ ONE_LEVEL_AND_REFSPEC, "*/foo", "*/foo");
+
+ ensure_refname_normalized(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "foo/*/bar", "foo/*/bar");
+ ensure_refname_normalized(
+ ONE_LEVEL_AND_REFSPEC, "foo/*/bar", "foo/*/bar");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "*");
+ ensure_refname_normalized(
+ ONE_LEVEL_AND_REFSPEC, "*", "*");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "foo/*/*");
+ ensure_refname_invalid(
+ ONE_LEVEL_AND_REFSPEC, "foo/*/*");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "*/foo/*");
+ ensure_refname_invalid(
+ ONE_LEVEL_AND_REFSPEC, "*/foo/*");
+
+ ensure_refname_invalid(
+ GIT_REF_FORMAT_REFSPEC_PATTERN, "*/*/foo");
+ ensure_refname_invalid(
+ ONE_LEVEL_AND_REFSPEC, "*/*/foo");
}
diff --git a/tests-clar/refs/overwrite.c b/tests-clar/refs/overwrite.c
index 410e39a84..ebe72069c 100644
--- a/tests-clar/refs/overwrite.c
+++ b/tests-clar/refs/overwrite.c
@@ -27,25 +27,25 @@ void test_refs_overwrite__symbolic(void)
git_reference *ref, *branch_ref;
/* The target needds to exist and we need to check the name has changed */
- cl_git_pass(git_reference_create_symbolic(&branch_ref, g_repo, ref_branch_name, ref_master_name, 0));
- cl_git_pass(git_reference_create_symbolic(&ref, g_repo, ref_name, ref_branch_name, 0));
+ cl_git_pass(git_reference_symbolic_create(&branch_ref, g_repo, ref_branch_name, ref_master_name, 0));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_branch_name, 0));
git_reference_free(ref);
/* Ensure it points to the right place*/
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
cl_assert(git_reference_type(ref) & GIT_REF_SYMBOLIC);
- cl_assert_equal_s(git_reference_target(ref), ref_branch_name);
+ cl_assert_equal_s(git_reference_symbolic_target(ref), ref_branch_name);
git_reference_free(ref);
/* Ensure we can't create it unless we force it to */
- cl_git_fail(git_reference_create_symbolic(&ref, g_repo, ref_name, ref_master_name, 0));
- cl_git_pass(git_reference_create_symbolic(&ref, g_repo, ref_name, ref_master_name, 1));
+ cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 1));
git_reference_free(ref);
/* Ensure it points to the right place */
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
cl_assert(git_reference_type(ref) & GIT_REF_SYMBOLIC);
- cl_assert_equal_s(git_reference_target(ref), ref_master_name);
+ cl_assert_equal_s(git_reference_symbolic_target(ref), ref_master_name);
git_reference_free(ref);
git_reference_free(branch_ref);
@@ -59,26 +59,26 @@ void test_refs_overwrite__object_id(void)
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
git_reference_free(ref);
/* Create it */
- cl_git_pass(git_reference_create_oid(&ref, g_repo, ref_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0));
git_reference_free(ref);
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_test_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
git_reference_free(ref);
/* Ensure we can't overwrite unless we force it */
- cl_git_fail(git_reference_create_oid(&ref, g_repo, ref_name, &id, 0));
- cl_git_pass(git_reference_create_oid(&ref, g_repo, ref_name, &id, 1));
+ cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1));
git_reference_free(ref);
/* Ensure it has been overwritten */
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
- cl_assert(!git_oid_cmp(&id, git_reference_oid(ref)));
+ cl_assert(!git_oid_cmp(&id, git_reference_target(ref)));
git_reference_free(ref);
}
@@ -91,19 +91,19 @@ void test_refs_overwrite__object_id_with_symbolic(void)
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
git_reference_free(ref);
- cl_git_pass(git_reference_create_oid(&ref, g_repo, ref_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0));
git_reference_free(ref);
- cl_git_fail(git_reference_create_symbolic(&ref, g_repo, ref_name, ref_master_name, 0));
- cl_git_pass(git_reference_create_symbolic(&ref, g_repo, ref_name, ref_master_name, 1));
+ cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 1));
git_reference_free(ref);
/* Ensure it points to the right place */
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
cl_assert(git_reference_type(ref) & GIT_REF_SYMBOLIC);
- cl_assert_equal_s(git_reference_target(ref), ref_master_name);
+ cl_assert_equal_s(git_reference_symbolic_target(ref), ref_master_name);
git_reference_free(ref);
}
@@ -116,21 +116,21 @@ void test_refs_overwrite__symbolic_with_object_id(void)
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
git_reference_free(ref);
/* Create the symbolic ref */
- cl_git_pass(git_reference_create_symbolic(&ref, g_repo, ref_name, ref_master_name, 0));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0));
git_reference_free(ref);
/* It shouldn't overwrite unless we tell it to */
- cl_git_fail(git_reference_create_oid(&ref, g_repo, ref_name, &id, 0));
- cl_git_pass(git_reference_create_oid(&ref, g_repo, ref_name, &id, 1));
+ cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1));
git_reference_free(ref);
/* Ensure it points to the right place */
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- cl_assert(!git_oid_cmp(git_reference_oid(ref), &id));
+ cl_assert(!git_oid_cmp(git_reference_target(ref), &id));
git_reference_free(ref);
}
diff --git a/tests-clar/refs/pack.c b/tests-clar/refs/pack.c
index 305594c28..973abae30 100644
--- a/tests-clar/refs/pack.c
+++ b/tests-clar/refs/pack.c
@@ -3,6 +3,7 @@
#include "repository.h"
#include "git2/reflog.h"
#include "reflog.h"
+#include "ref_helpers.h"
static const char *loose_tag_ref_name = "refs/tags/e90810b";
@@ -18,6 +19,14 @@ void test_refs_pack__cleanup(void)
cl_git_sandbox_cleanup();
}
+static void packall(void)
+{
+ git_refdb *refdb;
+
+ cl_git_pass(git_repository_refdb(&refdb, g_repo));
+ cl_git_pass(git_refdb_compress(refdb));
+}
+
void test_refs_pack__empty(void)
{
// create a packfile for an empty folder
@@ -27,7 +36,7 @@ void test_refs_pack__empty(void)
cl_git_pass(git_futils_mkdir_r(temp_path.ptr, NULL, GIT_REFS_DIR_MODE));
git_buf_free(&temp_path);
- cl_git_pass(git_reference_packall(g_repo));
+ packall();
}
void test_refs_pack__loose(void)
@@ -38,7 +47,7 @@ void test_refs_pack__loose(void)
/* Ensure a known loose ref can be looked up */
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
- cl_assert(git_reference_is_packed(reference) == 0);
+ cl_assert(reference_is_packed(reference) == 0);
cl_assert_equal_s(reference->name, loose_tag_ref_name);
git_reference_free(reference);
@@ -47,7 +56,7 @@ void test_refs_pack__loose(void)
* called `points_to_blob`, to make sure we can properly
* pack weak tags
*/
- cl_git_pass(git_reference_packall(g_repo));
+ packall();
/* Ensure the packed-refs file exists */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, GIT_PACKEDREFS_FILE));
@@ -55,7 +64,7 @@ void test_refs_pack__loose(void)
/* Ensure the known ref can still be looked up but is now packed */
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
- cl_assert(git_reference_is_packed(reference));
+ cl_assert(reference_is_packed(reference));
cl_assert_equal_s(reference->name, loose_tag_ref_name);
/* Ensure the known ref has been removed from the loose folder structure */
diff --git a/tests-clar/refs/peel.c b/tests-clar/refs/peel.c
new file mode 100644
index 000000000..34bd02ce0
--- /dev/null
+++ b/tests-clar/refs/peel.c
@@ -0,0 +1,92 @@
+#include "clar_libgit2.h"
+
+static git_repository *g_repo;
+
+void test_refs_peel__initialize(void)
+{
+ cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
+}
+
+void test_refs_peel__cleanup(void)
+{
+ git_repository_free(g_repo);
+ g_repo = NULL;
+}
+
+static void assert_peel(
+ const char *ref_name,
+ git_otype requested_type,
+ const char* expected_sha,
+ git_otype expected_type)
+{
+ git_oid expected_oid;
+ git_reference *ref;
+ git_object *peeled;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
+
+ cl_git_pass(git_reference_peel(&peeled, ref, requested_type));
+
+ cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha));
+ cl_assert_equal_i(0, git_oid_cmp(&expected_oid, git_object_id(peeled)));
+
+ cl_assert_equal_i(expected_type, git_object_type(peeled));
+
+ git_object_free(peeled);
+ git_reference_free(ref);
+}
+
+static void assert_peel_error(int error, const char *ref_name, git_otype requested_type)
+{
+ git_reference *ref;
+ git_object *peeled;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name));
+
+ cl_assert_equal_i(error, git_reference_peel(&peeled, ref, requested_type));
+
+ git_reference_free(ref);
+}
+
+void test_refs_peel__can_peel_a_tag(void)
+{
+ assert_peel("refs/tags/test", GIT_OBJ_TAG,
+ "b25fa35b38051e4ae45d4222e795f9df2e43f1d1", GIT_OBJ_TAG);
+ assert_peel("refs/tags/test", GIT_OBJ_COMMIT,
+ "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT);
+ assert_peel("refs/tags/test", GIT_OBJ_TREE,
+ "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJ_TREE);
+ assert_peel("refs/tags/point_to_blob", GIT_OBJ_BLOB,
+ "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OBJ_BLOB);
+}
+
+void test_refs_peel__can_peel_a_branch(void)
+{
+ assert_peel("refs/heads/master", GIT_OBJ_COMMIT,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OBJ_COMMIT);
+ assert_peel("refs/heads/master", GIT_OBJ_TREE,
+ "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162", GIT_OBJ_TREE);
+}
+
+void test_refs_peel__can_peel_a_symbolic_reference(void)
+{
+ assert_peel("HEAD", GIT_OBJ_COMMIT,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OBJ_COMMIT);
+ assert_peel("HEAD", GIT_OBJ_TREE,
+ "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162", GIT_OBJ_TREE);
+}
+
+void test_refs_peel__cannot_peel_into_a_non_existing_target(void)
+{
+ assert_peel_error(GIT_ENOTFOUND, "refs/tags/point_to_blob", GIT_OBJ_TAG);
+}
+
+void test_refs_peel__can_peel_into_any_non_tag_object(void)
+{
+ assert_peel("refs/heads/master", GIT_OBJ_ANY,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OBJ_COMMIT);
+ assert_peel("refs/tags/point_to_blob", GIT_OBJ_ANY,
+ "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OBJ_BLOB);
+ assert_peel("refs/tags/test", GIT_OBJ_ANY,
+ "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT);
+}
diff --git a/tests-clar/refs/read.c b/tests-clar/refs/read.c
index d7111b232..afb6be008 100644
--- a/tests-clar/refs/read.c
+++ b/tests-clar/refs/read.c
@@ -3,10 +3,11 @@
#include "repository.h"
#include "git2/reflog.h"
#include "reflog.h"
+#include "ref_helpers.h"
static const char *loose_tag_ref_name = "refs/tags/e90810b";
static const char *non_existing_tag_ref_name = "refs/tags/i-do-not-exist";
-static const char *head_tracker_sym_ref_name = "head-tracker";
+static const char *head_tracker_sym_ref_name = "HEAD_TRACKER";
static const char *current_head_target = "refs/heads/master";
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
static const char *packed_head_name = "refs/heads/packed";
@@ -16,12 +17,13 @@ static git_repository *g_repo;
void test_refs_read__initialize(void)
{
- g_repo = cl_git_sandbox_init("testrepo");
+ cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
}
void test_refs_read__cleanup(void)
{
- cl_git_sandbox_cleanup();
+ git_repository_free(g_repo);
+ g_repo = NULL;
}
void test_refs_read__loose_tag(void)
@@ -33,10 +35,10 @@ void test_refs_read__loose_tag(void)
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
cl_assert(git_reference_type(reference) & GIT_REF_OID);
- cl_assert(git_reference_is_packed(reference) == 0);
+ cl_assert(reference_is_packed(reference) == 0);
cl_assert_equal_s(reference->name, loose_tag_ref_name);
- cl_git_pass(git_object_lookup(&object, g_repo, git_reference_oid(reference), GIT_OBJ_ANY));
+ cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(reference), GIT_OBJ_ANY));
cl_assert(object != NULL);
cl_assert(git_object_type(object) == GIT_OBJ_TAG);
@@ -70,13 +72,13 @@ void test_refs_read__symbolic(void)
cl_git_pass(git_reference_lookup(&reference, g_repo, GIT_HEAD_FILE));
cl_assert(git_reference_type(reference) & GIT_REF_SYMBOLIC);
- cl_assert(git_reference_is_packed(reference) == 0);
+ cl_assert(reference_is_packed(reference) == 0);
cl_assert_equal_s(reference->name, GIT_HEAD_FILE);
cl_git_pass(git_reference_resolve(&resolved_ref, reference));
cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID);
- cl_git_pass(git_object_lookup(&object, g_repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
+ cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(resolved_ref), GIT_OBJ_ANY));
cl_assert(object != NULL);
cl_assert(git_object_type(object) == GIT_OBJ_COMMIT);
@@ -98,13 +100,13 @@ void test_refs_read__nested_symbolic(void)
cl_git_pass(git_reference_lookup(&reference, g_repo, head_tracker_sym_ref_name));
cl_assert(git_reference_type(reference) & GIT_REF_SYMBOLIC);
- cl_assert(git_reference_is_packed(reference) == 0);
+ cl_assert(reference_is_packed(reference) == 0);
cl_assert_equal_s(reference->name, head_tracker_sym_ref_name);
cl_git_pass(git_reference_resolve(&resolved_ref, reference));
cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID);
- cl_git_pass(git_object_lookup(&object, g_repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
+ cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(resolved_ref), GIT_OBJ_ANY));
cl_assert(object != NULL);
cl_assert(git_object_type(object) == GIT_OBJ_COMMIT);
@@ -128,13 +130,13 @@ void test_refs_read__head_then_master(void)
cl_git_pass(git_reference_lookup(&reference, g_repo, GIT_HEAD_FILE));
cl_git_pass(git_reference_resolve(&resolved_ref, reference));
- cl_git_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref)));
+ cl_git_pass(git_oid_cmp(git_reference_target(comp_base_ref), git_reference_target(resolved_ref)));
git_reference_free(reference);
git_reference_free(resolved_ref);
cl_git_pass(git_reference_lookup(&reference, g_repo, current_head_target));
cl_git_pass(git_reference_resolve(&resolved_ref, reference));
- cl_git_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref)));
+ cl_git_pass(git_oid_cmp(git_reference_target(comp_base_ref), git_reference_target(resolved_ref)));
git_reference_free(reference);
git_reference_free(resolved_ref);
@@ -150,7 +152,7 @@ void test_refs_read__master_then_head(void)
cl_git_pass(git_reference_lookup(&reference, g_repo, GIT_HEAD_FILE));
cl_git_pass(git_reference_resolve(&resolved_ref, reference));
- cl_git_pass(git_oid_cmp(git_reference_oid(master_ref), git_reference_oid(resolved_ref)));
+ cl_git_pass(git_oid_cmp(git_reference_target(master_ref), git_reference_target(resolved_ref)));
git_reference_free(reference);
git_reference_free(resolved_ref);
@@ -166,10 +168,10 @@ void test_refs_read__packed(void)
cl_git_pass(git_reference_lookup(&reference, g_repo, packed_head_name));
cl_assert(git_reference_type(reference) & GIT_REF_OID);
- cl_assert(git_reference_is_packed(reference));
+ cl_assert(reference_is_packed(reference));
cl_assert_equal_s(reference->name, packed_head_name);
- cl_git_pass(git_object_lookup(&object, g_repo, git_reference_oid(reference), GIT_OBJ_ANY));
+ cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(reference), GIT_OBJ_ANY));
cl_assert(object != NULL);
cl_assert(git_object_type(object) == GIT_OBJ_COMMIT);
@@ -187,8 +189,80 @@ void test_refs_read__loose_first(void)
git_reference_free(reference);
cl_git_pass(git_reference_lookup(&reference, g_repo, packed_test_head_name));
cl_assert(git_reference_type(reference) & GIT_REF_OID);
- cl_assert(git_reference_is_packed(reference) == 0);
+ cl_assert(reference_is_packed(reference) == 0);
cl_assert_equal_s(reference->name, packed_test_head_name);
git_reference_free(reference);
}
+
+void test_refs_read__chomped(void)
+{
+ git_reference *test, *chomped;
+
+ cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test"));
+ cl_git_pass(git_reference_lookup(&chomped, g_repo, "refs/heads/chomped"));
+ cl_git_pass(git_oid_cmp(git_reference_target(test), git_reference_target(chomped)));
+
+ git_reference_free(test);
+ git_reference_free(chomped);
+}
+
+void test_refs_read__trailing(void)
+{
+ git_reference *test, *trailing;
+
+ cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test"));
+ cl_git_pass(git_reference_lookup(&trailing, g_repo, "refs/heads/trailing"));
+ cl_git_pass(git_oid_cmp(git_reference_target(test), git_reference_target(trailing)));
+ git_reference_free(trailing);
+ cl_git_pass(git_reference_lookup(&trailing, g_repo, "FETCH_HEAD"));
+
+ git_reference_free(test);
+ git_reference_free(trailing);
+}
+
+void test_refs_read__unfound_return_ENOTFOUND(void)
+{
+ git_reference *reference;
+ git_oid id;
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_reference_lookup(&reference, g_repo, "TEST_MASTER"));
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_reference_lookup(&reference, g_repo, "refs/test/master"));
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_reference_lookup(&reference, g_repo, "refs/tags/test/master"));
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_reference_lookup(&reference, g_repo, "refs/tags/test/farther/master"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_reference_name_to_id(&id, g_repo, "refs/tags/test/farther/master"));
+}
+
+static void assert_is_branch(const char *name, bool expected_branchness)
+{
+ git_reference *reference;
+ cl_git_pass(git_reference_lookup(&reference, g_repo, name));
+ cl_assert_equal_i(expected_branchness, git_reference_is_branch(reference));
+ git_reference_free(reference);
+}
+
+void test_refs_read__can_determine_if_a_reference_is_a_local_branch(void)
+{
+ assert_is_branch("refs/heads/master", true);
+ assert_is_branch("refs/heads/packed", true);
+ assert_is_branch("refs/remotes/test/master", false);
+ assert_is_branch("refs/tags/e90810b", false);
+}
+
+void test_refs_read__invalid_name_returns_EINVALIDSPEC(void)
+{
+ git_reference *reference;
+ git_oid id;
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_reference_lookup(&reference, g_repo, "refs/heads/Inv@{id"));
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_reference_name_to_id(&id, g_repo, "refs/heads/Inv@{id"));
+}
diff --git a/tests-clar/refs/ref_helpers.c b/tests-clar/refs/ref_helpers.c
new file mode 100644
index 000000000..16ab9e6ef
--- /dev/null
+++ b/tests-clar/refs/ref_helpers.c
@@ -0,0 +1,25 @@
+#include "git2/repository.h"
+#include "git2/refs.h"
+#include "common.h"
+#include "util.h"
+#include "buffer.h"
+#include "path.h"
+
+int reference_is_packed(git_reference *ref)
+{
+ git_buf ref_path = GIT_BUF_INIT;
+ int packed;
+
+ assert(ref);
+
+ if (git_buf_joinpath(&ref_path,
+ git_repository_path(git_reference_owner(ref)),
+ git_reference_name(ref)) < 0)
+ return -1;
+
+ packed = !git_path_isfile(ref_path.ptr);
+
+ git_buf_free(&ref_path);
+
+ return packed;
+}
diff --git a/tests-clar/refs/ref_helpers.h b/tests-clar/refs/ref_helpers.h
new file mode 100644
index 000000000..0ef55bfce
--- /dev/null
+++ b/tests-clar/refs/ref_helpers.h
@@ -0,0 +1 @@
+int reference_is_packed(git_reference *ref);
diff --git a/tests-clar/refs/reflog.c b/tests-clar/refs/reflog.c
deleted file mode 100644
index 1bc51b2b8..000000000
--- a/tests-clar/refs/reflog.c
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "clar_libgit2.h"
-
-#include "repository.h"
-#include "git2/reflog.h"
-#include "reflog.h"
-
-
-static const char *new_ref = "refs/heads/test-reflog";
-static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
-static const char *commit_msg = "commit: bla bla";
-
-static git_repository *g_repo;
-
-
-// helpers
-static void assert_signature(git_signature *expected, git_signature *actual)
-{
- cl_assert(actual);
- cl_assert_equal_s(expected->name, actual->name);
- cl_assert_equal_s(expected->email, actual->email);
- cl_assert(expected->when.offset == actual->when.offset);
- cl_assert(expected->when.time == actual->when.time);
-}
-
-
-// Fixture setup and teardown
-void test_refs_reflog__initialize(void)
-{
- g_repo = cl_git_sandbox_init("testrepo");
-}
-
-void test_refs_reflog__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-}
-
-
-
-void test_refs_reflog__write_then_read(void)
-{
- // write a reflog for a given reference and ensure it can be read back
- git_repository *repo2;
- git_reference *ref, *lookedup_ref;
- git_oid oid;
- git_signature *committer;
- git_reflog *reflog;
- git_reflog_entry *entry;
- char oid_str[GIT_OID_HEXSZ+1];
-
- /* Create a new branch pointing at the HEAD */
- git_oid_fromstr(&oid, current_master_tip);
- cl_git_pass(git_reference_create_oid(&ref, g_repo, new_ref, &oid, 0));
- git_reference_free(ref);
- cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref));
-
- cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
-
- cl_git_pass(git_reflog_write(ref, NULL, committer, NULL));
- cl_git_fail(git_reflog_write(ref, NULL, committer, "no ancestor NULL for an existing reflog"));
- cl_git_fail(git_reflog_write(ref, NULL, committer, "no\nnewline"));
- cl_git_pass(git_reflog_write(ref, &oid, committer, commit_msg));
-
- /* Reopen a new instance of the repository */
- cl_git_pass(git_repository_open(&repo2, "testrepo"));
-
- /* Lookup the preivously created branch */
- cl_git_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref));
-
- /* Read and parse the reflog for this branch */
- cl_git_pass(git_reflog_read(&reflog, lookedup_ref));
- cl_assert(reflog->entries.length == 2);
-
- entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0);
- assert_signature(committer, entry->committer);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
- cl_assert_equal_s("0000000000000000000000000000000000000000", oid_str);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
- cl_assert_equal_s(current_master_tip, oid_str);
- cl_assert(entry->msg == NULL);
-
- entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 1);
- assert_signature(committer, entry->committer);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
- cl_assert_equal_s(current_master_tip, oid_str);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
- cl_assert_equal_s(current_master_tip, oid_str);
- cl_assert_equal_s(commit_msg, entry->msg);
-
- git_signature_free(committer);
- git_reflog_free(reflog);
- git_repository_free(repo2);
-
- git_reference_free(ref);
- git_reference_free(lookedup_ref);
-}
-
-void test_refs_reflog__dont_write_bad(void)
-{
- // avoid writing an obviously wrong reflog
- git_reference *ref;
- git_oid oid;
- git_signature *committer;
-
- /* Create a new branch pointing at the HEAD */
- git_oid_fromstr(&oid, current_master_tip);
- cl_git_pass(git_reference_create_oid(&ref, g_repo, new_ref, &oid, 0));
- git_reference_free(ref);
- cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref));
-
- cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
-
- /* Write the reflog for the new branch */
- cl_git_pass(git_reflog_write(ref, NULL, committer, NULL));
-
- /* Try to update the reflog with wrong information:
- * It's no new reference, so the ancestor OID cannot
- * be NULL. */
- cl_git_fail(git_reflog_write(ref, NULL, committer, NULL));
-
- git_signature_free(committer);
-
- git_reference_free(ref);
-}
diff --git a/tests-clar/refs/reflog/drop.c b/tests-clar/refs/reflog/drop.c
new file mode 100644
index 000000000..21cc847bf
--- /dev/null
+++ b/tests-clar/refs/reflog/drop.c
@@ -0,0 +1,124 @@
+#include "clar_libgit2.h"
+
+#include "reflog.h"
+
+static git_repository *g_repo;
+static git_reflog *g_reflog;
+static size_t entrycount;
+
+void test_refs_reflog_drop__initialize(void)
+{
+ git_reference *ref;
+
+ g_repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
+
+ git_reflog_read(&g_reflog, ref);
+ entrycount = git_reflog_entrycount(g_reflog);
+
+ git_reference_free(ref);
+}
+
+void test_refs_reflog_drop__cleanup(void)
+{
+ git_reflog_free(g_reflog);
+ g_reflog = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_reflog_drop__dropping_a_non_exisiting_entry_from_the_log_returns_ENOTFOUND(void)
+{
+ cl_assert_equal_i(GIT_ENOTFOUND, git_reflog_drop(g_reflog, entrycount, 0));
+
+ cl_assert_equal_sz(entrycount, git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_drop_an_entry(void)
+{
+ cl_assert(entrycount > 4);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 2, 0));
+ cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_drop_an_entry_and_rewrite_the_log_history(void)
+{
+ const git_reflog_entry *before_current;
+ const git_reflog_entry *after_current;
+ git_oid before_current_old_oid, before_current_cur_oid;
+
+ cl_assert(entrycount > 4);
+
+ before_current = git_reflog_entry_byindex(g_reflog, 1);
+
+ git_oid_cpy(&before_current_old_oid, &before_current->oid_old);
+ git_oid_cpy(&before_current_cur_oid, &before_current->oid_cur);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 1, 1));
+
+ cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
+
+ after_current = git_reflog_entry_byindex(g_reflog, 0);
+
+ cl_assert_equal_i(0, git_oid_cmp(&before_current_old_oid, &after_current->oid_old));
+ cl_assert(0 != git_oid_cmp(&before_current_cur_oid, &after_current->oid_cur));
+}
+
+void test_refs_reflog_drop__can_drop_the_oldest_entry(void)
+{
+ const git_reflog_entry *entry;
+
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 0));
+ cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
+
+ entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) != 0);
+}
+
+void test_refs_reflog_drop__can_drop_the_oldest_entry_and_rewrite_the_log_history(void)
+{
+ const git_reflog_entry *entry;
+
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 1));
+ cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
+
+ entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
+}
+
+void test_refs_reflog_drop__can_drop_all_the_entries(void)
+{
+ cl_assert(--entrycount > 0);
+
+ do {
+ cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
+ } while (--entrycount > 0);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
+
+ cl_assert_equal_i(0, (int)git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_persist_deletion_on_disk(void)
+{
+ git_reference *ref;
+
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, g_reflog->ref_name));
+ cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
+ cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
+ cl_git_pass(git_reflog_write(g_reflog));
+
+ git_reflog_free(g_reflog);
+
+ git_reflog_read(&g_reflog, ref);
+ git_reference_free(ref);
+
+ cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
+}
diff --git a/tests-clar/refs/reflog/reflog.c b/tests-clar/refs/reflog/reflog.c
new file mode 100644
index 000000000..1cd0ddd92
--- /dev/null
+++ b/tests-clar/refs/reflog/reflog.c
@@ -0,0 +1,186 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "git2/reflog.h"
+#include "reflog.h"
+
+
+static const char *new_ref = "refs/heads/test-reflog";
+static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
+#define commit_msg "commit: bla bla"
+
+static git_repository *g_repo;
+
+
+// helpers
+static void assert_signature(git_signature *expected, git_signature *actual)
+{
+ cl_assert(actual);
+ cl_assert_equal_s(expected->name, actual->name);
+ cl_assert_equal_s(expected->email, actual->email);
+ cl_assert(expected->when.offset == actual->when.offset);
+ cl_assert(expected->when.time == actual->when.time);
+}
+
+
+// Fixture setup and teardown
+void test_refs_reflog_reflog__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_refs_reflog_reflog__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_reflog_reflog__append_then_read(void)
+{
+ // write a reflog for a given reference and ensure it can be read back
+ git_repository *repo2;
+ git_reference *ref, *lookedup_ref;
+ git_oid oid;
+ git_signature *committer;
+ git_reflog *reflog;
+ const git_reflog_entry *entry;
+
+ /* Create a new branch pointing at the HEAD */
+ git_oid_fromstr(&oid, current_master_tip);
+ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0));
+
+ cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
+
+ cl_git_pass(git_reflog_read(&reflog, ref));
+
+ cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline"));
+ cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL));
+ cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n"));
+ cl_git_pass(git_reflog_write(reflog));
+ git_reflog_free(reflog);
+
+ /* Reopen a new instance of the repository */
+ cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
+
+ /* Lookup the previously created branch */
+ cl_git_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref));
+
+ /* Read and parse the reflog for this branch */
+ cl_git_pass(git_reflog_read(&reflog, lookedup_ref));
+ cl_assert_equal_i(2, (int)git_reflog_entrycount(reflog));
+
+ entry = git_reflog_entry_byindex(reflog, 1);
+ assert_signature(committer, entry->committer);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
+ cl_assert(git_oid_cmp(&oid, &entry->oid_cur) == 0);
+ cl_assert(entry->msg == NULL);
+
+ entry = git_reflog_entry_byindex(reflog, 0);
+ assert_signature(committer, entry->committer);
+ cl_assert(git_oid_cmp(&oid, &entry->oid_old) == 0);
+ cl_assert(git_oid_cmp(&oid, &entry->oid_cur) == 0);
+ cl_assert_equal_s(commit_msg, entry->msg);
+
+ git_signature_free(committer);
+ git_reflog_free(reflog);
+ git_repository_free(repo2);
+
+ git_reference_free(ref);
+ git_reference_free(lookedup_ref);
+}
+
+void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
+{
+ git_reference *master, *new_master;
+ git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+
+ git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_buf_puts(&moved_log_path, git_buf_cstr(&master_log_path));
+ git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
+ git_buf_joinpath(&moved_log_path, git_buf_cstr(&moved_log_path), "refs/moved");
+
+ cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&moved_log_path)));
+
+ cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
+ cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0));
+ git_reference_free(master);
+
+ cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&moved_log_path)));
+
+ git_reference_free(new_master);
+ git_buf_free(&moved_log_path);
+ git_buf_free(&master_log_path);
+}
+
+static void assert_has_reflog(bool expected_result, const char *name)
+{
+ git_reference *ref;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, name));
+
+ cl_assert_equal_i(expected_result, git_reference_has_log(ref));
+
+ git_reference_free(ref);
+}
+
+void test_refs_reflog_reflog__reference_has_reflog(void)
+{
+ assert_has_reflog(true, "HEAD");
+ assert_has_reflog(true, "refs/heads/master");
+ assert_has_reflog(false, "refs/heads/subtrees");
+}
+
+void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_returns_an_empty_one(void)
+{
+ git_reference *subtrees;
+ git_reflog *reflog;
+ git_buf subtrees_log_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_reference_lookup(&subtrees, g_repo, "refs/heads/subtrees"));
+
+ git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, git_reference_name(subtrees));
+ cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path)));
+
+ cl_git_pass(git_reflog_read(&reflog, subtrees));
+
+ cl_assert_equal_i(0, (int)git_reflog_entrycount(reflog));
+
+ git_reflog_free(reflog);
+ git_reference_free(subtrees);
+ git_buf_free(&subtrees_log_path);
+}
+
+void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
+{
+ git_reference *master, *new_master;
+ git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+ git_reflog *reflog;
+
+ cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
+ cl_git_pass(git_reflog_read(&reflog, master));
+
+ cl_git_pass(git_reflog_write(reflog));
+
+ cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0));
+ git_reference_free(master);
+
+ cl_git_fail(git_reflog_write(reflog));
+
+ git_reflog_free(reflog);
+ git_reference_free(new_master);
+ git_buf_free(&moved_log_path);
+ git_buf_free(&master_log_path);
+}
+
+void test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ git_reference *master;
+
+ cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC,
+ git_reflog_rename(master, "refs/heads/Inv@{id"));
+
+ git_reference_free(master);
+}
diff --git a/tests-clar/refs/rename.c b/tests-clar/refs/rename.c
index 4b917ef6d..e39abeb05 100644
--- a/tests-clar/refs/rename.c
+++ b/tests-clar/refs/rename.c
@@ -3,6 +3,7 @@
#include "repository.h"
#include "git2/reflog.h"
#include "reflog.h"
+#include "ref_helpers.h"
static const char *loose_tag_ref_name = "refs/tags/e90810b";
static const char *packed_head_name = "refs/heads/packed";
@@ -19,20 +20,20 @@ static git_repository *g_repo;
void test_refs_rename__initialize(void)
{
- g_repo = cl_git_sandbox_init("testrepo");
+ g_repo = cl_git_sandbox_init("testrepo");
}
void test_refs_rename__cleanup(void)
{
- cl_git_sandbox_cleanup();
+ cl_git_sandbox_cleanup();
}
void test_refs_rename__loose(void)
{
- // rename a loose reference
- git_reference *looked_up_ref, *another_looked_up_ref;
+ // rename a loose reference
+ git_reference *looked_up_ref, *new_ref, *another_looked_up_ref;
git_buf temp_path = GIT_BUF_INIT;
const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu";
@@ -44,36 +45,37 @@ void test_refs_rename__loose(void)
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, loose_tag_ref_name));
/* ... which is indeed loose */
- cl_assert(git_reference_is_packed(looked_up_ref) == 0);
+ cl_assert(reference_is_packed(looked_up_ref) == 0);
/* Now that the reference is renamed... */
- cl_git_pass(git_reference_rename(looked_up_ref, new_name, 0));
- cl_assert_equal_s(looked_up_ref->name, new_name);
+ cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, new_name, 0));
+ cl_assert_equal_s(new_ref->name, new_name);
+ git_reference_free(looked_up_ref);
/* ...It can't be looked-up with the old name... */
cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, loose_tag_ref_name));
/* ...but the new name works ok... */
cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, new_name));
- cl_assert_equal_s(another_looked_up_ref->name, new_name);
+ cl_assert_equal_s(new_ref->name, new_name);
- /* .. the ref is still loose... */
- cl_assert(git_reference_is_packed(another_looked_up_ref) == 0);
- cl_assert(git_reference_is_packed(looked_up_ref) == 0);
+ /* .. the new ref is loose... */
+ cl_assert(reference_is_packed(another_looked_up_ref) == 0);
+ cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref can be found in the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, new_name));
cl_assert(git_path_exists(temp_path.ptr));
- git_reference_free(looked_up_ref);
+ git_reference_free(new_ref);
git_reference_free(another_looked_up_ref);
git_buf_free(&temp_path);
}
void test_refs_rename__packed(void)
{
- // rename a packed reference (should make it loose)
- git_reference *looked_up_ref, *another_looked_up_ref;
+ // rename a packed reference (should make it loose)
+ git_reference *looked_up_ref, *new_ref, *another_looked_up_ref;
git_buf temp_path = GIT_BUF_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
@@ -85,11 +87,12 @@ void test_refs_rename__packed(void)
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name));
/* .. and it's packed */
- cl_assert(git_reference_is_packed(looked_up_ref) != 0);
+ cl_assert(reference_is_packed(looked_up_ref) != 0);
/* Now that the reference is renamed... */
- cl_git_pass(git_reference_rename(looked_up_ref, brand_new_name, 0));
- cl_assert_equal_s(looked_up_ref->name, brand_new_name);
+ cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, brand_new_name, 0));
+ cl_assert_equal_s(new_ref->name, brand_new_name);
+ git_reference_free(looked_up_ref);
/* ...It can't be looked-up with the old name... */
cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_head_name));
@@ -99,22 +102,22 @@ void test_refs_rename__packed(void)
cl_assert_equal_s(another_looked_up_ref->name, brand_new_name);
/* .. the ref is no longer packed... */
- cl_assert(git_reference_is_packed(another_looked_up_ref) == 0);
- cl_assert(git_reference_is_packed(looked_up_ref) == 0);
+ cl_assert(reference_is_packed(another_looked_up_ref) == 0);
+ cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref now happily lives in the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, brand_new_name));
cl_assert(git_path_exists(temp_path.ptr));
- git_reference_free(looked_up_ref);
+ git_reference_free(new_ref);
git_reference_free(another_looked_up_ref);
git_buf_free(&temp_path);
}
void test_refs_rename__packed_doesnt_pack_others(void)
{
- // renaming a packed reference does not pack another reference which happens to be in both loose and pack state
- git_reference *looked_up_ref, *another_looked_up_ref;
+ // renaming a packed reference does not pack another reference which happens to be in both loose and pack state
+ git_reference *looked_up_ref, *another_looked_up_ref, *renamed_ref;
git_buf temp_path = GIT_BUF_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
@@ -126,42 +129,43 @@ void test_refs_rename__packed_doesnt_pack_others(void)
cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name));
/* Ensure it's loose */
- cl_assert(git_reference_is_packed(another_looked_up_ref) == 0);
+ cl_assert(reference_is_packed(another_looked_up_ref) == 0);
git_reference_free(another_looked_up_ref);
/* Lookup the reference to rename */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name));
/* Ensure it's packed */
- cl_assert(git_reference_is_packed(looked_up_ref) != 0);
+ cl_assert(reference_is_packed(looked_up_ref) != 0);
/* Now that the reference is renamed... */
- cl_git_pass(git_reference_rename(looked_up_ref, brand_new_name, 0));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, brand_new_name, 0));
+ git_reference_free(looked_up_ref);
/* Lookup the other reference */
cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name));
/* Ensure it's loose */
- cl_assert(git_reference_is_packed(another_looked_up_ref) == 0);
+ cl_assert(reference_is_packed(another_looked_up_ref) == 0);
/* Ensure the other ref still exists on the file system */
cl_assert(git_path_exists(temp_path.ptr));
- git_reference_free(looked_up_ref);
+ git_reference_free(renamed_ref);
git_reference_free(another_looked_up_ref);
git_buf_free(&temp_path);
}
void test_refs_rename__name_collision(void)
{
- // can not rename a reference with the name of an existing reference
- git_reference *looked_up_ref;
+ // can not rename a reference with the name of an existing reference
+ git_reference *looked_up_ref, *renamed_ref;
/* An existing reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name));
/* Can not be renamed to the name of another existing reference. */
- cl_git_fail(git_reference_rename(looked_up_ref, packed_test_head_name, 0));
+ cl_git_fail(git_reference_rename(&renamed_ref, looked_up_ref, packed_test_head_name, 0));
git_reference_free(looked_up_ref);
/* Failure to rename it hasn't corrupted its state */
@@ -173,17 +177,21 @@ void test_refs_rename__name_collision(void)
void test_refs_rename__invalid_name(void)
{
- // can not rename a reference with an invalid name
- git_reference *looked_up_ref;
+ // can not rename a reference with an invalid name
+ git_reference *looked_up_ref, *renamed_ref;
/* An existing oid reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name));
/* Can not be renamed with an invalid name. */
- cl_git_fail(git_reference_rename(looked_up_ref, "Hello! I'm a very invalid name.", 0));
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC,
+ git_reference_rename(&renamed_ref, looked_up_ref, "Hello! I'm a very invalid name.", 0));
- /* Can not be renamed outside of the refs hierarchy. */
- cl_git_fail(git_reference_rename(looked_up_ref, "i-will-sudo-you", 0));
+ /* Can not be renamed outside of the refs hierarchy
+ * unless it's ALL_CAPS_AND_UNDERSCORES.
+ */
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_rename(&renamed_ref, looked_up_ref, "i-will-sudo-you", 0));
/* Failure to rename it hasn't corrupted its state */
git_reference_free(looked_up_ref);
@@ -195,22 +203,23 @@ void test_refs_rename__invalid_name(void)
void test_refs_rename__force_loose_packed(void)
{
- // can force-rename a packed reference with the name of an existing loose and packed reference
- git_reference *looked_up_ref;
+ // can force-rename a packed reference with the name of an existing loose and packed reference
+ git_reference *looked_up_ref, *renamed_ref;
git_oid oid;
/* An existing reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name));
- git_oid_cpy(&oid, git_reference_oid(looked_up_ref));
+ git_oid_cpy(&oid, git_reference_target(looked_up_ref));
/* Can be force-renamed to the name of another existing reference. */
- cl_git_pass(git_reference_rename(looked_up_ref, packed_test_head_name, 1));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, packed_test_head_name, 1));
git_reference_free(looked_up_ref);
+ git_reference_free(renamed_ref);
/* Check we actually renamed it */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name));
cl_assert_equal_s(looked_up_ref->name, packed_test_head_name);
- cl_assert(!git_oid_cmp(&oid, git_reference_oid(looked_up_ref)));
+ cl_assert(!git_oid_cmp(&oid, git_reference_target(looked_up_ref)));
git_reference_free(looked_up_ref);
/* And that the previous one doesn't exist any longer */
@@ -219,22 +228,23 @@ void test_refs_rename__force_loose_packed(void)
void test_refs_rename__force_loose(void)
{
- // can force-rename a loose reference with the name of an existing loose reference
- git_reference *looked_up_ref;
+ // can force-rename a loose reference with the name of an existing loose reference
+ git_reference *looked_up_ref, *renamed_ref;
git_oid oid;
/* An existing reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, "refs/heads/br2"));
- git_oid_cpy(&oid, git_reference_oid(looked_up_ref));
+ git_oid_cpy(&oid, git_reference_target(looked_up_ref));
/* Can be force-renamed to the name of another existing reference. */
- cl_git_pass(git_reference_rename(looked_up_ref, "refs/heads/test", 1));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, "refs/heads/test", 1));
git_reference_free(looked_up_ref);
+ git_reference_free(renamed_ref);
/* Check we actually renamed it */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, "refs/heads/test"));
cl_assert_equal_s(looked_up_ref->name, "refs/heads/test");
- cl_assert(!git_oid_cmp(&oid, git_reference_oid(looked_up_ref)));
+ cl_assert(!git_oid_cmp(&oid, git_reference_target(looked_up_ref)));
git_reference_free(looked_up_ref);
/* And that the previous one doesn't exist any longer */
@@ -246,24 +256,26 @@ void test_refs_rename__force_loose(void)
void test_refs_rename__overwrite(void)
{
- // can not overwrite name of existing reference
+ // can not overwrite name of existing reference
git_reference *ref, *ref_one, *ref_one_new, *ref_two;
+ git_refdb *refdb;
git_oid id;
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
/* Create loose references */
- cl_git_pass(git_reference_create_oid(&ref_one, g_repo, ref_one_name, &id, 0));
- cl_git_pass(git_reference_create_oid(&ref_two, g_repo, ref_two_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref_one, g_repo, ref_one_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0));
/* Pack everything */
- cl_git_pass(git_reference_packall(g_repo));
+ cl_git_pass(git_repository_refdb(&refdb, g_repo));
+ cl_git_pass(git_refdb_compress(refdb));
/* Attempt to create illegal reference */
- cl_git_fail(git_reference_create_oid(&ref_one_new, g_repo, ref_one_name_new, &id, 0));
+ cl_git_fail(git_reference_create(&ref_one_new, g_repo, ref_one_name_new, &id, 0));
/* Illegal reference couldn't be created so this is supposed to fail */
cl_git_fail(git_reference_lookup(&ref_one_new, g_repo, ref_one_name_new));
@@ -277,24 +289,25 @@ void test_refs_rename__overwrite(void)
void test_refs_rename__prefix(void)
{
- // can be renamed to a new name prefixed with the old name
- git_reference *ref, *ref_two, *looked_up_ref;
+ // can be renamed to a new name prefixed with the old name
+ git_reference *ref, *ref_two, *looked_up_ref, *renamed_ref;
git_oid id;
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
/* Create loose references */
- cl_git_pass(git_reference_create_oid(&ref_two, g_repo, ref_two_name, &id, 0));
+ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0));
/* An existing reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name));
/* Can be rename to a new name starting with the old name. */
- cl_git_pass(git_reference_rename(looked_up_ref, ref_two_name_new, 0));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name_new, 0));
git_reference_free(looked_up_ref);
+ git_reference_free(renamed_ref);
/* Check we actually renamed it */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new));
@@ -309,31 +322,44 @@ void test_refs_rename__prefix(void)
void test_refs_rename__move_up(void)
{
- // can move a reference to a upper reference hierarchy
- git_reference *ref, *ref_two, *looked_up_ref;
- git_oid id;
+ // can move a reference to a upper reference hierarchy
+ git_reference *ref, *ref_two, *looked_up_ref, *renamed_ref;
+ git_oid id;
- cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
- cl_assert(git_reference_type(ref) & GIT_REF_OID);
+ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
+ cl_assert(git_reference_type(ref) & GIT_REF_OID);
- git_oid_cpy(&id, git_reference_oid(ref));
+ git_oid_cpy(&id, git_reference_target(ref));
- /* Create loose references */
- cl_git_pass(git_reference_create_oid(&ref_two, g_repo, ref_two_name_new, &id, 0));
- git_reference_free(ref_two);
+ /* Create loose references */
+ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name_new, &id, 0));
+ git_reference_free(ref_two);
- /* An existing reference... */
- cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new));
+ /* An existing reference... */
+ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new));
- /* Can be renamed upward the reference tree. */
- cl_git_pass(git_reference_rename(looked_up_ref, ref_two_name, 0));
- git_reference_free(looked_up_ref);
+ /* Can be renamed upward the reference tree. */
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name, 0));
+ git_reference_free(looked_up_ref);
+ git_reference_free(renamed_ref);
- /* Check we actually renamed it */
- cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name));
- cl_assert_equal_s(looked_up_ref->name, ref_two_name);
- git_reference_free(looked_up_ref);
- cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new));
- git_reference_free(ref);
- git_reference_free(looked_up_ref);
+ /* Check we actually renamed it */
+ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name));
+ cl_assert_equal_s(looked_up_ref->name, ref_two_name);
+ git_reference_free(looked_up_ref);
+
+ cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new));
+ git_reference_free(ref);
+ git_reference_free(looked_up_ref);
+}
+
+void test_refs_rename__propagate_eexists(void)
+{
+ git_reference *ref, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, packed_head_name));
+
+ cl_assert_equal_i(GIT_EEXISTS, git_reference_rename(&new_ref, ref, packed_test_head_name, 0));
+
+ git_reference_free(ref);
}
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
new file mode 100644
index 000000000..74472b175
--- /dev/null
+++ b/tests-clar/refs/revparse.c
@@ -0,0 +1,697 @@
+#include "clar_libgit2.h"
+
+#include "git2/revparse.h"
+#include "buffer.h"
+#include "refs.h"
+#include "path.h"
+
+static git_repository *g_repo;
+static git_object *g_obj;
+
+/* Helpers */
+static void test_object_inrepo(const char *spec, const char *expected_oid, git_repository *repo)
+{
+ char objstr[64] = {0};
+ git_object *obj = NULL;
+ int error;
+
+ error = git_revparse_single(&obj, repo, spec);
+
+ if (expected_oid != NULL) {
+ cl_assert_equal_i(0, error);
+ git_oid_fmt(objstr, git_object_id(obj));
+ cl_assert_equal_s(objstr, expected_oid);
+ } else
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+
+ git_object_free(obj);
+}
+
+static void test_id_inrepo(
+ const char *spec,
+ const char *expected_left,
+ const char *expected_right,
+ git_revparse_mode_t expected_flags,
+ git_repository *repo)
+{
+ git_revspec revspec;
+ int error = git_revparse(&revspec, repo, spec);
+
+ if (expected_left) {
+ char str[64] = {0};
+ cl_assert_equal_i(0, error);
+ git_oid_fmt(str, git_object_id(revspec.from));
+ cl_assert_equal_s(str, expected_left);
+ git_object_free(revspec.from);
+ } else {
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+ }
+
+ if (expected_right) {
+ char str[64] = {0};
+ git_oid_fmt(str, git_object_id(revspec.to));
+ cl_assert_equal_s(str, expected_right);
+ git_object_free(revspec.to);
+ }
+
+ if (expected_flags)
+ cl_assert_equal_i(expected_flags, revspec.flags);
+}
+
+static void test_object(const char *spec, const char *expected_oid)
+{
+ test_object_inrepo(spec, expected_oid, g_repo);
+}
+
+static void test_rangelike(const char *rangelike,
+ const char *expected_left,
+ const char *expected_right,
+ git_revparse_mode_t expected_revparseflags)
+{
+ char objstr[64] = {0};
+ git_revspec revspec;
+ int error;
+
+ error = git_revparse(&revspec, g_repo, rangelike);
+
+ if (expected_left != NULL) {
+ cl_assert_equal_i(0, error);
+ cl_assert_equal_i(revspec.flags, expected_revparseflags);
+ git_oid_fmt(objstr, git_object_id(revspec.from));
+ cl_assert_equal_s(objstr, expected_left);
+ git_oid_fmt(objstr, git_object_id(revspec.to));
+ cl_assert_equal_s(objstr, expected_right);
+ } else
+ cl_assert(error != 0);
+
+ git_object_free(revspec.from);
+ git_object_free(revspec.to);
+}
+
+
+static void test_id(
+ const char *spec,
+ const char *expected_left,
+ const char *expected_right,
+ git_revparse_mode_t expected_flags)
+{
+ test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo);
+}
+
+void test_refs_revparse__initialize(void)
+{
+ cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
+}
+
+void test_refs_revparse__cleanup(void)
+{
+ git_repository_free(g_repo);
+}
+
+void test_refs_revparse__nonexistant_object(void)
+{
+ test_object("this-does-not-exist", NULL);
+ test_object("this-does-not-exist^1", NULL);
+ test_object("this-does-not-exist~2", NULL);
+}
+
+static void assert_invalid_single_spec(const char *invalid_spec)
+{
+ cl_assert_equal_i(
+ GIT_EINVALIDSPEC, git_revparse_single(&g_obj, g_repo, invalid_spec));
+}
+
+void test_refs_revparse__invalid_reference_name(void)
+{
+ assert_invalid_single_spec("this doesn't make sense");
+ assert_invalid_single_spec("Inv@{id");
+ assert_invalid_single_spec("");
+}
+
+void test_refs_revparse__shas(void)
+{
+ test_object("c47800c7266a2be04c571c04d5a6614691ea99bd", "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ test_object("c47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd");
+}
+
+void test_refs_revparse__head(void)
+{
+ test_object("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD^0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+}
+
+void test_refs_revparse__full_refs(void)
+{
+ test_object("refs/heads/master", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("refs/heads/test", "e90810b8df3e80c413d903f631643c716887138d");
+ test_object("refs/tags/test", "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
+}
+
+void test_refs_revparse__partial_refs(void)
+{
+ test_object("point_to_blob", "1385f264afb75a56a5bec74243be9b367ba4ca08");
+ test_object("packed-test", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
+ test_object("br2", "a4a7dce85cf63874e984719f4fdd239f5145052f");
+}
+
+void test_refs_revparse__describe_output(void)
+{
+ test_object("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ test_object("not-good", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+}
+
+void test_refs_revparse__nth_parent(void)
+{
+ assert_invalid_single_spec("be3563a^-1");
+ assert_invalid_single_spec("^");
+ assert_invalid_single_spec("be3563a^{tree}^");
+ assert_invalid_single_spec("point_to_blob^{blob}^");
+ assert_invalid_single_spec("this doesn't make sense^1");
+
+ test_object("be3563a^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("be3563a^", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("be3563a^2", "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ test_object("be3563a^1^1", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
+ test_object("be3563a^^", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
+ test_object("be3563a^2^1", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ test_object("be3563a^0", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("be3563a^{commit}^", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+
+ test_object("be3563a^42", NULL);
+}
+
+void test_refs_revparse__not_tag(void)
+{
+ test_object("point_to_blob^{}", "1385f264afb75a56a5bec74243be9b367ba4ca08");
+ test_object("wrapped_tag^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master^{tree}^{}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
+ test_object("e90810b^{}", "e90810b8df3e80c413d903f631643c716887138d");
+ test_object("tags/e90810b^{}", "e90810b8df3e80c413d903f631643c716887138d");
+ test_object("e908^{}", "e90810b8df3e80c413d903f631643c716887138d");
+}
+
+void test_refs_revparse__to_type(void)
+{
+ assert_invalid_single_spec("wrapped_tag^{trip}");
+ test_object("point_to_blob^{commit}", NULL);
+ cl_assert_equal_i(
+ GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}"));
+
+ test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
+ test_object("point_to_blob^{blob}", "1385f264afb75a56a5bec74243be9b367ba4ca08");
+ test_object("master^{commit}^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+}
+
+void test_refs_revparse__linear_history(void)
+{
+ assert_invalid_single_spec("~");
+ test_object("foo~bar", NULL);
+
+ assert_invalid_single_spec("master~bar");
+ assert_invalid_single_spec("master~-1");
+ assert_invalid_single_spec("master~0bar");
+ assert_invalid_single_spec("this doesn't make sense~2");
+ assert_invalid_single_spec("be3563a^{tree}~");
+ assert_invalid_single_spec("point_to_blob^{blob}~");
+
+ test_object("master~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master~1", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("master~2", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("master~1~1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("master~~", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+}
+
+void test_refs_revparse__chaining(void)
+{
+ assert_invalid_single_spec("master@{0}@{0}");
+ assert_invalid_single_spec("@{u}@{-1}");
+ assert_invalid_single_spec("@{-1}@{-1}");
+ assert_invalid_single_spec("@{-3}@{0}");
+
+ test_object("master@{0}~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("@{u}@{0}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("@{-1}@{0}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
+ test_object("@{-4}@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("master~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("master~1^2", "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ test_object("master^1^2~1", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ test_object("master^^2^", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ test_object("master^1^1^1^1^1", "8496071c1b46c854b31185ea97743be6a8774479");
+ test_object("master^^1^2^1", NULL);
+}
+
+void test_refs_revparse__upstream(void)
+{
+ assert_invalid_single_spec("e90810b@{u}");
+ assert_invalid_single_spec("refs/tags/e90810b@{u}");
+ test_object("refs/heads/e90810b@{u}", NULL);
+
+ test_object("master@{upstream}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("heads/master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("refs/heads/master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+}
+
+void test_refs_revparse__ordinal(void)
+{
+ assert_invalid_single_spec("master@{-2}");
+
+ /* TODO: make the test below actually fail
+ * cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
+ */
+
+ test_object("nope@{0}", NULL);
+ test_object("master@{31415}", NULL);
+ test_object("@{1000}", NULL);
+ test_object("@{2}", NULL);
+
+ test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+
+ test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("refs/heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+}
+
+void test_refs_revparse__previous_head(void)
+{
+ assert_invalid_single_spec("@{-xyz}");
+ assert_invalid_single_spec("@{-0}");
+ assert_invalid_single_spec("@{-1b}");
+
+ test_object("@{-42}", NULL);
+
+ test_object("@{-2}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("@{-1}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
+}
+
+static void create_fake_stash_reference_and_reflog(git_repository *repo)
+{
+ git_reference *master, *new_master;
+ git_buf log_path = GIT_BUF_INIT;
+
+ git_buf_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
+
+ cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&log_path)));
+
+ cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
+ cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0));
+ git_reference_free(master);
+
+ cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+
+ git_buf_free(&log_path);
+ git_reference_free(new_master);
+}
+
+void test_refs_revparse__reflog_of_a_ref_under_refs(void)
+{
+ git_repository *repo = cl_git_sandbox_init("testrepo.git");
+
+ test_object_inrepo("refs/fakestash", NULL, repo);
+
+ create_fake_stash_reference_and_reflog(repo);
+
+ /*
+ * $ git reflog -1 refs/fakestash
+ * a65fedf refs/fakestash@{0}: commit: checking in
+ *
+ * $ git reflog -1 refs/fakestash@{0}
+ * a65fedf refs/fakestash@{0}: commit: checking in
+ *
+ * $ git reflog -1 fakestash
+ * a65fedf fakestash@{0}: commit: checking in
+ *
+ * $ git reflog -1 fakestash@{0}
+ * a65fedf fakestash@{0}: commit: checking in
+ */
+ test_object_inrepo("refs/fakestash", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
+ test_object_inrepo("refs/fakestash@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
+ test_object_inrepo("fakestash", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
+ test_object_inrepo("fakestash@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_revparse__revwalk(void)
+{
+ test_object("master^{/not found in any commit}", NULL);
+ test_object("master^{/merge}", NULL);
+ assert_invalid_single_spec("master^{/((}");
+
+ test_object("master^{/anoth}", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ test_object("master^{/Merge}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("br2^{/Merge}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
+ test_object("master^{/fo.rth}", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+}
+
+void test_refs_revparse__date(void)
+{
+ /*
+ * $ git reflog HEAD --date=iso
+ * a65fedf HEAD@{2012-04-30 08:23:41 -0900}: checkout: moving from br2 to master
+ * a4a7dce HEAD@{2012-04-30 08:23:37 -0900}: commit: checking in
+ * c47800c HEAD@{2012-04-30 08:23:28 -0900}: checkout: moving from master to br2
+ * a65fedf HEAD@{2012-04-30 08:23:23 -0900}: commit:
+ * be3563a HEAD@{2012-04-30 10:22:43 -0700}: clone: from /Users/ben/src/libgit2/tes
+ *
+ * $ git reflog HEAD --date=raw
+ * a65fedf HEAD@{1335806621 -0900}: checkout: moving from br2 to master
+ * a4a7dce HEAD@{1335806617 -0900}: commit: checking in
+ * c47800c HEAD@{1335806608 -0900}: checkout: moving from master to br2
+ * a65fedf HEAD@{1335806603 -0900}: commit:
+ * be3563a HEAD@{1335806563 -0700}: clone: from /Users/ben/src/libgit2/tests/resour
+ */
+ test_object("HEAD@{10 years ago}", NULL);
+
+ test_object("HEAD@{1 second}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD@{1 second ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD@{2 days ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+
+ /*
+ * $ git reflog master --date=iso
+ * a65fedf master@{2012-04-30 09:23:23 -0800}: commit: checking in
+ * be3563a master@{2012-04-30 09:22:43 -0800}: clone: from /Users/ben/src...
+ *
+ * $ git reflog master --date=raw
+ * a65fedf master@{1335806603 -0800}: commit: checking in
+ * be3563a master@{1335806563 -0800}: clone: from /Users/ben/src/libgit2/tests/reso
+ */
+
+
+ /*
+ * $ git reflog -1 "master@{2012-04-30 17:22:42 +0000}"
+ * warning: Log for 'master' only goes back to Mon, 30 Apr 2012 09:22:43 -0800.
+ */
+ test_object("master@{2012-04-30 17:22:42 +0000}", NULL);
+ test_object("master@{2012-04-30 09:22:42 -0800}", NULL);
+
+ /*
+ * $ git reflog -1 "master@{2012-04-30 17:22:43 +0000}"
+ * be3563a master@{Mon Apr 30 09:22:43 2012 -0800}: clone: from /Users/ben/src/libg
+ */
+ test_object("master@{2012-04-30 17:22:43 +0000}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("master@{2012-04-30 09:22:43 -0800}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+
+ /*
+ * $ git reflog -1 "master@{2012-4-30 09:23:27 -0800}"
+ * a65fedf master@{Mon Apr 30 09:23:23 2012 -0800}: commit: checking in
+ */
+ test_object("master@{2012-4-30 09:23:27 -0800}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+
+ /*
+ * $ git reflog -1 master@{2012-05-03}
+ * a65fedf master@{Mon Apr 30 09:23:23 2012 -0800}: commit: checking in
+ */
+ test_object("master@{2012-05-03}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+
+ /*
+ * $ git reflog -1 "master@{1335806603}"
+ * a65fedf
+ *
+ * $ git reflog -1 "master@{1335806602}"
+ * be3563a
+ */
+ test_object("master@{1335806603}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master@{1335806602}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+}
+
+void test_refs_revparse__colon(void)
+{
+ assert_invalid_single_spec(":/");
+ assert_invalid_single_spec("point_to_blob:readme.txt");
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, ":2:README")); /* Not implemented */
+
+ test_object(":/not found in any commit", NULL);
+ test_object("subtrees:ab/42.txt", NULL);
+ test_object("subtrees:ab/4.txt/nope", NULL);
+ test_object("subtrees:nope", NULL);
+ test_object("test/master^1:branch_file.txt", NULL);
+
+ /* From tags */
+ test_object("test:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
+ test_object("tags/test:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
+ test_object("e90810b:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
+ test_object("tags/e90810b:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
+
+ /* From commits */
+ test_object("a65f:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
+
+ /* From trees */
+ test_object("a65f^{tree}:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
+ test_object("944c:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
+
+ /* Retrieving trees */
+ test_object("master:", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
+ test_object("subtrees:", "ae90f12eea699729ed24555e40b9fd669da12a12");
+ test_object("subtrees:ab", "f1425cef211cc08caa31e7b545ffb232acb098c3");
+ test_object("subtrees:ab/", "f1425cef211cc08caa31e7b545ffb232acb098c3");
+
+ /* Retrieving blobs */
+ test_object("subtrees:ab/4.txt", "d6c93164c249c8000205dd4ec5cbca1b516d487f");
+ test_object("subtrees:ab/de/fgh/1.txt", "1f67fc4386b2d171e0d21be1c447e12660561f9b");
+ test_object("master:README", "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ test_object("master:new.txt", "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
+ test_object(":/Merge", "a4a7dce85cf63874e984719f4fdd239f5145052f");
+ test_object(":/one", "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ test_object(":/packed commit t", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9");
+ test_object("test/master^2:branch_file.txt", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
+ test_object("test/master@{1}:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
+}
+
+void test_refs_revparse__disambiguation(void)
+{
+ /*
+ * $ git show e90810b
+ * tag e90810b
+ * Tagger: Vicent Marti <tanoku@gmail.com>
+ * Date: Thu Aug 12 03:59:17 2010 +0200
+ *
+ * This is a very simple tag.
+ *
+ * commit e90810b8df3e80c413d903f631643c716887138d
+ * Author: Vicent Marti <tanoku@gmail.com>
+ * Date: Thu Aug 5 18:42:20 2010 +0200
+ *
+ * Test commit 2
+ *
+ * diff --git a/readme.txt b/readme.txt
+ * index 6336846..0266163 100644
+ * --- a/readme.txt
+ * +++ b/readme.txt
+ * @@ -1 +1,2 @@
+ * Testing a readme.txt
+ * +Now we add a single line here
+ *
+ * $ git show-ref e90810b
+ * 7b4384978d2493e851f9cca7858815fac9b10980 refs/tags/e90810b
+ *
+ */
+ test_object("e90810b", "7b4384978d2493e851f9cca7858815fac9b10980");
+
+ /*
+ * $ git show e90810
+ * commit e90810b8df3e80c413d903f631643c716887138d
+ * Author: Vicent Marti <tanoku@gmail.com>
+ * Date: Thu Aug 5 18:42:20 2010 +0200
+ *
+ * Test commit 2
+ *
+ * diff --git a/readme.txt b/readme.txt
+ * index 6336846..0266163 100644
+ * --- a/readme.txt
+ * +++ b/readme.txt
+ * @@ -1 +1,2 @@
+ * Testing a readme.txt
+ * +Now we add a single line here
+ */
+ test_object("e90810", "e90810b8df3e80c413d903f631643c716887138d");
+}
+
+void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void)
+{
+ cl_assert_equal_i(
+ GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "e90"));
+}
+
+void test_refs_revparse__issue_994(void)
+{
+ git_repository *repo;
+ git_reference *head, *with_at;
+ git_object *target;
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296"));
+
+
+ cl_git_pass(git_repository_head(&head, repo));
+ cl_git_pass(git_reference_create(
+ &with_at,
+ repo,
+ "refs/remotes/origin/bim_with_3d@11296",
+ git_reference_target(head),
+ 0));
+
+ cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
+ git_object_free(target);
+
+ cl_git_pass(git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296"));
+ git_object_free(target);
+
+ git_reference_free(with_at);
+ git_reference_free(head);
+ cl_git_sandbox_cleanup();
+}
+
+/**
+ * $ git rev-parse blah-7-gc47800c
+ * c47800c7266a2be04c571c04d5a6614691ea99bd
+ *
+ * $ git rev-parse HEAD~3
+ * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ *
+ * $ git branch blah-7-gc47800c HEAD~3
+ *
+ * $ git rev-parse blah-7-gc47800c
+ * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ */
+void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void)
+{
+ git_repository *repo;
+ git_reference *branch;
+ git_object *target;
+ char sha[GIT_OID_HEXSZ + 1];
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
+
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
+ cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0));
+
+ git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
+
+ test_object_inrepo("blah-7-gc47800c", sha, repo);
+
+ git_reference_free(branch);
+ git_object_free(target);
+ cl_git_sandbox_cleanup();
+}
+
+/**
+ * $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ *
+ * $ git rev-parse HEAD~3
+ * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ *
+ * $ git branch a65fedf39aefe402d3bb6e24df4d4f5fe4547750 HEAD~3
+ *
+ * $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ *
+ * $ git rev-parse heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ */
+void test_refs_revparse__try_to_retrieve_sha_before_branch(void)
+{
+ git_repository *repo;
+ git_reference *branch;
+ git_object *target;
+ char sha[GIT_OID_HEXSZ + 1];
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
+
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
+ cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0));
+
+ git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
+
+ test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
+ test_object_inrepo("heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750", sha, repo);
+
+ git_reference_free(branch);
+ git_object_free(target);
+ cl_git_sandbox_cleanup();
+}
+
+/**
+ * $ git rev-parse c47800
+ * c47800c7266a2be04c571c04d5a6614691ea99bd
+ *
+ * $ git rev-parse HEAD~3
+ * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ *
+ * $ git branch c47800 HEAD~3
+ *
+ * $ git rev-parse c47800
+ * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ */
+void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
+{
+ git_repository *repo;
+ git_reference *branch;
+ git_object *target;
+ char sha[GIT_OID_HEXSZ + 1];
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
+
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
+ cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0));
+
+ git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
+
+ test_object_inrepo("c47800", sha, repo);
+
+ git_reference_free(branch);
+ git_object_free(target);
+ cl_git_sandbox_cleanup();
+}
+
+
+void test_refs_revparse__range(void)
+{
+ assert_invalid_single_spec("be3563a^1..be3563a");
+
+ test_rangelike("be3563a^1..be3563a",
+ "9fd738e8f7967c078dceed8190330fc8648ee56a",
+ "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
+ GIT_REVPARSE_RANGE);
+
+ test_rangelike("be3563a^1...be3563a",
+ "9fd738e8f7967c078dceed8190330fc8648ee56a",
+ "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
+ GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+
+ test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
+}
+
+void test_refs_revparse__parses_range_operator(void)
+{
+ test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE);
+ test_id("HEAD~3..HEAD",
+ "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ GIT_REVPARSE_RANGE);
+
+ test_id("HEAD~3...HEAD",
+ "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+}
+
diff --git a/tests-clar/refs/setter.c b/tests-clar/refs/setter.c
new file mode 100644
index 000000000..713af814f
--- /dev/null
+++ b/tests-clar/refs/setter.c
@@ -0,0 +1,99 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "git2/reflog.h"
+#include "reflog.h"
+#include "git2/refs.h"
+
+static const char *ref_name = "refs/heads/other";
+static const char *ref_master_name = "refs/heads/master";
+static const char *ref_test_name = "refs/heads/test";
+
+static git_repository *g_repo;
+
+void test_refs_setter__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_refs_setter__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_setter__update_direct(void)
+{
+ git_reference *ref, *test_ref, *new_ref;
+ git_oid id;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
+ cl_assert(git_reference_type(ref) == GIT_REF_OID);
+ git_oid_cpy(&id, git_reference_target(ref));
+ git_reference_free(ref);
+
+ cl_git_pass(git_reference_lookup(&test_ref, g_repo, ref_test_name));
+ cl_assert(git_reference_type(test_ref) == GIT_REF_OID);
+
+ cl_git_pass(git_reference_set_target(&new_ref, test_ref, &id));
+
+ git_reference_free(test_ref);
+ git_reference_free(new_ref);
+
+ cl_git_pass(git_reference_lookup(&test_ref, g_repo, ref_test_name));
+ cl_assert(git_reference_type(test_ref) == GIT_REF_OID);
+ cl_assert(git_oid_cmp(&id, git_reference_target(test_ref)) == 0);
+ git_reference_free(test_ref);
+}
+
+void test_refs_setter__update_symbolic(void)
+{
+ git_reference *head, *new_head;
+
+ cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
+ cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC);
+ cl_assert(strcmp(git_reference_symbolic_target(head), ref_master_name) == 0);
+
+ cl_git_pass(git_reference_symbolic_set_target(&new_head, head, ref_test_name));
+ git_reference_free(new_head);
+ git_reference_free(head);
+
+ cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
+ cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC);
+ cl_assert(strcmp(git_reference_symbolic_target(head), ref_test_name) == 0);
+ git_reference_free(head);
+}
+
+void test_refs_setter__cant_update_direct_with_symbolic(void)
+{
+ // Overwrite an existing object id reference with a symbolic one
+ git_reference *ref, *new;
+ git_oid id;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
+ cl_assert(git_reference_type(ref) == GIT_REF_OID);
+ git_oid_cpy(&id, git_reference_target(ref));
+
+ cl_git_fail(git_reference_symbolic_set_target(&new, ref, ref_name));
+
+ git_reference_free(ref);
+}
+
+void test_refs_setter__cant_update_symbolic_with_direct(void)
+{
+ // Overwrite an existing symbolic reference with an object id one
+ git_reference *ref, *new;
+ git_oid id;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
+ cl_assert(git_reference_type(ref) == GIT_REF_OID);
+ git_oid_cpy(&id, git_reference_target(ref));
+ git_reference_free(ref);
+
+ /* Create the symbolic ref */
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0));
+
+ /* Can't set an OID on a direct ref */
+ cl_git_fail(git_reference_set_target(&new, ref, &id));
+
+ git_reference_free(ref);
+}
diff --git a/tests-clar/refs/unicode.c b/tests-clar/refs/unicode.c
index 889c85666..2ec103275 100644
--- a/tests-clar/refs/unicode.c
+++ b/tests-clar/refs/unicode.c
@@ -12,6 +12,8 @@ void test_refs_unicode__initialize(void)
void test_refs_unicode__cleanup(void)
{
git_repository_free(repo);
+ repo = NULL;
+
cl_fixture_cleanup("testrepo.git");
}
@@ -25,15 +27,15 @@ void test_refs_unicode__create_and_lookup(void)
/* Create the reference */
cl_git_pass(git_reference_lookup(&ref0, repo, master));
- cl_git_pass(git_reference_create_oid(&ref1, repo, REFNAME, git_reference_oid(ref0), 0));
- cl_assert(strcmp(REFNAME, git_reference_name(ref1)) == 0);
+ cl_git_pass(git_reference_create(&ref1, repo, REFNAME, git_reference_target(ref0), 0));
+ cl_assert_equal_s(REFNAME, git_reference_name(ref1));
/* Lookup the reference in a different instance of the repository */
cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME));
- cl_assert(git_oid_cmp(git_reference_oid(ref1), git_reference_oid(ref2)) == 0);
- cl_assert(strcmp(REFNAME, git_reference_name(ref2)) == 0);
+ cl_assert(git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2)) == 0);
+ cl_assert_equal_s(REFNAME, git_reference_name(ref2));
git_reference_free(ref0);
git_reference_free(ref1);
diff --git a/tests-clar/refs/update.c b/tests-clar/refs/update.c
new file mode 100644
index 000000000..205b526a2
--- /dev/null
+++ b/tests-clar/refs/update.c
@@ -0,0 +1,26 @@
+#include "clar_libgit2.h"
+
+#include "refs.h"
+
+static git_repository *g_repo;
+
+void test_refs_update__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_refs_update__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_update__updating_the_target_of_a_symref_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+ git_reference *head;
+
+ cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
+ git_reference_free(head);
+
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create(&head, g_repo, GIT_HEAD_FILE, "refs/heads/inv@{id", 1));
+}
diff --git a/tests-clar/repo/discover.c b/tests-clar/repo/discover.c
index b3d639bd1..3d9aeedd7 100644
--- a/tests-clar/repo/discover.c
+++ b/tests-clar/repo/discover.c
@@ -135,7 +135,7 @@ void test_repo_discover__0(void)
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path);
- cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_RMDIR_REMOVE_FILES));
git_repository_free(repo);
git_buf_free(&ceiling_dirs_buf);
}
diff --git a/tests-clar/repo/getters.c b/tests-clar/repo/getters.c
index 966de1f16..b372f5b70 100644
--- a/tests-clar/repo/getters.c
+++ b/tests-clar/repo/getters.c
@@ -1,71 +1,25 @@
#include "clar_libgit2.h"
-void test_repo_getters__initialize(void)
-{
- cl_fixture_sandbox("testrepo.git");
-}
-
-void test_repo_getters__cleanup(void)
-{
- cl_fixture_cleanup("testrepo.git");
-}
-
-void test_repo_getters__empty(void)
-{
- git_repository *repo_empty, *repo_normal;
-
- cl_git_pass(git_repository_open(&repo_normal, cl_fixture("testrepo.git")));
- cl_assert(git_repository_is_empty(repo_normal) == 0);
- git_repository_free(repo_normal);
-
- cl_git_pass(git_repository_open(&repo_empty, cl_fixture("empty_bare.git")));
- cl_assert(git_repository_is_empty(repo_empty) == 1);
- git_repository_free(repo_empty);
-}
-
-void test_repo_getters__head_detached(void)
+void test_repo_getters__is_empty_correctly_deals_with_pristine_looking_repos(void)
{
git_repository *repo;
- git_reference *ref;
- git_oid oid;
-
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
- cl_assert(git_repository_head_detached(repo) == 0);
+ repo = cl_git_sandbox_init("empty_bare.git");
+ cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
- /* detach the HEAD */
- git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
- cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1));
- cl_assert(git_repository_head_detached(repo) == 1);
- git_reference_free(ref);
+ cl_assert_equal_i(true, git_repository_is_empty(repo));
- /* take the reop back to it's original state */
- cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
- cl_assert(git_repository_head_detached(repo) == 0);
-
- git_reference_free(ref);
- git_repository_free(repo);
+ cl_git_sandbox_cleanup();
}
-void test_repo_getters__head_orphan(void)
+void test_repo_getters__is_empty_can_detect_used_repositories(void)
{
git_repository *repo;
- git_reference *ref;
-
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
-
- cl_assert(git_repository_head_orphan(repo) == 0);
- /* orphan HEAD */
- cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1));
- cl_assert(git_repository_head_orphan(repo) == 1);
- git_reference_free(ref);
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- /* take the reop back to it's original state */
- cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
- cl_assert(git_repository_head_orphan(repo) == 0);
+ cl_assert_equal_i(false, git_repository_is_empty(repo));
- git_reference_free(ref);
git_repository_free(repo);
}
@@ -74,7 +28,7 @@ void test_repo_getters__retrieving_the_odb_honors_the_refcount(void)
git_odb *odb;
git_repository *repo;
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_odb(&odb, repo));
cl_assert(((git_refcount *)odb)->refcount == 2);
diff --git a/tests-clar/repo/hashfile.c b/tests-clar/repo/hashfile.c
new file mode 100644
index 000000000..4cc9f18b4
--- /dev/null
+++ b/tests-clar/repo/hashfile.c
@@ -0,0 +1,85 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+
+static git_repository *_repo;
+
+void test_repo_hashfile__initialize(void)
+{
+ _repo = cl_git_sandbox_init("status");
+}
+
+void test_repo_hashfile__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ _repo = NULL;
+}
+
+void test_repo_hashfile__simple(void)
+{
+ git_oid a, b;
+ git_buf full = GIT_BUF_INIT;
+
+ /* hash with repo relative path */
+ cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJ_BLOB, NULL));
+ cl_assert(git_oid_equal(&a, &b));
+
+ cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file"));
+
+ /* hash with full path */
+ cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_BLOB, NULL));
+ cl_assert(git_oid_equal(&a, &b));
+
+ /* hash with invalid type */
+ cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJ_ANY));
+ cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_OFS_DELTA, NULL));
+
+ git_buf_free(&full);
+}
+
+void test_repo_hashfile__filtered(void)
+{
+ git_oid a, b;
+
+ cl_repo_set_bool(_repo, "core.autocrlf", true);
+
+ cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
+
+ /* create some sample content with CRLF in it */
+ cl_git_mkfile("status/testfile.txt", "content\r\n");
+ cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n");
+
+ /* not equal hashes because of filtering */
+ cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, NULL));
+ cl_assert(git_oid_cmp(&a, &b));
+
+ /* equal hashes because filter is binary */
+ cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, NULL));
+ cl_assert(git_oid_equal(&a, &b));
+
+ /* equal hashes when 'as_file' points to binary filtering */
+ cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, "foo.bin"));
+ cl_assert(git_oid_equal(&a, &b));
+
+ /* not equal hashes when 'as_file' points to text filtering */
+ cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, "foo.txt"));
+ cl_assert(git_oid_cmp(&a, &b));
+
+ /* equal hashes when 'as_file' is empty and turns off filtering */
+ cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, ""));
+ cl_assert(git_oid_equal(&a, &b));
+
+ cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
+ cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, ""));
+ cl_assert(git_oid_equal(&a, &b));
+
+ /* some hash type failures */
+ cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
+ cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_ANY, NULL));
+}
diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c
new file mode 100644
index 000000000..a9f5cfc58
--- /dev/null
+++ b/tests-clar/repo/head.c
@@ -0,0 +1,196 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "repo_helpers.h"
+#include "posix.h"
+
+static git_repository *repo;
+
+void test_repo_head__initialize(void)
+{
+ repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_repo_head__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_repo_head__head_detached(void)
+{
+ git_reference *ref;
+
+ cl_git_pass(git_repository_head_detached(repo));
+
+ cl_git_pass(git_repository_detach_head(repo));
+
+ cl_assert_equal_i(true, git_repository_head_detached(repo));
+
+ /* take the reop back to it's original state */
+ cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1));
+ git_reference_free(ref);
+
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+}
+
+void test_repo_head__head_orphan(void)
+{
+ git_reference *ref;
+
+ cl_git_pass(git_repository_head_detached(repo));
+
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert(git_repository_head_orphan(repo) == 1);
+
+
+ /* take the repo back to it's original state */
+ cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1));
+ cl_assert(git_repository_head_orphan(repo) == 0);
+
+ git_reference_free(ref);
+}
+
+void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_doesnt_exist(void)
+{
+ git_reference *head;
+
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet"));
+
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo));
+}
+
+void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void)
+{
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet"));
+}
+
+void test_repo_head__set_head_Fails_when_the_reference_points_to_a_non_commitish(void)
+{
+ cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob"));
+}
+
+void test_repo_head__set_head_Attaches_HEAD_when_the_reference_points_to_a_branch(void)
+{
+ git_reference *head;
+
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/br2"));
+
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+
+ cl_git_pass(git_repository_head(&head, repo));
+ cl_assert_equal_s("refs/heads/br2", git_reference_name(head));
+
+ git_reference_free(head);
+}
+
+static void assert_head_is_correctly_detached(void)
+{
+ git_reference *head;
+ git_object *commit;
+
+ cl_assert_equal_i(true, git_repository_head_detached(repo));
+
+ cl_git_pass(git_repository_head(&head, repo));
+
+ cl_git_pass(git_object_lookup(&commit, repo, git_reference_target(head), GIT_OBJ_COMMIT));
+
+ git_object_free(commit);
+ git_reference_free(head);
+}
+
+void test_repo_head__set_head_Detaches_HEAD_when_the_reference_doesnt_point_to_a_branch(void)
+{
+ cl_git_pass(git_repository_set_head(repo, "refs/tags/test"));
+
+ cl_assert_equal_i(true, git_repository_head_detached(repo));
+
+ assert_head_is_correctly_detached();
+}
+
+void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_exist(void)
+{
+ git_oid oid;
+
+ cl_git_pass(git_oid_fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid));
+}
+
+void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void)
+{
+ git_object *blob;
+
+ cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob"));
+
+ cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob)));
+
+ git_object_free(blob);
+}
+
+void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void)
+{
+ git_object *tag;
+
+ cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
+ cl_assert_equal_i(GIT_OBJ_TAG, git_object_type(tag));
+
+ cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
+
+ assert_head_is_correctly_detached();
+
+ git_object_free(tag);
+}
+
+void test_repo_head__detach_head_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void)
+{
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+
+ cl_git_pass(git_repository_detach_head(repo));
+
+ assert_head_is_correctly_detached();
+}
+
+void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void)
+{
+ git_reference *head;
+
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1));
+
+ cl_git_fail(git_repository_detach_head(repo));
+
+ git_reference_free(head);
+}
+
+void test_repo_head__detaching_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
+{
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_detach_head(repo));
+}
+
+void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
+{
+ git_reference *head;
+
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo));
+}
+
+void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void)
+{
+ git_reference *head;
+
+ delete_head(repo);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo));
+}
+
+void test_repo_head__can_tell_if_an_orphaned_head_is_detached(void)
+{
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+}
diff --git a/tests-clar/repo/headtree.c b/tests-clar/repo/headtree.c
new file mode 100644
index 000000000..0e7fe93e5
--- /dev/null
+++ b/tests-clar/repo/headtree.c
@@ -0,0 +1,53 @@
+#include "clar_libgit2.h"
+#include "repository.h"
+#include "repo_helpers.h"
+#include "posix.h"
+
+static git_repository *repo;
+static git_tree *tree;
+
+void test_repo_headtree__initialize(void)
+{
+ repo = cl_git_sandbox_init("testrepo.git");
+ tree = NULL;
+}
+
+void test_repo_headtree__cleanup(void)
+{
+ git_tree_free(tree);
+ cl_git_sandbox_cleanup();
+}
+
+void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void)
+{
+ cl_git_pass(git_repository_detach_head(repo));
+
+ cl_git_pass(git_repository_head_tree(&tree, repo));
+
+ cl_assert(git_oid_streq(git_tree_id(tree), "az"));
+}
+
+void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(void)
+{
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+
+ cl_git_pass(git_repository_head_tree(&tree, repo));
+
+ cl_assert(git_oid_streq(git_tree_id(tree), "az"));
+}
+
+void test_repo_headtree__when_head_is_orphaned_returns_EORPHANEDHEAD(void)
+{
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(true, git_repository_head_orphan(repo));
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head_tree(&tree, repo));
+}
+
+void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void)
+{
+ delete_head(repo);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head_tree(&tree, repo));
+}
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index 7f16b5b7c..8cf73795f 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -2,13 +2,14 @@
#include "fileops.h"
#include "repository.h"
#include "config.h"
+#include "path.h"
enum repo_mode {
STANDARD_REPOSITORY = 0,
BARE_REPOSITORY = 1
};
-static git_repository *_repo;
+static git_repository *_repo = NULL;
void test_repo_init__initialize(void)
{
@@ -18,6 +19,8 @@ void test_repo_init__initialize(void)
static void cleanup_repository(void *path)
{
git_repository_free(_repo);
+ _repo = NULL;
+
cl_fixture_cleanup((const char *)path);
}
@@ -29,6 +32,8 @@ static void ensure_repository_init(
{
const char *workdir;
+ cl_assert(!git_path_isdir(working_directory));
+
cl_git_pass(git_repository_init(&_repo, working_directory, is_bare));
workdir = git_repository_workdir(_repo);
@@ -46,7 +51,8 @@ static void ensure_repository_init(
#ifdef GIT_WIN32
if (!is_bare) {
- cl_assert((GetFileAttributes(git_repository_path(_repo)) & FILE_ATTRIBUTE_HIDDEN) != 0);
+ DWORD fattrs = GetFileAttributes(git_repository_path(_repo));
+ cl_assert((fattrs & FILE_ATTRIBUTE_HIDDEN) != 0);
}
#endif
@@ -83,7 +89,7 @@ void test_repo_init__bare_repo_escaping_current_workdir(void)
git_buf path_current_workdir = GIT_BUF_INIT;
cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
-
+
cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c"));
cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), NULL, GIT_DIR_MODE));
@@ -165,3 +171,362 @@ void test_repo_init__additional_templates(void)
git_buf_free(&path);
}
+
+static void assert_config_entry_on_init_bytype(const char *config_key, int expected_value, bool is_bare)
+{
+ git_config *config;
+ int current_value;
+ git_buf repo_path = GIT_BUF_INIT;
+
+ cl_set_cleanup(&cleanup_repository, "config_entry");
+
+ cl_git_pass(git_buf_puts(&repo_path, "config_entry/test."));
+
+ if (!is_bare)
+ cl_git_pass(git_buf_puts(&repo_path, "non."));
+
+ cl_git_pass(git_buf_puts(&repo_path, "bare.git"));
+
+ cl_git_pass(git_repository_init(&_repo, git_buf_cstr(&repo_path), is_bare));
+
+ git_buf_free(&repo_path);
+
+ git_repository_config(&config, _repo);
+
+ if (expected_value >= 0) {
+ cl_git_pass(git_config_get_bool(&current_value, config, config_key));
+
+ cl_assert_equal_i(expected_value, current_value);
+ } else {
+ int error = git_config_get_bool(&current_value, config, config_key);
+
+ cl_assert_equal_i(expected_value, error);
+ }
+
+ git_config_free(config);
+}
+
+static void assert_config_entry_on_init(const char *config_key, int expected_value)
+{
+ assert_config_entry_on_init_bytype(config_key, expected_value, true);
+ git_repository_free(_repo);
+
+ assert_config_entry_on_init_bytype(config_key, expected_value, false);
+}
+
+void test_repo_init__detect_filemode(void)
+{
+#ifdef GIT_WIN32
+ assert_config_entry_on_init("core.filemode", false);
+#else
+ assert_config_entry_on_init("core.filemode", true);
+#endif
+}
+
+#define CASE_INSENSITIVE_FILESYSTEM (defined GIT_WIN32 || defined __APPLE__)
+
+void test_repo_init__detect_ignorecase(void)
+{
+#if CASE_INSENSITIVE_FILESYSTEM
+ assert_config_entry_on_init("core.ignorecase", true);
+#else
+ assert_config_entry_on_init("core.ignorecase", GIT_ENOTFOUND);
+#endif
+}
+
+void test_repo_init__reinit_doesnot_overwrite_ignorecase(void)
+{
+ git_config *config;
+ int current_value;
+
+ /* Init a new repo */
+ cl_set_cleanup(&cleanup_repository, "not.overwrite.git");
+ cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1));
+
+ /* Change the "core.ignorecase" config value to something unlikely */
+ git_repository_config(&config, _repo);
+ git_config_set_int32(config, "core.ignorecase", 42);
+ git_config_free(config);
+ git_repository_free(_repo);
+ _repo = NULL;
+
+ /* Reinit the repository */
+ cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1));
+ git_repository_config(&config, _repo);
+
+ /* Ensure the "core.ignorecase" config value hasn't been updated */
+ cl_git_pass(git_config_get_int32(&current_value, config, "core.ignorecase"));
+ cl_assert_equal_i(42, current_value);
+
+ git_config_free(config);
+}
+
+void test_repo_init__reinit_overwrites_filemode(void)
+{
+ git_config *config;
+ int expected, current_value;
+
+#ifdef GIT_WIN32
+ expected = false;
+#else
+ expected = true;
+#endif
+
+ /* Init a new repo */
+ cl_set_cleanup(&cleanup_repository, "overwrite.git");
+ cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
+
+ /* Change the "core.filemode" config value to something unlikely */
+ cl_repo_set_bool(_repo, "core.filemode", !expected);
+
+ git_repository_free(_repo);
+ _repo = NULL;
+
+ /* Reinit the repository */
+ cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
+ git_repository_config(&config, _repo);
+
+ /* Ensure the "core.filemode" config value has been reset */
+ cl_git_pass(git_config_get_bool(&current_value, config, "core.filemode"));
+ cl_assert_equal_i(expected, current_value);
+
+ git_config_free(config);
+}
+
+void test_repo_init__sets_logAllRefUpdates_according_to_type_of_repository(void)
+{
+ assert_config_entry_on_init_bytype("core.logallrefupdates", GIT_ENOTFOUND, true);
+ git_repository_free(_repo);
+ assert_config_entry_on_init_bytype("core.logallrefupdates", true, false);
+}
+
+void test_repo_init__extended_0(void)
+{
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+
+ /* without MKDIR this should fail */
+ cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts));
+
+ /* make the directory first, then it should succeed */
+ cl_git_pass(git_futils_mkdir("extended", NULL, 0775, 0));
+ cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts));
+
+ cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/"));
+ cl_assert(!git__suffixcmp(git_repository_path(_repo), "/extended/.git/"));
+ cl_assert(!git_repository_is_bare(_repo));
+ cl_assert(git_repository_is_empty(_repo));
+
+ cleanup_repository("extended");
+}
+
+void test_repo_init__extended_1(void)
+{
+ git_reference *ref;
+ git_remote *remote;
+ struct stat st;
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+
+ opts.flags = GIT_REPOSITORY_INIT_MKPATH |
+ GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
+ opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
+ opts.workdir_path = "../c_wd";
+ opts.description = "Awesomest test repository evah";
+ opts.initial_head = "development";
+ opts.origin_url = "https://github.com/libgit2/libgit2.git";
+
+ cl_git_pass(git_repository_init_ext(&_repo, "root/b/c.git", &opts));
+
+ cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/c_wd/"));
+ cl_assert(!git__suffixcmp(git_repository_path(_repo), "/c.git/"));
+ cl_assert(git_path_isfile("root/b/c_wd/.git"));
+ cl_assert(!git_repository_is_bare(_repo));
+ /* repo will not be counted as empty because we set head to "development" */
+ cl_assert(!git_repository_is_empty(_repo));
+
+ cl_git_pass(git_path_lstat(git_repository_path(_repo), &st));
+ cl_assert(S_ISDIR(st.st_mode));
+ cl_assert((S_ISGID & st.st_mode) == S_ISGID);
+
+ cl_git_pass(git_reference_lookup(&ref, _repo, "HEAD"));
+ cl_assert(git_reference_type(ref) == GIT_REF_SYMBOLIC);
+ cl_assert_equal_s("refs/heads/development", git_reference_symbolic_target(ref));
+ git_reference_free(ref);
+
+ cl_git_pass(git_remote_load(&remote, _repo, "origin"));
+ cl_assert_equal_s("origin", git_remote_name(remote));
+ cl_assert_equal_s(opts.origin_url, git_remote_url(remote));
+ git_remote_free(remote);
+
+ git_repository_free(_repo);
+ cl_fixture_cleanup("root");
+}
+
+static void assert_hooks_match(
+ const char *template_dir,
+ const char *repo_dir,
+ const char *hook_path,
+ bool core_filemode)
+{
+ git_buf expected = GIT_BUF_INIT;
+ git_buf actual = GIT_BUF_INIT;
+ struct stat expected_st, st;
+
+ cl_git_pass(git_buf_joinpath(&expected, template_dir, hook_path));
+ cl_git_pass(git_path_lstat(expected.ptr, &expected_st));
+
+ cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
+ cl_git_pass(git_path_lstat(actual.ptr, &st));
+
+ cl_assert(expected_st.st_size == st.st_size);
+
+ if (!core_filemode) {
+ expected_st.st_mode = expected_st.st_mode & ~0111;
+ st.st_mode = st.st_mode & ~0111;
+ }
+
+ cl_assert_equal_i((int)expected_st.st_mode, (int)st.st_mode);
+
+ git_buf_free(&expected);
+ git_buf_free(&actual);
+}
+
+static void assert_mode_seems_okay(
+ const char *base, const char *path,
+ git_filemode_t expect_mode, bool expect_setgid, bool core_filemode)
+{
+ git_buf full = GIT_BUF_INIT;
+ struct stat st;
+
+ cl_git_pass(git_buf_joinpath(&full, base, path));
+ cl_git_pass(git_path_lstat(full.ptr, &st));
+ git_buf_free(&full);
+
+ if (!core_filemode) {
+ expect_mode = expect_mode & ~0111;
+ st.st_mode = st.st_mode & ~0111;
+ expect_setgid = false;
+ }
+
+ if (S_ISGID != 0) {
+ if (expect_setgid)
+ cl_assert((st.st_mode & S_ISGID) != 0);
+ else
+ cl_assert((st.st_mode & S_ISGID) == 0);
+ }
+
+ if ((expect_mode & 0111) != 0)
+ cl_assert((st.st_mode & 0111) != 0);
+ else
+ cl_assert((st.st_mode & 0111) == 0);
+
+ cl_assert((expect_mode & 0170000) == (st.st_mode & 0170000));
+}
+
+void test_repo_init__extended_with_template(void)
+{
+ git_buf expected = GIT_BUF_INIT;
+ git_buf actual = GIT_BUF_INIT;
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+
+ cl_set_cleanup(&cleanup_repository, "templated.git");
+
+ opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
+ GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
+ opts.template_path = cl_fixture("template");
+
+ cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts));
+
+ cl_assert(git_repository_is_bare(_repo));
+
+ cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/"));
+
+ cl_git_pass(git_futils_readbuffer(
+ &expected, cl_fixture("template/description")));
+ cl_git_pass(git_futils_readbuffer(
+ &actual, "templated.git/description"));
+
+ cl_assert_equal_s(expected.ptr, actual.ptr);
+
+ git_buf_free(&expected);
+ git_buf_free(&actual);
+
+ assert_hooks_match(
+ cl_fixture("template"), git_repository_path(_repo),
+ "hooks/update.sample", true);
+
+ assert_hooks_match(
+ cl_fixture("template"), git_repository_path(_repo),
+ "hooks/link.sample", true);
+}
+
+void test_repo_init__extended_with_template_and_shared_mode(void)
+{
+ git_buf expected = GIT_BUF_INIT;
+ git_buf actual = GIT_BUF_INIT;
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+ git_config *config;
+ int filemode = true;
+ const char *repo_path = NULL;
+
+ cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl");
+
+ opts.flags = GIT_REPOSITORY_INIT_MKPATH |
+ GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
+ opts.template_path = cl_fixture("template");
+ opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
+
+ cl_git_pass(git_repository_init_ext(&_repo, "init_shared_from_tpl", &opts));
+
+ cl_assert(!git_repository_is_bare(_repo));
+ cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/"));
+
+ cl_git_pass(git_repository_config(&config, _repo));
+ cl_git_pass(git_config_get_bool(&filemode, config, "core.filemode"));
+ git_config_free(config);
+
+ cl_git_pass(git_futils_readbuffer(
+ &expected, cl_fixture("template/description")));
+ cl_git_pass(git_futils_readbuffer(
+ &actual, "init_shared_from_tpl/.git/description"));
+
+ cl_assert_equal_s(expected.ptr, actual.ptr);
+
+ git_buf_free(&expected);
+ git_buf_free(&actual);
+
+ repo_path = git_repository_path(_repo);
+ assert_mode_seems_okay(repo_path, "hooks",
+ GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode);
+ assert_mode_seems_okay(repo_path, "info",
+ GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode);
+ assert_mode_seems_okay(repo_path, "description",
+ GIT_FILEMODE_BLOB, false, filemode);
+
+ /* for a non-symlinked hook, it should have shared permissions now */
+ assert_hooks_match(
+ cl_fixture("template"), git_repository_path(_repo),
+ "hooks/update.sample", filemode);
+
+ /* for a symlinked hook, the permissions still should match the
+ * source link, not the GIT_REPOSITORY_INIT_SHARED_GROUP value
+ */
+ assert_hooks_match(
+ cl_fixture("template"), git_repository_path(_repo),
+ "hooks/link.sample", filemode);
+}
+
+void test_repo_init__can_reinit_an_initialized_repository(void)
+{
+ git_repository *reinit;
+
+ cl_set_cleanup(&cleanup_repository, "extended");
+
+ cl_git_pass(git_futils_mkdir("extended", NULL, 0775, 0));
+ cl_git_pass(git_repository_init(&_repo, "extended", false));
+
+ cl_git_pass(git_repository_init(&reinit, "extended", false));
+
+ cl_assert_equal_s(git_repository_path(_repo), git_repository_path(reinit));
+
+ git_repository_free(reinit);
+}
diff --git a/tests-clar/repo/iterator.c b/tests-clar/repo/iterator.c
new file mode 100644
index 000000000..00c46d6b1
--- /dev/null
+++ b/tests-clar/repo/iterator.c
@@ -0,0 +1,810 @@
+#include "clar_libgit2.h"
+#include "iterator.h"
+#include "repository.h"
+#include "fileops.h"
+#include <stdarg.h>
+
+static git_repository *g_repo;
+
+void test_repo_iterator__initialize(void)
+{
+}
+
+void test_repo_iterator__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}
+
+static void expect_iterator_items(
+ git_iterator *i,
+ int expected_flat,
+ const char **expected_flat_paths,
+ int expected_total,
+ const char **expected_total_paths)
+{
+ const git_index_entry *entry;
+ int count, error;
+ int no_trees = !(git_iterator_flags(i) & GIT_ITERATOR_INCLUDE_TREES);
+ bool v = false;
+
+ if (expected_flat < 0) { v = true; expected_flat = -expected_flat; }
+ if (expected_total < 0) { v = true; expected_total = -expected_total; }
+
+ count = 0;
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ if (v) fprintf(stderr, "== %s ==\n", no_trees ? "notrees" : "trees");
+
+ while (entry != NULL) {
+ if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
+
+ if (no_trees)
+ cl_assert(entry->mode != GIT_FILEMODE_TREE);
+
+ if (expected_flat_paths) {
+ const char *expect_path = expected_flat_paths[count];
+ size_t expect_len = strlen(expect_path);
+
+ cl_assert_equal_s(expect_path, entry->path);
+
+ if (expect_path[expect_len - 1] == '/')
+ cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
+ else
+ cl_assert(entry->mode != GIT_FILEMODE_TREE);
+ }
+
+ cl_git_pass(git_iterator_advance(&entry, i));
+
+ if (++count > expected_flat)
+ break;
+ }
+
+ cl_assert_equal_i(expected_flat, count);
+
+ cl_git_pass(git_iterator_reset(i, NULL, NULL));
+
+ count = 0;
+ cl_git_pass(git_iterator_current(&entry, i));
+
+ if (v) fprintf(stderr, "-- %s --\n", no_trees ? "notrees" : "trees");
+
+ while (entry != NULL) {
+ if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
+
+ if (no_trees)
+ cl_assert(entry->mode != GIT_FILEMODE_TREE);
+
+ if (expected_total_paths) {
+ const char *expect_path = expected_total_paths[count];
+ size_t expect_len = strlen(expect_path);
+
+ cl_assert_equal_s(expect_path, entry->path);
+
+ if (expect_path[expect_len - 1] == '/')
+ cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
+ else
+ cl_assert(entry->mode != GIT_FILEMODE_TREE);
+ }
+
+ if (entry->mode == GIT_FILEMODE_TREE) {
+ error = git_iterator_advance_into(&entry, i);
+
+ /* could return NOTFOUND if directory is empty */
+ cl_assert(!error || error == GIT_ENOTFOUND);
+
+ if (error == GIT_ENOTFOUND)
+ cl_git_pass(git_iterator_advance(&entry, i));
+ } else
+ cl_git_pass(git_iterator_advance(&entry, i));
+
+ if (++count > expected_total)
+ break;
+ }
+
+ cl_assert_equal_i(expected_total, count);
+}
+
+/* Index contents (including pseudotrees):
+ *
+ * 0: a 5: F 10: k/ 16: L/
+ * 1: B 6: g 11: k/1 17: L/1
+ * 2: c 7: H 12: k/a 18: L/a
+ * 3: D 8: i 13: k/B 19: L/B
+ * 4: e 9: J 14: k/c 20: L/c
+ * 15: k/D 21: L/D
+ *
+ * 0: B 5: L/ 11: a 16: k/
+ * 1: D 6: L/1 12: c 17: k/1
+ * 2: F 7: L/B 13: e 18: k/B
+ * 3: H 8: L/D 14: g 19: k/D
+ * 4: J 9: L/a 15: i 20: k/a
+ * 10: L/c 21: k/c
+ */
+
+void test_repo_iterator__index(void)
+{
+ git_iterator *i;
+ git_index *index;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ /* autoexpand with no tree entries for index */
+ cl_git_pass(git_iterator_for_index(&i, index, 0, NULL, NULL));
+ expect_iterator_items(i, 20, NULL, 20, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 22, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 12, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ git_index_free(index);
+}
+
+void test_repo_iterator__index_icase(void)
+{
+ git_iterator *i;
+ git_index *index;
+ unsigned int caps;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ caps = git_index_caps(index);
+
+ /* force case sensitivity */
+ cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
+
+ /* autoexpand with no tree entries over range */
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "c", "k/D"));
+ expect_iterator_items(i, 7, NULL, 7, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "k", "k/Z"));
+ expect_iterator_items(i, 3, NULL, 3, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 8, NULL, 8, NULL);
+ git_iterator_free(i);
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 5, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* force case insensitivity */
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
+
+ /* autoexpand with no tree entries over range */
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "c", "k/D"));
+ expect_iterator_items(i, 13, NULL, 13, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "k", "k/Z"));
+ expect_iterator_items(i, 5, NULL, 5, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 14, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 9, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_index_set_caps(index, caps));
+ git_index_free(index);
+}
+
+void test_repo_iterator__tree(void)
+{
+ git_iterator *i;
+ git_tree *head;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_repository_head_tree(&head, g_repo));
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_tree(&i, head, 0, NULL, NULL));
+ expect_iterator_items(i, 20, NULL, 20, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 22, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 12, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ git_tree_free(head);
+}
+
+void test_repo_iterator__tree_icase(void)
+{
+ git_iterator *i;
+ git_tree *head;
+ git_iterator_flag_t flag;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_repository_head_tree(&head, g_repo));
+
+ flag = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "c", "k/D"));
+ expect_iterator_items(i, 7, NULL, 7, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "k", "k/Z"));
+ expect_iterator_items(i, 3, NULL, 3, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 8, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 5, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ flag = GIT_ITERATOR_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "c", "k/D"));
+ expect_iterator_items(i, 13, NULL, 13, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "k", "k/Z"));
+ expect_iterator_items(i, 5, NULL, 5, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 14, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 9, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ git_tree_free(head);
+}
+
+void test_repo_iterator__tree_more(void)
+{
+ git_iterator *i;
+ git_tree *head;
+ static const char *expect_basic[] = {
+ "current_file",
+ "file_deleted",
+ "modified_file",
+ "staged_changes",
+ "staged_changes_file_deleted",
+ "staged_changes_modified_file",
+ "staged_delete_file_deleted",
+ "staged_delete_modified_file",
+ "subdir.txt",
+ "subdir/current_file",
+ "subdir/deleted_file",
+ "subdir/modified_file",
+ NULL,
+ };
+ static const char *expect_trees[] = {
+ "current_file",
+ "file_deleted",
+ "modified_file",
+ "staged_changes",
+ "staged_changes_file_deleted",
+ "staged_changes_modified_file",
+ "staged_delete_file_deleted",
+ "staged_delete_modified_file",
+ "subdir.txt",
+ "subdir/",
+ "subdir/current_file",
+ "subdir/deleted_file",
+ "subdir/modified_file",
+ NULL,
+ };
+ static const char *expect_noauto[] = {
+ "current_file",
+ "file_deleted",
+ "modified_file",
+ "staged_changes",
+ "staged_changes_file_deleted",
+ "staged_changes_modified_file",
+ "staged_delete_file_deleted",
+ "staged_delete_modified_file",
+ "subdir.txt",
+ "subdir/",
+ NULL
+ };
+
+ g_repo = cl_git_sandbox_init("status");
+
+ cl_git_pass(git_repository_head_tree(&head, g_repo));
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_tree(&i, head, 0, NULL, NULL));
+ expect_iterator_items(i, 12, expect_basic, 12, expect_basic);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 13, expect_trees, 13, expect_trees);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 10, expect_noauto, 13, expect_trees);
+ git_iterator_free(i);
+
+ git_tree_free(head);
+}
+
+/* "b=name,t=name", blob_id, tree_id */
+static void build_test_tree(
+ git_oid *out, git_repository *repo, const char *fmt, ...)
+{
+ git_oid *id;
+ git_treebuilder *builder;
+ const char *scan = fmt, *next;
+ char type, delimiter;
+ git_filemode_t mode;
+ git_buf name = GIT_BUF_INIT;
+ va_list arglist;
+
+ cl_git_pass(git_treebuilder_create(&builder, NULL)); /* start builder */
+
+ va_start(arglist, fmt);
+ while (*scan) {
+ switch (type = *scan++) {
+ case 't': case 'T': mode = GIT_FILEMODE_TREE; break;
+ case 'b': case 'B': mode = GIT_FILEMODE_BLOB; break;
+ default:
+ cl_assert(type == 't' || type == 'T' || type == 'b' || type == 'B');
+ }
+
+ delimiter = *scan++; /* read and skip delimiter */
+ for (next = scan; *next && *next != delimiter; ++next)
+ /* seek end */;
+ cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
+ for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
+ /* skip delimiter and optional comma */;
+
+ id = va_arg(arglist, git_oid *);
+
+ cl_git_pass(git_treebuilder_insert(NULL, builder, name.ptr, id, mode));
+ }
+ va_end(arglist);
+
+ cl_git_pass(git_treebuilder_write(out, repo, builder));
+
+ git_treebuilder_free(builder);
+ git_buf_free(&name);
+}
+
+void test_repo_iterator__tree_case_conflicts_0(void)
+{
+ const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
+ git_tree *tree;
+ git_oid blob_id, biga_id, littlea_id, tree_id;
+ git_iterator *i;
+ const char *expect_cs[] = {
+ "A/1.file", "A/3.file", "a/2.file", "a/4.file" };
+ const char *expect_ci[] = {
+ "A/1.file", "a/2.file", "A/3.file", "a/4.file" };
+ const char *expect_cs_trees[] = {
+ "A/", "A/1.file", "A/3.file", "a/", "a/2.file", "a/4.file" };
+ const char *expect_ci_trees[] = {
+ "A/", "A/1.file", "a/2.file", "A/3.file", "a/4.file" };
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
+
+ /* create tree with: A/1.file, A/3.file, a/2.file, a/4.file */
+ build_test_tree(
+ &biga_id, g_repo, "b|1.file|,b|3.file|", &blob_id, &blob_id);
+ build_test_tree(
+ &littlea_id, g_repo, "b|2.file|,b|4.file|", &blob_id, &blob_id);
+ build_test_tree(
+ &tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 4, expect_cs, 4, expect_cs);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 6, expect_cs_trees, 6, expect_cs_trees);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 5, expect_ci_trees, 5, expect_ci_trees);
+ git_iterator_free(i);
+
+ git_tree_free(tree);
+}
+
+void test_repo_iterator__tree_case_conflicts_1(void)
+{
+ const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
+ git_tree *tree;
+ git_oid blob_id, Ab_id, biga_id, littlea_id, tree_id;
+ git_iterator *i;
+ const char *expect_cs[] = {
+ "A/a", "A/b/1", "A/c", "a/C", "a/a", "a/b" };
+ const char *expect_ci[] = {
+ "A/a", "a/b", "A/b/1", "A/c" };
+ const char *expect_cs_trees[] = {
+ "A/", "A/a", "A/b/", "A/b/1", "A/c", "a/", "a/C", "a/a", "a/b" };
+ const char *expect_ci_trees[] = {
+ "A/", "A/a", "a/b", "A/b/", "A/b/1", "A/c" };
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
+
+ /* create: A/a A/b/1 A/c a/a a/b a/C */
+ build_test_tree(&Ab_id, g_repo, "b|1|", &blob_id);
+ build_test_tree(
+ &biga_id, g_repo, "b|a|,t|b|,b|c|", &blob_id, &Ab_id, &blob_id);
+ build_test_tree(
+ &littlea_id, g_repo, "b|a|,b|b|,b|C|", &blob_id, &blob_id, &blob_id);
+ build_test_tree(
+ &tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 6, expect_cs, 6, expect_cs);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 9, expect_cs_trees, 9, expect_cs_trees);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 6, expect_ci_trees, 6, expect_ci_trees);
+ git_iterator_free(i);
+
+ git_tree_free(tree);
+}
+
+void test_repo_iterator__tree_case_conflicts_2(void)
+{
+ const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
+ git_tree *tree;
+ git_oid blob_id, d1, d2, c1, c2, b1, b2, a1, a2, tree_id;
+ git_iterator *i;
+ const char *expect_cs[] = {
+ "A/B/C/D/16", "A/B/C/D/foo", "A/B/C/d/15", "A/B/C/d/FOO",
+ "A/B/c/D/14", "A/B/c/D/foo", "A/B/c/d/13", "A/B/c/d/FOO",
+ "A/b/C/D/12", "A/b/C/D/foo", "A/b/C/d/11", "A/b/C/d/FOO",
+ "A/b/c/D/10", "A/b/c/D/foo", "A/b/c/d/09", "A/b/c/d/FOO",
+ "a/B/C/D/08", "a/B/C/D/foo", "a/B/C/d/07", "a/B/C/d/FOO",
+ "a/B/c/D/06", "a/B/c/D/foo", "a/B/c/d/05", "a/B/c/d/FOO",
+ "a/b/C/D/04", "a/b/C/D/foo", "a/b/C/d/03", "a/b/C/d/FOO",
+ "a/b/c/D/02", "a/b/c/D/foo", "a/b/c/d/01", "a/b/c/d/FOO", };
+ const char *expect_ci[] = {
+ "a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
+ "a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
+ "A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
+ "A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
+ "A/B/C/D/foo", };
+ const char *expect_ci_trees[] = {
+ "A/", "A/B/", "A/B/C/", "A/B/C/D/",
+ "a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
+ "a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
+ "A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
+ "A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
+ "A/B/C/D/foo", };
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
+
+ build_test_tree(&d1, g_repo, "b|16|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|15|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&d1, g_repo, "b|14|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|13|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
+
+ build_test_tree(&d1, g_repo, "b|12|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|11|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&d1, g_repo, "b|10|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|09|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
+
+ build_test_tree(&a1, g_repo, "t|B|,t|b|", &b1, &b2);
+
+ build_test_tree(&d1, g_repo, "b|08|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|07|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&d1, g_repo, "b|06|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|05|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
+
+ build_test_tree(&d1, g_repo, "b|04|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|03|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&d1, g_repo, "b|02|,b|foo|", &blob_id, &blob_id);
+ build_test_tree(&d2, g_repo, "b|01|,b|FOO|", &blob_id, &blob_id);
+ build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
+ build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
+
+ build_test_tree(&a2, g_repo, "t|B|,t|b|", &b1, &b2);
+
+ build_test_tree(&tree_id, g_repo, "t/A/,t/a/", &a1, &a2);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 32, expect_cs, 32, expect_cs);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 17, expect_ci, 17, expect_ci);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 21, expect_ci_trees, 21, expect_ci_trees);
+ git_iterator_free(i);
+
+ git_tree_free(tree);
+}
+
+void test_repo_iterator__workdir(void)
+{
+ git_iterator *i;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, 0, NULL, NULL));
+ expect_iterator_items(i, 20, NULL, 20, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 22, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 12, NULL, 22, NULL);
+ git_iterator_free(i);
+}
+
+void test_repo_iterator__workdir_icase(void)
+{
+ git_iterator *i;
+ git_iterator_flag_t flag;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ flag = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "c", "k/D"));
+ expect_iterator_items(i, 7, NULL, 7, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "k", "k/Z"));
+ expect_iterator_items(i, 3, NULL, 3, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 8, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 5, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ flag = GIT_ITERATOR_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "c", "k/D"));
+ expect_iterator_items(i, 13, NULL, 13, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "k", "k/Z"));
+ expect_iterator_items(i, 5, NULL, 5, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 14, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 9, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 6, NULL);
+ git_iterator_free(i);
+}
+
+void test_repo_iterator__workdir_depth(void)
+{
+ int i, j;
+ git_iterator *iter;
+ char buf[64];
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ for (i = 0; i < 10; ++i) {
+ p_snprintf(buf, sizeof(buf), "icase/dir%02d", i);
+ cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+
+ if (i % 2 == 0) {
+ p_snprintf(buf, sizeof(buf), "icase/dir%02d/file", i);
+ cl_git_mkfile(buf, buf);
+ }
+
+ for (j = 0; j < 10; ++j) {
+ p_snprintf(buf, sizeof(buf), "icase/dir%02d/sub%02d", i, j);
+ cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+
+ if (j % 2 == 0) {
+ p_snprintf(
+ buf, sizeof(buf), "icase/dir%02d/sub%02d/file", i, j);
+ cl_git_mkfile(buf, buf);
+ }
+ }
+ }
+
+ for (i = 1; i < 3; ++i) {
+ for (j = 0; j < 50; ++j) {
+ p_snprintf(buf, sizeof(buf), "icase/dir%02d/sub01/moar%02d", i, j);
+ cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+
+ if (j % 2 == 0) {
+ p_snprintf(buf, sizeof(buf),
+ "icase/dir%02d/sub01/moar%02d/file", i, j);
+ cl_git_mkfile(buf, buf);
+ }
+ }
+ }
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&iter, g_repo, 0, NULL, NULL));
+ expect_iterator_items(iter, 125, NULL, 125, NULL);
+ git_iterator_free(iter);
+
+ /* auto expand with tree entries (empty dirs silently skipped) */
+ cl_git_pass(git_iterator_for_workdir(
+ &iter, g_repo, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(iter, 337, NULL, 337, NULL);
+ git_iterator_free(iter);
+}
diff --git a/tests-clar/repo/message.c b/tests-clar/repo/message.c
new file mode 100644
index 000000000..59487d51b
--- /dev/null
+++ b/tests-clar/repo/message.c
@@ -0,0 +1,47 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "refs.h"
+#include "posix.h"
+
+static git_repository *_repo;
+static git_buf _path;
+static char *_actual;
+
+void test_repo_message__initialize(void)
+{
+ _repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_repo_message__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ git_buf_free(&_path);
+ git__free(_actual);
+ _actual = NULL;
+}
+
+void test_repo_message__none(void)
+{
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo));
+}
+
+void test_repo_message__message(void)
+{
+ const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
+ ssize_t len;
+
+ cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG"));
+ cl_git_mkfile(git_buf_cstr(&_path), expected);
+
+ len = git_repository_message(NULL, 0, _repo);
+ cl_assert(len > 0);
+ _actual = git__malloc(len + 1);
+ cl_assert(_actual != NULL);
+
+ cl_assert(git_repository_message(_actual, len, _repo) > 0);
+ _actual[len] = '\0';
+ cl_assert_equal_s(expected, _actual);
+
+ cl_git_pass(p_unlink(git_buf_cstr(&_path)));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo));
+}
diff --git a/tests-clar/repo/open.c b/tests-clar/repo/open.c
index c70ec83a9..7f93ae91a 100644
--- a/tests-clar/repo/open.c
+++ b/tests-clar/repo/open.c
@@ -7,7 +7,7 @@ void test_repo_open__cleanup(void)
cl_git_sandbox_cleanup();
if (git_path_isdir("alternate"))
- git_futils_rmdir_r("alternate", GIT_DIRREMOVAL_FILES_AND_DIRS);
+ git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES);
}
void test_repo_open__bare_empty_repo(void)
@@ -202,8 +202,8 @@ void test_repo_open__bad_gitlinks(void)
cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
}
- git_futils_rmdir_r("invalid", GIT_DIRREMOVAL_FILES_AND_DIRS);
- git_futils_rmdir_r("invalid2", GIT_DIRREMOVAL_FILES_AND_DIRS);
+ git_futils_rmdir_r("invalid", NULL, GIT_RMDIR_REMOVE_FILES);
+ git_futils_rmdir_r("invalid2", NULL, GIT_RMDIR_REMOVE_FILES);
}
#ifdef GIT_WIN32
diff --git a/tests-clar/repo/repo_helpers.c b/tests-clar/repo/repo_helpers.c
new file mode 100644
index 000000000..74902e439
--- /dev/null
+++ b/tests-clar/repo/repo_helpers.c
@@ -0,0 +1,22 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "repo_helpers.h"
+#include "posix.h"
+
+void make_head_orphaned(git_repository* repo, const char *target)
+{
+ git_reference *head;
+
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1));
+ git_reference_free(head);
+}
+
+void delete_head(git_repository* repo)
+{
+ git_buf head_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
+ cl_git_pass(p_unlink(git_buf_cstr(&head_path)));
+
+ git_buf_free(&head_path);
+}
diff --git a/tests-clar/repo/repo_helpers.h b/tests-clar/repo/repo_helpers.h
new file mode 100644
index 000000000..09b5cac84
--- /dev/null
+++ b/tests-clar/repo/repo_helpers.h
@@ -0,0 +1,6 @@
+#include "common.h"
+
+#define NON_EXISTING_HEAD "refs/heads/hide/and/seek"
+
+extern void make_head_orphaned(git_repository* repo, const char *target);
+extern void delete_head(git_repository* repo);
diff --git a/tests-clar/repo/setters.c b/tests-clar/repo/setters.c
index 6242d8541..7e482dee1 100644
--- a/tests-clar/repo/setters.c
+++ b/tests-clar/repo/setters.c
@@ -2,6 +2,8 @@
#include "buffer.h"
#include "posix.h"
#include "util.h"
+#include "path.h"
+#include "fileops.h"
static git_repository *repo;
@@ -15,8 +17,10 @@ void test_repo_setters__initialize(void)
void test_repo_setters__cleanup(void)
{
git_repository_free(repo);
+ repo = NULL;
+
cl_fixture_cleanup("testrepo.git");
- cl_must_pass(p_rmdir("new_workdir"));
+ cl_fixture_cleanup("new_workdir");
}
void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
@@ -24,7 +28,7 @@ void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standar
cl_assert(git_repository_is_bare(repo) == 1);
cl_assert(git_repository_workdir(repo) == NULL);
- cl_git_pass(git_repository_set_workdir(repo, "./new_workdir"));
+ cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
cl_assert(git_repository_workdir(repo) != NULL);
cl_assert(git_repository_is_bare(repo) == 0);
@@ -32,9 +36,30 @@ void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standar
void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
{
- cl_git_pass(git_repository_set_workdir(repo, "./new_workdir"));
+ cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
+
+ cl_assert(git__suffixcmp(git_repository_workdir(repo), "new_workdir/") == 0);
+}
+
+void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
+{
+ git_config *cfg;
+ const char *val;
+ git_buf content = GIT_BUF_INIT;
+
+ cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
+
+ cl_assert(git_path_isfile("./new_workdir/.git"));
+
+ cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
+ cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
+ cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
+ git_buf_free(&content);
- cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
+ cl_git_pass(git_repository_config(&cfg, repo));
+ cl_git_pass(git_config_get_string(&val, cfg, "core.worktree"));
+ cl_assert(git__suffixcmp(val, "new_workdir/") == 0);
+ git_config_free(cfg);
}
void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_one_properly_honors_the_refcount(void)
diff --git a/tests-clar/repo/state.c b/tests-clar/repo/state.c
new file mode 100644
index 000000000..5a0a5f360
--- /dev/null
+++ b/tests-clar/repo/state.c
@@ -0,0 +1,96 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "refs.h"
+#include "posix.h"
+#include "fileops.h"
+
+static git_repository *_repo;
+static git_buf _path;
+
+void test_repo_state__initialize(void)
+{
+ _repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_repo_state__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ git_buf_free(&_path);
+}
+
+static void setup_simple_state(const char *filename)
+{
+ cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
+ git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
+ cl_git_mkfile(git_buf_cstr(&_path), "dummy");
+}
+
+static void assert_repo_state(git_repository_state_t state)
+{
+ cl_assert_equal_i(state, git_repository_state(_repo));
+}
+
+void test_repo_state__none_with_HEAD_attached(void)
+{
+ assert_repo_state(GIT_REPOSITORY_STATE_NONE);
+}
+
+void test_repo_state__none_with_HEAD_detached(void)
+{
+ cl_git_pass(git_repository_detach_head(_repo));
+ assert_repo_state(GIT_REPOSITORY_STATE_NONE);
+}
+
+void test_repo_state__merge(void)
+{
+ setup_simple_state(GIT_MERGE_HEAD_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_MERGE);
+}
+
+void test_repo_state__revert(void)
+{
+ setup_simple_state(GIT_REVERT_HEAD_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_REVERT);
+}
+
+void test_repo_state__cherry_pick(void)
+{
+ setup_simple_state(GIT_CHERRY_PICK_HEAD_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_CHERRY_PICK);
+}
+
+void test_repo_state__bisect(void)
+{
+ setup_simple_state(GIT_BISECT_LOG_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_BISECT);
+}
+
+void test_repo_state__rebase_interactive(void)
+{
+ setup_simple_state(GIT_REBASE_MERGE_INTERACTIVE_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_REBASE_INTERACTIVE);
+}
+
+void test_repo_state__rebase_merge(void)
+{
+ setup_simple_state(GIT_REBASE_MERGE_DIR "whatever");
+ assert_repo_state(GIT_REPOSITORY_STATE_REBASE_MERGE);
+}
+
+void test_repo_state__rebase(void)
+{
+ setup_simple_state(GIT_REBASE_APPLY_REBASING_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_REBASE);
+}
+
+void test_repo_state__apply_mailbox(void)
+{
+ setup_simple_state(GIT_REBASE_APPLY_APPLYING_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX);
+}
+
+void test_repo_state__apply_mailbox_or_rebase(void)
+{
+ setup_simple_state(GIT_REBASE_APPLY_DIR "whatever");
+ assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE);
+}
diff --git a/tests-clar/reset/default.c b/tests-clar/reset/default.c
new file mode 100644
index 000000000..506d971ff
--- /dev/null
+++ b/tests-clar/reset/default.c
@@ -0,0 +1,180 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "reset_helpers.h"
+#include "path.h"
+
+static git_repository *_repo;
+static git_object *_target;
+static git_strarray _pathspecs;
+static git_index *_index;
+
+static void initialize(const char *repo_name)
+{
+ _repo = cl_git_sandbox_init(repo_name);
+ cl_git_pass(git_repository_index(&_index, _repo));
+
+ _target = NULL;
+
+ _pathspecs.strings = NULL;
+ _pathspecs.count = 0;
+}
+
+void test_reset_default__initialize(void)
+{
+ initialize("status");
+}
+
+void test_reset_default__cleanup(void)
+{
+ git_object_free(_target);
+ _target = NULL;
+
+ git_index_free(_index);
+ _index = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+static void assert_content_in_index(
+ git_strarray *pathspecs,
+ bool should_exist,
+ git_strarray *expected_shas)
+{
+ size_t i, pos;
+ int error;
+
+ for (i = 0; i < pathspecs->count; i++) {
+ error = git_index_find(&pos, _index, pathspecs->strings[i]);
+
+ if (should_exist) {
+ const git_index_entry *entry;
+
+ cl_assert(error != GIT_ENOTFOUND);
+
+ entry = git_index_get_byindex(_index, pos);
+ cl_assert(entry != NULL);
+
+ if (!expected_shas)
+ continue;
+
+ cl_git_pass(git_oid_streq(&entry->oid, expected_shas->strings[i]));
+ } else
+ cl_assert_equal_i(should_exist, error != GIT_ENOTFOUND);
+ }
+}
+
+void test_reset_default__resetting_filepaths_against_a_null_target_removes_them_from_the_index(void)
+{
+ char *paths[] = { "staged_changes", "staged_new_file" };
+
+ _pathspecs.strings = paths;
+ _pathspecs.count = 2;
+
+ assert_content_in_index(&_pathspecs, true, NULL);
+
+ cl_git_pass(git_reset_default(_repo, NULL, &_pathspecs));
+
+ assert_content_in_index(&_pathspecs, false, NULL);
+}
+
+/*
+ * $ git ls-files --cached -s --abbrev=7 -- "staged*"
+ * 100644 55d316c 0 staged_changes
+ * 100644 a6be623 0 staged_changes_file_deleted
+ * ...
+ *
+ * $ git reset 0017bd4 -- staged_changes staged_changes_file_deleted
+ * Unstaged changes after reset:
+ * ...
+ *
+ * $ git ls-files --cached -s --abbrev=7 -- "staged*"
+ * 100644 32504b7 0 staged_changes
+ * 100644 061d42a 0 staged_changes_file_deleted
+ * ...
+ */
+void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_entries(void)
+{
+ git_strarray before, after;
+
+ char *paths[] = { "staged_changes", "staged_changes_file_deleted" };
+ char *before_shas[] = { "55d316c9ba708999f1918e9677d01dfcae69c6b9",
+ "a6be623522ce87a1d862128ac42672604f7b468b" };
+ char *after_shas[] = { "32504b727382542f9f089e24fddac5e78533e96c",
+ "061d42a44cacde5726057b67558821d95db96f19" };
+
+ _pathspecs.strings = paths;
+ _pathspecs.count = 2;
+ before.strings = before_shas;
+ before.count = 2;
+ after.strings = after_shas;
+ after.count = 2;
+
+ cl_git_pass(git_revparse_single(&_target, _repo, "0017bd4"));
+ assert_content_in_index(&_pathspecs, true, &before);
+
+ cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
+
+ assert_content_in_index(&_pathspecs, true, &after);
+}
+
+/*
+ * $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt
+ * 100644 1f85ca5 1 conflicts-one.txt
+ * 100644 6aea5f2 2 conflicts-one.txt
+ * 100644 516bd85 3 conflicts-one.txt
+ *
+ * $ git reset 9a05ccb -- conflicts-one.txt
+ * Unstaged changes after reset:
+ * ...
+ *
+ * $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt
+ * 100644 1f85ca5 0 conflicts-one.txt
+ *
+ */
+void test_reset_default__resetting_filepaths_clears_previous_conflicts(void)
+{
+ git_index_entry *conflict_entry[3];
+ git_strarray after;
+
+ char *paths[] = { "conflicts-one.txt" };
+ char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" };
+
+ test_reset_default__cleanup();
+ initialize("mergedrepo");
+
+ _pathspecs.strings = paths;
+ _pathspecs.count = 1;
+ after.strings = after_shas;
+ after.count = 1;
+
+ cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+ &conflict_entry[2], _index, "conflicts-one.txt"));
+
+ cl_git_pass(git_revparse_single(&_target, _repo, "9a05ccb"));
+ cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
+
+ assert_content_in_index(&_pathspecs, true, &after);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_index_conflict_get(&conflict_entry[0],
+ &conflict_entry[1], &conflict_entry[2], _index, "conflicts-one.txt"));
+}
+
+/*
+$ git reset HEAD -- "I_am_not_there.txt" "me_neither.txt"
+Unstaged changes after reset:
+...
+*/
+void test_reset_default__resetting_unknown_filepaths_does_not_fail(void)
+{
+ char *paths[] = { "I_am_not_there.txt", "me_neither.txt" };
+
+ _pathspecs.strings = paths;
+ _pathspecs.count = 2;
+
+ assert_content_in_index(&_pathspecs, false, NULL);
+
+ cl_git_pass(git_revparse_single(&_target, _repo, "HEAD"));
+ cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
+
+ assert_content_in_index(&_pathspecs, false, NULL);
+}
diff --git a/tests-clar/reset/hard.c b/tests-clar/reset/hard.c
new file mode 100644
index 000000000..62371f83f
--- /dev/null
+++ b/tests-clar/reset/hard.c
@@ -0,0 +1,200 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "reset_helpers.h"
+#include "path.h"
+#include "fileops.h"
+
+static git_repository *repo;
+static git_object *target;
+
+void test_reset_hard__initialize(void)
+{
+ repo = cl_git_sandbox_init("status");
+ target = NULL;
+}
+
+void test_reset_hard__cleanup(void)
+{
+ if (target != NULL) {
+ git_object_free(target);
+ target = NULL;
+ }
+
+ cl_git_sandbox_cleanup();
+}
+
+static int strequal_ignore_eol(const char *exp, const char *str)
+{
+ while (*exp && *str) {
+ if (*exp != *str) {
+ while (*exp == '\r' || *exp == '\n') ++exp;
+ while (*str == '\r' || *str == '\n') ++str;
+ if (*exp != *str)
+ return false;
+ } else {
+ exp++; str++;
+ }
+ }
+ return (!*exp && !*str);
+}
+
+void test_reset_hard__resetting_reverts_modified_files(void)
+{
+ git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ int i;
+ static const char *files[4] = {
+ "current_file",
+ "modified_file",
+ "staged_new_file",
+ "staged_changes_modified_file" };
+ static const char *before[4] = {
+ "current_file\n",
+ "modified_file\nmodified_file\n",
+ "staged_new_file\n",
+ "staged_changes_modified_file\nstaged_changes_modified_file\nstaged_changes_modified_file\n"
+ };
+ static const char *after[4] = {
+ "current_file\n",
+ "modified_file\n",
+ NULL,
+ "staged_changes_modified_file\n"
+ };
+ const char *wd = git_repository_workdir(repo);
+
+ cl_assert(wd);
+
+ for (i = 0; i < 4; ++i) {
+ cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_futils_readbuffer(&content, path.ptr));
+ cl_assert_equal_s(before[i], content.ptr);
+ }
+
+ retrieve_target_from_oid(
+ &target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
+
+ for (i = 0; i < 4; ++i) {
+ cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ if (after[i]) {
+ cl_git_pass(git_futils_readbuffer(&content, path.ptr));
+ cl_assert(strequal_ignore_eol(after[i], content.ptr));
+ } else {
+ cl_assert(!git_path_exists(path.ptr));
+ }
+ }
+
+ git_buf_free(&content);
+ git_buf_free(&path);
+}
+
+void test_reset_hard__cannot_reset_in_a_bare_repository(void)
+{
+ git_repository *bare;
+
+ cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
+ cl_assert(git_repository_is_bare(bare) == true);
+
+ retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
+
+ cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD));
+
+ git_repository_free(bare);
+}
+
+static void index_entry_init(git_index *index, int side, git_oid *oid)
+{
+ git_index_entry entry;
+
+ memset(&entry, 0x0, sizeof(git_index_entry));
+
+ entry.path = "conflicting_file";
+ entry.flags = (side << GIT_IDXENTRY_STAGESHIFT);
+ entry.mode = 0100644;
+ git_oid_cpy(&entry.oid, oid);
+
+ cl_git_pass(git_index_add(index, &entry));
+}
+
+static void unmerged_index_init(git_index *index, int entries)
+{
+ int write_ancestor = 1;
+ int write_ours = 2;
+ int write_theirs = 4;
+ git_oid ancestor, ours, theirs;
+
+ git_oid_fromstr(&ancestor, "6bb0d9f700543ba3d318ba7075fc3bd696b4287b");
+ git_oid_fromstr(&ours, "b19a1e93bec1317dc6097229e12afaffbfa74dc2");
+ git_oid_fromstr(&theirs, "950b81b7eee953d050aa05a641f8e056c85dd1bd");
+
+ cl_git_rewritefile("status/conflicting_file", "conflicting file\n");
+
+ if (entries & write_ancestor)
+ index_entry_init(index, 1, &ancestor);
+
+ if (entries & write_ours)
+ index_entry_init(index, 2, &ours);
+
+ if (entries & write_theirs)
+ index_entry_init(index, 3, &theirs);
+}
+
+void test_reset_hard__resetting_reverts_unmerged(void)
+{
+ git_index *index;
+ int entries;
+
+ /* Ensure every permutation of non-zero stage entries results in the
+ * path being cleaned up. */
+ for (entries = 1; entries < 8; entries++) {
+ cl_git_pass(git_repository_index(&index, repo));
+
+ unmerged_index_init(index, entries);
+ cl_git_pass(git_index_write(index));
+
+ retrieve_target_from_oid(&target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
+
+ cl_assert(git_path_exists("status/conflicting_file") == 0);
+
+ git_object_free(target);
+ target = NULL;
+
+ git_index_free(index);
+ }
+}
+
+void test_reset_hard__cleans_up_merge(void)
+{
+ git_buf merge_head_path = GIT_BUF_INIT,
+ merge_msg_path = GIT_BUF_INIT,
+ merge_mode_path = GIT_BUF_INIT,
+ orig_head_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+
+ cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
+ cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
+
+ cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
+ cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");
+
+ cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
+ cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
+
+ retrieve_target_from_oid(&target, repo, "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
+
+ cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
+ cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
+ cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));
+
+ cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
+ cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));
+
+ git_buf_free(&merge_head_path);
+ git_buf_free(&merge_msg_path);
+ git_buf_free(&merge_mode_path);
+ git_buf_free(&orig_head_path);
+}
diff --git a/tests-clar/reset/mixed.c b/tests-clar/reset/mixed.c
new file mode 100644
index 000000000..7b90c23f1
--- /dev/null
+++ b/tests-clar/reset/mixed.c
@@ -0,0 +1,49 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "reset_helpers.h"
+#include "path.h"
+
+static git_repository *repo;
+static git_object *target;
+
+void test_reset_mixed__initialize(void)
+{
+ repo = cl_git_sandbox_init("attr");
+ target = NULL;
+}
+
+void test_reset_mixed__cleanup(void)
+{
+ git_object_free(target);
+ target = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
+{
+ git_repository *bare;
+
+ cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
+ cl_assert(git_repository_is_bare(bare) == true);
+
+ retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
+
+ cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED));
+
+ git_repository_free(bare);
+}
+
+void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
+{
+ unsigned int status;
+
+ cl_git_pass(git_status_file(&status, repo, "macro_bad"));
+ cl_assert(status == GIT_STATUS_CURRENT);
+ retrieve_target_from_oid(&target, repo, "605812ab7fe421fdd325a935d35cb06a9234a7d7");
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
+
+ cl_git_pass(git_status_file(&status, repo, "macro_bad"));
+ cl_assert(status == GIT_STATUS_WT_NEW);
+}
diff --git a/tests-clar/reset/reset_helpers.c b/tests-clar/reset/reset_helpers.c
new file mode 100644
index 000000000..17edca4e9
--- /dev/null
+++ b/tests-clar/reset/reset_helpers.c
@@ -0,0 +1,10 @@
+#include "clar_libgit2.h"
+#include "reset_helpers.h"
+
+void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha)
+{
+ git_oid oid;
+
+ cl_git_pass(git_oid_fromstr(&oid, sha));
+ cl_git_pass(git_object_lookup(object_out, repo, &oid, GIT_OBJ_ANY));
+}
diff --git a/tests-clar/reset/reset_helpers.h b/tests-clar/reset/reset_helpers.h
new file mode 100644
index 000000000..5dbe9d2c7
--- /dev/null
+++ b/tests-clar/reset/reset_helpers.h
@@ -0,0 +1,6 @@
+#include "common.h"
+
+#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
+#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
+
+extern void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha);
diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c
new file mode 100644
index 000000000..884697c91
--- /dev/null
+++ b/tests-clar/reset/soft.c
@@ -0,0 +1,157 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "reset_helpers.h"
+#include "path.h"
+#include "repo/repo_helpers.h"
+
+static git_repository *repo;
+static git_object *target;
+
+void test_reset_soft__initialize(void)
+{
+ repo = cl_git_sandbox_init("testrepo.git");
+}
+
+void test_reset_soft__cleanup(void)
+{
+ git_object_free(target);
+ target = NULL;
+
+ cl_git_sandbox_cleanup();
+}
+
+static void assert_reset_soft(bool should_be_detached)
+{
+ git_oid oid;
+
+ cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
+ cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
+
+ retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
+
+ cl_assert(git_repository_head_detached(repo) == should_be_detached);
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
+
+ cl_assert(git_repository_head_detached(repo) == should_be_detached);
+
+ cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
+ cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
+}
+
+void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(void)
+{
+ assert_reset_soft(false);
+}
+
+void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
+{
+ git_repository_detach_head(repo);
+
+ assert_reset_soft(true);
+}
+
+void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void)
+{
+ git_oid oid;
+ char raw_head_oid[GIT_OID_HEXSZ + 1];
+
+ cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
+ git_oid_fmt(raw_head_oid, &oid);
+ raw_head_oid[GIT_OID_HEXSZ] = '\0';
+
+ retrieve_target_from_oid(&target, repo, raw_head_oid);
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
+
+ cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
+ cl_git_pass(git_oid_streq(&oid, raw_head_oid));
+}
+
+void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void)
+{
+ git_oid oid;
+
+ /* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
+ retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
+
+ cl_assert(git_repository_head_detached(repo) == false);
+ cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
+ cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
+}
+
+void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
+{
+ /* 53fc32d is the tree of commit e90810b */
+ retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
+
+ cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
+ git_object_free(target);
+
+ /* 521d87c is an annotated tag pointing to a blob */
+ retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
+ cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
+}
+
+void test_reset_soft__resetting_against_an_orphaned_head_repo_makes_the_head_no_longer_orphaned(void)
+{
+ git_reference *head;
+
+ retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
+
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(true, git_repository_head_orphan(repo));
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
+
+ cl_assert_equal_i(false, git_repository_head_orphan(repo));
+
+ cl_git_pass(git_reference_lookup(&head, repo, NON_EXISTING_HEAD));
+ cl_assert_equal_i(0, git_oid_streq(git_reference_target(head), KNOWN_COMMIT_IN_BARE_REPO));
+
+ git_reference_free(head);
+}
+
+void test_reset_soft__fails_when_merging(void)
+{
+ git_buf merge_head_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_repository_detach_head(repo));
+ cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+
+ retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
+
+ cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT));
+ cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
+
+ git_buf_free(&merge_head_path);
+}
+
+void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE_HEAD_file_existence(void)
+{
+ git_index *index;
+ git_reference *head;
+ git_buf merge_head_path = GIT_BUF_INIT;
+
+ cl_git_sandbox_cleanup();
+
+ repo = cl_git_sandbox_init("mergedrepo");
+
+ cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
+ git_buf_free(&merge_head_path);
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert_equal_i(true, git_index_has_conflicts(index));
+ git_index_free(index);
+
+ cl_git_pass(git_repository_head(&head, repo));
+ cl_git_pass(git_reference_peel(&target, head, GIT_OBJ_COMMIT));
+ git_reference_free(head);
+
+ cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT));
+}
diff --git a/tests-clar/resources/attr/.gitted/index b/tests-clar/resources/attr/.gitted/index
index 1d60eab8f..439ffb151 100644
--- a/tests-clar/resources/attr/.gitted/index
+++ b/tests-clar/resources/attr/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/attr/.gitted/logs/HEAD b/tests-clar/resources/attr/.gitted/logs/HEAD
index 73f00f345..8ece39f37 100644
--- a/tests-clar/resources/attr/.gitted/logs/HEAD
+++ b/tests-clar/resources/attr/.gitted/logs/HEAD
@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6
f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes
a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub
217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status
+24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911 yorah <yoram.harmelin@gmail.com> 1341230701 +0200 commit: Updating test data so we can test inter-hunk-context
diff --git a/tests-clar/resources/attr/.gitted/logs/refs/heads/master b/tests-clar/resources/attr/.gitted/logs/refs/heads/master
index 73f00f345..8ece39f37 100644
--- a/tests-clar/resources/attr/.gitted/logs/refs/heads/master
+++ b/tests-clar/resources/attr/.gitted/logs/refs/heads/master
@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6
f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes
a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub
217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status
+24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911 yorah <yoram.harmelin@gmail.com> 1341230701 +0200 commit: Updating test data so we can test inter-hunk-context
diff --git a/tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512 b/tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512
new file mode 100644
index 000000000..e49c94acd
--- /dev/null
+++ b/tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512
Binary files differ
diff --git a/tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b911 b/tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b911
new file mode 100644
index 000000000..3dcf088e4
--- /dev/null
+++ b/tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b911
@@ -0,0 +1 @@
+xŽKj1D³Ö)zolôiõŒ _"hiÚK2²L’ÛG!7Ȫ¯¨ÔJÉ,ù—ÑEÀPXÝÆDèÈSŒˆ ] /)Òê}¢Í/èUwîR§ˆ. Åj댋‘pÕë‚Á#š#:?ÇÞ:|·Î;¼þF9íÜ‹Ür=_ çÛ)µòÆ¡±N/ÚÀA[­ÕlçÃ!ÿqÕû}ã‘ë†<Lfx4øH\ÿº\çôqÖcj“¿†úƒTè \ No newline at end of file
diff --git a/tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b b/tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b
new file mode 100644
index 000000000..985c2e281
--- /dev/null
+++ b/tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b
@@ -0,0 +1 @@
+x5Ž1Â0 E™}Š?–΀;•˜SâˆÔ®’”ŠÛ“Ðv´ýߢ8ŸO‡'FÈÈ:2r™ƒ)(¾ &¢Þ·«×9Z¼A Âð³¼Ñ¹r9Ýl¬ %¨˜ˆ„3ÑEo‚£.ÿV­Õi<Bñà F­©MÌb‰®+ÂÙŸ*vµªÛþìÖmõ÷¾¢ÞLK†Ý­D?+­N \ No newline at end of file
diff --git a/tests-clar/resources/attr/.gitted/objects/b4/35cd5689a0fb54afbeda4ac20368aa480e8f04 b/tests-clar/resources/attr/.gitted/objects/b4/35cd5689a0fb54afbeda4ac20368aa480e8f04
new file mode 100644
index 000000000..ffe3473f4
--- /dev/null
+++ b/tests-clar/resources/attr/.gitted/objects/b4/35cd5689a0fb54afbeda4ac20368aa480e8f04
Binary files differ
diff --git a/tests-clar/resources/attr/.gitted/refs/heads/master b/tests-clar/resources/attr/.gitted/refs/heads/master
index 8768776b3..b3abfff7d 100644
--- a/tests-clar/resources/attr/.gitted/refs/heads/master
+++ b/tests-clar/resources/attr/.gitted/refs/heads/master
@@ -1 +1 @@
-24fa9a9fc4e202313e24b648087495441dab432b
+8d0b9df9bd30be7910ddda60548d485bc302b911
diff --git a/tests-clar/resources/attr/gitignore b/tests-clar/resources/attr/gitignore
index 546d48f3a..192967012 100644
--- a/tests-clar/resources/attr/gitignore
+++ b/tests-clar/resources/attr/gitignore
@@ -1,3 +1,2 @@
-sub
ign
dir/
diff --git a/tests-clar/resources/attr/root_test4.txt b/tests-clar/resources/attr/root_test4.txt
index fe773770c..a0f7217ae 100644
--- a/tests-clar/resources/attr/root_test4.txt
+++ b/tests-clar/resources/attr/root_test4.txt
@@ -1,6 +1,6 @@
Here is some stuff at the start
-This should go in one hunk
+This should go in one hunk (first)
Some additional lines
@@ -8,7 +8,7 @@ Down here below the other lines
With even more at the end
-Followed by a second hunk of stuff
+Followed by a second hunk of stuff (second)
That happens down here
diff --git a/tests-clar/resources/attr/sub/ign b/tests-clar/resources/attr/sub/ign
deleted file mode 100644
index 592fd2594..000000000
--- a/tests-clar/resources/attr/sub/ign
+++ /dev/null
@@ -1 +0,0 @@
-ignore me
diff --git a/tests-clar/resources/attr/sub/ign/file b/tests-clar/resources/attr/sub/ign/file
new file mode 100644
index 000000000..4dcd992e1
--- /dev/null
+++ b/tests-clar/resources/attr/sub/ign/file
@@ -0,0 +1 @@
+in ignored dir
diff --git a/tests-clar/resources/attr/sub/ign/sub/file b/tests-clar/resources/attr/sub/ign/sub/file
new file mode 100644
index 000000000..88aca0164
--- /dev/null
+++ b/tests-clar/resources/attr/sub/ign/sub/file
@@ -0,0 +1 @@
+below ignored dir
diff --git a/tests-clar/resources/bad_tag.git/packed-refs b/tests-clar/resources/bad_tag.git/packed-refs
index f9fd2fd4a..9da16459b 100644
--- a/tests-clar/resources/bad_tag.git/packed-refs
+++ b/tests-clar/resources/bad_tag.git/packed-refs
@@ -1,3 +1,5 @@
# pack-refs with: peeled
eda9f45a2a98d4c17a09d681d88569fa4ea91755 refs/tags/e90810b
^e90810b8df3e80c413d903f631643c716887138d
+d3bacb8d3ff25876a961b1963b6515170d0151ab refs/tags/hello
+^6dcf9bf7541ee10456529833502442f385010c3d \ No newline at end of file
diff --git a/tests-clar/resources/binaryunicode/.gitted/HEAD b/tests-clar/resources/binaryunicode/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/binaryunicode/.gitted/config b/tests-clar/resources/binaryunicode/.gitted/config
new file mode 100644
index 000000000..f9845fe7e
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ autocrlf = true
+ logallrefupdates = true
diff --git a/tests-clar/resources/binaryunicode/.gitted/description b/tests-clar/resources/binaryunicode/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/binaryunicode/.gitted/index b/tests-clar/resources/binaryunicode/.gitted/index
new file mode 100644
index 000000000..a216d2219
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/binaryunicode/.gitted/info/exclude b/tests-clar/resources/binaryunicode/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/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-clar/resources/binaryunicode/.gitted/info/refs b/tests-clar/resources/binaryunicode/.gitted/info/refs
new file mode 100644
index 000000000..128eea7c9
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/info/refs
@@ -0,0 +1,3 @@
+39e046d1416a208265b754124d0d197b4c9c0c47 refs/heads/branch1
+9e7d8bcd4d24dd57e3f1179aaf7afe648ff50e80 refs/heads/branch2
+d2a291469f4c11f387600d189313b927ddfe891c refs/heads/master
diff --git a/tests-clar/resources/binaryunicode/.gitted/objects/info/packs b/tests-clar/resources/binaryunicode/.gitted/objects/info/packs
new file mode 100644
index 000000000..c2de8f5cb
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/objects/info/packs
@@ -0,0 +1,2 @@
+P pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.pack
+
diff --git a/tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.idx b/tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.idx
new file mode 100644
index 000000000..8a05b2beb
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.idx
Binary files differ
diff --git a/tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.pack b/tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.pack
new file mode 100644
index 000000000..6b5ddc414
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/objects/pack/pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.pack
Binary files differ
diff --git a/tests-clar/resources/binaryunicode/.gitted/refs/heads/branch1 b/tests-clar/resources/binaryunicode/.gitted/refs/heads/branch1
new file mode 100644
index 000000000..0595fbd31
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/refs/heads/branch1
@@ -0,0 +1 @@
+39e046d1416a208265b754124d0d197b4c9c0c47
diff --git a/tests-clar/resources/binaryunicode/.gitted/refs/heads/branch2 b/tests-clar/resources/binaryunicode/.gitted/refs/heads/branch2
new file mode 100644
index 000000000..d86856687
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/refs/heads/branch2
@@ -0,0 +1 @@
+9e7d8bcd4d24dd57e3f1179aaf7afe648ff50e80
diff --git a/tests-clar/resources/binaryunicode/.gitted/refs/heads/master b/tests-clar/resources/binaryunicode/.gitted/refs/heads/master
new file mode 100644
index 000000000..552d166da
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/.gitted/refs/heads/master
@@ -0,0 +1 @@
+d2a291469f4c11f387600d189313b927ddfe891c
diff --git a/tests-clar/resources/binaryunicode/file.txt b/tests-clar/resources/binaryunicode/file.txt
new file mode 100644
index 000000000..2255035d4
--- /dev/null
+++ b/tests-clar/resources/binaryunicode/file.txt
@@ -0,0 +1 @@
+Master branch.
diff --git a/tests-clar/resources/config/config11 b/tests-clar/resources/config/config11
index 880c94589..7331862a5 100644
--- a/tests-clar/resources/config/config11
+++ b/tests-clar/resources/config/config11
@@ -1,3 +1,5 @@
[remote "fancy"]
url = git://github.com/libgit2/libgit2
url = git://git.example.com/libgit2
+
+
diff --git a/tests-clar/resources/config/config14 b/tests-clar/resources/config/config14
new file mode 100644
index 000000000..ef2198c45
--- /dev/null
+++ b/tests-clar/resources/config/config14
@@ -0,0 +1,4 @@
+[a]
+ b=c
+[d]
+ e = f
diff --git a/tests-clar/resources/config/config15 b/tests-clar/resources/config/config15
new file mode 100644
index 000000000..6d34f817b
--- /dev/null
+++ b/tests-clar/resources/config/config15
@@ -0,0 +1,3 @@
+[core]
+ dummy2 = 7
+ global = 17
diff --git a/tests-clar/resources/config/config16 b/tests-clar/resources/config/config16
new file mode 100644
index 000000000..f25cdb728
--- /dev/null
+++ b/tests-clar/resources/config/config16
@@ -0,0 +1,3 @@
+[core]
+ dummy2 = 28
+ system = 11
diff --git a/tests-clar/resources/config/config17 b/tests-clar/resources/config/config17
new file mode 100644
index 000000000..ca25a86af
--- /dev/null
+++ b/tests-clar/resources/config/config17
@@ -0,0 +1,3 @@
+[core]
+ dummy2 = 7
+ global = 17 \ No newline at end of file
diff --git a/tests-clar/resources/config/config18 b/tests-clar/resources/config/config18
new file mode 100644
index 000000000..cb6fd5ebc
--- /dev/null
+++ b/tests-clar/resources/config/config18
@@ -0,0 +1,5 @@
+[core]
+ int32global = 28
+ int64global = 9223372036854775803
+ boolglobal = true
+ stringglobal = I'm a global config value! \ No newline at end of file
diff --git a/tests-clar/resources/config/config19 b/tests-clar/resources/config/config19
new file mode 100644
index 000000000..f3ae5a640
--- /dev/null
+++ b/tests-clar/resources/config/config19
@@ -0,0 +1,5 @@
+[core]
+ int32global = -1
+ int64global = -2
+ boolglobal = false
+ stringglobal = don't find me! \ No newline at end of file
diff --git a/tests-clar/resources/config/config4 b/tests-clar/resources/config/config4
index 741fa0ffd..9dd40419e 100644
--- a/tests-clar/resources/config/config4
+++ b/tests-clar/resources/config/config4
@@ -1,3 +1,5 @@
# A variable name on its own is valid
[some.section]
variable
+# A variable and '=' is accepted, but it's not considered true
+ variableeq =
diff --git a/tests-clar/resources/crlf/.gitted/HEAD b/tests-clar/resources/crlf/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/crlf/.gitted/config b/tests-clar/resources/crlf/.gitted/config
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/config
diff --git a/tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448c b/tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448c
new file mode 100644
index 000000000..c3b7598c0
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448c
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88 b/tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88
new file mode 100644
index 000000000..e118d6656
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205f b/tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205f
new file mode 100644
index 000000000..b7a1f3290
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205f
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987 b/tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987
new file mode 100644
index 000000000..5366acd8c
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb b/tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb
new file mode 100644
index 000000000..96d5b2f91
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb
@@ -0,0 +1 @@
+x¥ŽÝ 1„}NÛ€²ù½,ˆøb6K6œ`.’‹Ø¾QìÀ·™o†ab-åÖA»ë0¡ódXš”•btnr:0¡cä¤yž(*´Y<Bãµå0‡¨q m-y«|TSöα6èGŸsáÙ—Úà’^¡%¸.µlu…#úQgþ?wˆµœ@jëµ”DöèÅ ãlç?gDl÷ ·¾‰7kP \ No newline at end of file
diff --git a/tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6 b/tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6
new file mode 100644
index 000000000..0cf707296
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3a b/tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3a
new file mode 100644
index 000000000..5c701b867
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3a
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49 b/tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49
new file mode 100644
index 000000000..8e836aba1
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d5966 b/tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d5966
new file mode 100644
index 000000000..33d59f1f1
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d5966
@@ -0,0 +1 @@
+xKÊÉOR02aH.ÊIãåÂ$œž  \ No newline at end of file
diff --git a/tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62e b/tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62e
new file mode 100644
index 000000000..4c544d5ef
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62e
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112c b/tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112c
new file mode 100644
index 000000000..3db13aa79
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112c
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511 b/tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511
new file mode 100644
index 000000000..117dc725a
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407f b/tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407f
new file mode 100644
index 000000000..2e8d10b76
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407f
Binary files differ
diff --git a/tests-clar/resources/crlf/.gitted/refs/heads/master b/tests-clar/resources/crlf/.gitted/refs/heads/master
new file mode 100644
index 000000000..a2dbe0c2d
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/refs/heads/master
@@ -0,0 +1 @@
+12faf3c1ea55f572473cec9052fca468c3584ccb
diff --git a/tests-clar/resources/crlf/.gitted/refs/heads/utf8 b/tests-clar/resources/crlf/.gitted/refs/heads/utf8
new file mode 100644
index 000000000..4b32f7f91
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/refs/heads/utf8
@@ -0,0 +1 @@
+baaa042ab2976f8264e467988e6112ee518ec62e
diff --git a/tests-clar/resources/deprecated-mode.git/HEAD b/tests-clar/resources/deprecated-mode.git/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/deprecated-mode.git/config b/tests-clar/resources/deprecated-mode.git/config
new file mode 100644
index 000000000..f57351fd5
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/config
@@ -0,0 +1,6 @@
+[core]
+ bare = true
+ repositoryformatversion = 0
+ filemode = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/deprecated-mode.git/description b/tests-clar/resources/deprecated-mode.git/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/deprecated-mode.git/index b/tests-clar/resources/deprecated-mode.git/index
new file mode 100644
index 000000000..682740603
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/index
Binary files differ
diff --git a/tests-clar/resources/deprecated-mode.git/info/exclude b/tests-clar/resources/deprecated-mode.git/info/exclude
new file mode 100644
index 000000000..6d05881d3
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/info/exclude
@@ -0,0 +1,2 @@
+# File patterns to ignore; see `git help ignore` for more information.
+# Lines that start with '#' are comments.
diff --git a/tests-clar/resources/deprecated-mode.git/objects/06/262edc257418e9987caf999f9a7a3e1547adff b/tests-clar/resources/deprecated-mode.git/objects/06/262edc257418e9987caf999f9a7a3e1547adff
new file mode 100644
index 000000000..a030cf7a7
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/objects/06/262edc257418e9987caf999f9a7a3e1547adff
Binary files differ
diff --git a/tests-clar/resources/deprecated-mode.git/objects/08/10fb7818088ff5ac41ee49199b51473b1bd6c7 b/tests-clar/resources/deprecated-mode.git/objects/08/10fb7818088ff5ac41ee49199b51473b1bd6c7
new file mode 100644
index 000000000..52d56936a
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/objects/08/10fb7818088ff5ac41ee49199b51473b1bd6c7
Binary files differ
diff --git a/tests-clar/resources/deprecated-mode.git/objects/1b/05fdaa881ee45b48cbaa5e9b037d667a47745e b/tests-clar/resources/deprecated-mode.git/objects/1b/05fdaa881ee45b48cbaa5e9b037d667a47745e
new file mode 100644
index 000000000..ae7765a70
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/objects/1b/05fdaa881ee45b48cbaa5e9b037d667a47745e
Binary files differ
diff --git a/tests-clar/resources/deprecated-mode.git/objects/3d/0970ec547fc41ef8a5882dde99c6adce65b021 b/tests-clar/resources/deprecated-mode.git/objects/3d/0970ec547fc41ef8a5882dde99c6adce65b021
new file mode 100644
index 000000000..595283e89
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/objects/3d/0970ec547fc41ef8a5882dde99c6adce65b021
Binary files differ
diff --git a/tests-clar/resources/deprecated-mode.git/refs/heads/master b/tests-clar/resources/deprecated-mode.git/refs/heads/master
new file mode 100644
index 000000000..1e106dfa4
--- /dev/null
+++ b/tests-clar/resources/deprecated-mode.git/refs/heads/master
@@ -0,0 +1 @@
+06262edc257418e9987caf999f9a7a3e1547adff
diff --git a/tests-clar/resources/diff/.gitted/HEAD b/tests-clar/resources/diff/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/diff/.gitted/config b/tests-clar/resources/diff/.gitted/config
new file mode 100644
index 000000000..77a27ef1d
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = false
diff --git a/tests-clar/resources/diff/.gitted/description b/tests-clar/resources/diff/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/diff/.gitted/index b/tests-clar/resources/diff/.gitted/index
new file mode 100644
index 000000000..e1071874e
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/info/exclude b/tests-clar/resources/diff/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/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-clar/resources/diff/.gitted/logs/HEAD b/tests-clar/resources/diff/.gitted/logs/HEAD
new file mode 100644
index 000000000..8c6f6fd18
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/logs/HEAD
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 d70d245ed97ed2aa596dd1af6536e4bfdb047b69 Russell Belfer <rb@github.com> 1347559804 -0700 commit (initial): initial commit
+d70d245ed97ed2aa596dd1af6536e4bfdb047b69 7a9e0b02e63179929fed24f0a3e0f19168114d10 Russell Belfer <rb@github.com> 1347560491 -0700 commit: some changes
diff --git a/tests-clar/resources/diff/.gitted/logs/refs/heads/master b/tests-clar/resources/diff/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..8c6f6fd18
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/logs/refs/heads/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 d70d245ed97ed2aa596dd1af6536e4bfdb047b69 Russell Belfer <rb@github.com> 1347559804 -0700 commit (initial): initial commit
+d70d245ed97ed2aa596dd1af6536e4bfdb047b69 7a9e0b02e63179929fed24f0a3e0f19168114d10 Russell Belfer <rb@github.com> 1347560491 -0700 commit: some changes
diff --git a/tests-clar/resources/diff/.gitted/objects/29/ab7053bb4dde0298e03e2c179e890b7dd465a7 b/tests-clar/resources/diff/.gitted/objects/29/ab7053bb4dde0298e03e2c179e890b7dd465a7
new file mode 100644
index 000000000..94f9a676d
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/29/ab7053bb4dde0298e03e2c179e890b7dd465a7
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/objects/3e/5bcbad2a68e5bc60a53b8388eea53a1a7ab847 b/tests-clar/resources/diff/.gitted/objects/3e/5bcbad2a68e5bc60a53b8388eea53a1a7ab847
new file mode 100644
index 000000000..9fed523dc
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/3e/5bcbad2a68e5bc60a53b8388eea53a1a7ab847
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/objects/54/6c735f16a3b44d9784075c2c0dab2ac9bf1989 b/tests-clar/resources/diff/.gitted/objects/54/6c735f16a3b44d9784075c2c0dab2ac9bf1989
new file mode 100644
index 000000000..d7df4d6a1
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/54/6c735f16a3b44d9784075c2c0dab2ac9bf1989
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/objects/7a/9e0b02e63179929fed24f0a3e0f19168114d10 b/tests-clar/resources/diff/.gitted/objects/7a/9e0b02e63179929fed24f0a3e0f19168114d10
new file mode 100644
index 000000000..9bc25eb34
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/7a/9e0b02e63179929fed24f0a3e0f19168114d10
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/objects/7b/808f723a8ca90df319682c221187235af76693 b/tests-clar/resources/diff/.gitted/objects/7b/808f723a8ca90df319682c221187235af76693
new file mode 100644
index 000000000..2fd266be6
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/7b/808f723a8ca90df319682c221187235af76693
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/objects/88/789109439c1e1c3cd45224001edee5304ed53c b/tests-clar/resources/diff/.gitted/objects/88/789109439c1e1c3cd45224001edee5304ed53c
new file mode 100644
index 000000000..7598b5914
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/88/789109439c1e1c3cd45224001edee5304ed53c
@@ -0,0 +1 @@
+x+)JMU07g040031QHÌË/ÉH-Ò+©(aÉ)Ž[¼Åwz {Œïj­“û%;¡ÊŠRSrSÁª4Wïö½Ç4ãŽø¼NîÚ+©Ë¶a \ No newline at end of file
diff --git a/tests-clar/resources/diff/.gitted/objects/cb/8294e696339863df760b2ff5d1e275bee72455 b/tests-clar/resources/diff/.gitted/objects/cb/8294e696339863df760b2ff5d1e275bee72455
new file mode 100644
index 000000000..86ebe04fe
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/cb/8294e696339863df760b2ff5d1e275bee72455
Binary files differ
diff --git a/tests-clar/resources/diff/.gitted/objects/d7/0d245ed97ed2aa596dd1af6536e4bfdb047b69 b/tests-clar/resources/diff/.gitted/objects/d7/0d245ed97ed2aa596dd1af6536e4bfdb047b69
new file mode 100644
index 000000000..99304c4aa
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/objects/d7/0d245ed97ed2aa596dd1af6536e4bfdb047b69
@@ -0,0 +1 @@
+x•Û !óm·_ׄRB:XÝkVpWpµÿ© ¿‡™9±î{î ,^z#‚œôšŒ7JygÔš¬áA¦„« i1Y©Ù2úV¼ÇyR)𢒨Á½…ç'÷m„[¬û„ÒÑ;®áÊ-çl®ó¯Oô_“å#÷¼ø%Øœv8¤ \ No newline at end of file
diff --git a/tests-clar/resources/diff/.gitted/refs/heads/master b/tests-clar/resources/diff/.gitted/refs/heads/master
new file mode 100644
index 000000000..a83afc38b
--- /dev/null
+++ b/tests-clar/resources/diff/.gitted/refs/heads/master
@@ -0,0 +1 @@
+7a9e0b02e63179929fed24f0a3e0f19168114d10
diff --git a/tests-clar/resources/diff/another.txt b/tests-clar/resources/diff/another.txt
new file mode 100644
index 000000000..d0e0bae4d
--- /dev/null
+++ b/tests-clar/resources/diff/another.txt
@@ -0,0 +1,38 @@
+Git is fast. With Git, nearly all operations are performed locally, giving
+it an huge speed advantage on centralized systems that constantly have to
+communicate with a server somewh3r3.
+
+For testing, large AWS instances were set up in the same availability
+zone. Git and SVN were installed on both machines, the Ruby repository was
+copied to both Git and SVN servers, and common operations were performed on
+both.
+
+In some cases the commands don't match up exactly. Here, matching on the
+lowest common denominator was attempted. For example, the 'commit' tests
+also include the time to push for Git, though most of the time you would not
+actually be pushing to the server immediately after a commit where the two
+commands cannot be separated in SVN.
+
+Note that this is the best case scenario for SVN - a server with no load
+with an 80MB/s bandwidth connection to the client machine. Nearly all of
+these times would be even worse for SVN if that connection was slower, while
+many of the Git times would not be affected.
+
+Clearly, in many of these common version control operations, Git is one or
+two orders of magnitude faster than SVN, even under ideal conditions for
+SVN.
+
+Let's see how common operations stack up against Subversion, a common
+centralized version control system that is similar to CVS or
+Perforce. Smaller is faster.
+
+One place where Git is slower is in the initial clone operation. Here, Git
+One place where Git is slower is in the initial clone operation. Here, Git
+One place where Git is slower is in the initial clone operation. Here, Git
+seen in the above charts, it's not considerably slower for an operation that
+is only performed once.
+
+It's also interesting to note that the size of the data on the client side
+is very similar even though Git also has every version of every file for the
+entire history of the project. This illustrates how efficient it is at
+compressing and storing data on the client side. \ No newline at end of file
diff --git a/tests-clar/resources/diff/readme.txt b/tests-clar/resources/diff/readme.txt
new file mode 100644
index 000000000..beedf288d
--- /dev/null
+++ b/tests-clar/resources/diff/readme.txt
@@ -0,0 +1,36 @@
+The Git feature that r3ally mak3s it stand apart from n3arly 3v3ry other SCM
+out there is its branching model.
+
+Git allows and encourages you to have multiple local branches that can be
+entirely independent of each other. The creation, merging, and deletion of
+those lines of development takes seconds.
+
+Git allows and encourages you to have multiple local branches that can be
+entirely independent of each other. The creation, merging, and deletion of
+those lines of development takes seconds.
+
+This means that you can do things like:
+
+Role-Bas3d Codelin3s. Have a branch that always contains only what goes to
+production, another that you merge work into for testing, and several
+smaller ones for day to day work.
+
+Feature Based Workflow. Create new branches for each new feature you're
+working on so you can seamlessly switch back and forth between them, then
+delete each branch when that feature gets merged into your main line.
+
+Disposable Experimentation. Create a branch to experiment in, realize it's
+not going to work, and just delete it - abandoning the work—with nobody else
+ever seeing it (even if you've pushed other branches in the meantime).
+
+Notably, when you push to a remote repository, you do not have to push all
+share it with others.
+
+Git allows and encourages you to have multiple local branches that can be
+entirely independent of each other. The creation, merging, and deletion of
+those lines of development takes seconds.
+
+There are ways to accomplish some of this with other systems, but the work
+involved is much more difficult and error-prone. Git makes this process
+incredibly easy and it changes the way most developers work when they learn
+it.!
diff --git a/tests-clar/resources/duplicate.git/hooks/applypatch-msg.sample b/tests-clar/resources/duplicate.git/hooks/applypatch-msg.sample
deleted file mode 100755
index 8b2a2fe84..000000000
--- a/tests-clar/resources/duplicate.git/hooks/applypatch-msg.sample
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to check the commit log message taken by
-# applypatch from an e-mail message.
-#
-# The hook should exit with non-zero status after issuing an
-# appropriate message if it wants to stop the commit. The hook is
-# allowed to edit the commit message file.
-#
-# To enable this hook, rename this file to "applypatch-msg".
-
-. git-sh-setup
-test -x "$GIT_DIR/hooks/commit-msg" &&
- exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
-:
diff --git a/tests-clar/resources/duplicate.git/hooks/commit-msg.sample b/tests-clar/resources/duplicate.git/hooks/commit-msg.sample
deleted file mode 100755
index b58d1184a..000000000
--- a/tests-clar/resources/duplicate.git/hooks/commit-msg.sample
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to check the commit log message.
-# Called by "git commit" with one argument, the name of the file
-# that has the commit message. The hook should exit with non-zero
-# status after issuing an appropriate message if it wants to stop the
-# commit. The hook is allowed to edit the commit message file.
-#
-# To enable this hook, rename this file to "commit-msg".
-
-# Uncomment the below to add a Signed-off-by line to the message.
-# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
-# hook is more suited to it.
-#
-# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
-# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
-
-# This example catches duplicate Signed-off-by lines.
-
-test "" = "$(grep '^Signed-off-by: ' "$1" |
- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
- echo >&2 Duplicate Signed-off-by lines.
- exit 1
-}
diff --git a/tests-clar/resources/duplicate.git/hooks/post-update.sample b/tests-clar/resources/duplicate.git/hooks/post-update.sample
deleted file mode 100755
index ec17ec193..000000000
--- a/tests-clar/resources/duplicate.git/hooks/post-update.sample
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to prepare a packed repository for use over
-# dumb transports.
-#
-# To enable this hook, rename this file to "post-update".
-
-exec git update-server-info
diff --git a/tests-clar/resources/duplicate.git/hooks/pre-applypatch.sample b/tests-clar/resources/duplicate.git/hooks/pre-applypatch.sample
deleted file mode 100755
index b1f187c2e..000000000
--- a/tests-clar/resources/duplicate.git/hooks/pre-applypatch.sample
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to verify what is about to be committed
-# by applypatch from an e-mail message.
-#
-# The hook should exit with non-zero status after issuing an
-# appropriate message if it wants to stop the commit.
-#
-# To enable this hook, rename this file to "pre-applypatch".
-
-. git-sh-setup
-test -x "$GIT_DIR/hooks/pre-commit" &&
- exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
-:
diff --git a/tests-clar/resources/duplicate.git/hooks/pre-commit.sample b/tests-clar/resources/duplicate.git/hooks/pre-commit.sample
deleted file mode 100755
index 18c482976..000000000
--- a/tests-clar/resources/duplicate.git/hooks/pre-commit.sample
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to verify what is about to be committed.
-# Called by "git commit" with no arguments. The hook should
-# exit with non-zero status after issuing an appropriate message if
-# it wants to stop the commit.
-#
-# To enable this hook, rename this file to "pre-commit".
-
-if git rev-parse --verify HEAD >/dev/null 2>&1
-then
- against=HEAD
-else
- # Initial commit: diff against an empty tree object
- against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
-fi
-
-# If you want to allow non-ascii filenames set this variable to true.
-allownonascii=$(git config hooks.allownonascii)
-
-# Redirect output to stderr.
-exec 1>&2
-
-# Cross platform projects tend to avoid non-ascii filenames; prevent
-# them from being added to the repository. We exploit the fact that the
-# printable range starts at the space character and ends with tilde.
-if [ "$allownonascii" != "true" ] &&
- # Note that the use of brackets around a tr range is ok here, (it's
- # even required, for portability to Solaris 10's /usr/bin/tr), since
- # the square bracket bytes happen to fall in the designated range.
- test $(git diff --cached --name-only --diff-filter=A -z $against |
- LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
-then
- echo "Error: Attempt to add a non-ascii file name."
- echo
- echo "This can cause problems if you want to work"
- echo "with people on other platforms."
- echo
- echo "To be portable it is advisable to rename the file ..."
- echo
- echo "If you know what you are doing you can disable this"
- echo "check using:"
- echo
- echo " git config hooks.allownonascii true"
- echo
- exit 1
-fi
-
-# If there are whitespace errors, print the offending file names and fail.
-exec git diff-index --check --cached $against --
diff --git a/tests-clar/resources/duplicate.git/hooks/pre-rebase.sample b/tests-clar/resources/duplicate.git/hooks/pre-rebase.sample
deleted file mode 100755
index 9773ed4cb..000000000
--- a/tests-clar/resources/duplicate.git/hooks/pre-rebase.sample
+++ /dev/null
@@ -1,169 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2006, 2008 Junio C Hamano
-#
-# The "pre-rebase" hook is run just before "git rebase" starts doing
-# its job, and can prevent the command from running by exiting with
-# non-zero status.
-#
-# The hook is called with the following parameters:
-#
-# $1 -- the upstream the series was forked from.
-# $2 -- the branch being rebased (or empty when rebasing the current branch).
-#
-# This sample shows how to prevent topic branches that are already
-# merged to 'next' branch from getting rebased, because allowing it
-# would result in rebasing already published history.
-
-publish=next
-basebranch="$1"
-if test "$#" = 2
-then
- topic="refs/heads/$2"
-else
- topic=`git symbolic-ref HEAD` ||
- exit 0 ;# we do not interrupt rebasing detached HEAD
-fi
-
-case "$topic" in
-refs/heads/??/*)
- ;;
-*)
- exit 0 ;# we do not interrupt others.
- ;;
-esac
-
-# Now we are dealing with a topic branch being rebased
-# on top of master. Is it OK to rebase it?
-
-# Does the topic really exist?
-git show-ref -q "$topic" || {
- echo >&2 "No such branch $topic"
- exit 1
-}
-
-# Is topic fully merged to master?
-not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
-if test -z "$not_in_master"
-then
- echo >&2 "$topic is fully merged to master; better remove it."
- exit 1 ;# we could allow it, but there is no point.
-fi
-
-# Is topic ever merged to next? If so you should not be rebasing it.
-only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
-only_next_2=`git rev-list ^master ${publish} | sort`
-if test "$only_next_1" = "$only_next_2"
-then
- not_in_topic=`git rev-list "^$topic" master`
- if test -z "$not_in_topic"
- then
- echo >&2 "$topic is already up-to-date with master"
- exit 1 ;# we could allow it, but there is no point.
- else
- exit 0
- fi
-else
- not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
- /usr/bin/perl -e '
- my $topic = $ARGV[0];
- my $msg = "* $topic has commits already merged to public branch:\n";
- my (%not_in_next) = map {
- /^([0-9a-f]+) /;
- ($1 => 1);
- } split(/\n/, $ARGV[1]);
- for my $elem (map {
- /^([0-9a-f]+) (.*)$/;
- [$1 => $2];
- } split(/\n/, $ARGV[2])) {
- if (!exists $not_in_next{$elem->[0]}) {
- if ($msg) {
- print STDERR $msg;
- undef $msg;
- }
- print STDERR " $elem->[1]\n";
- }
- }
- ' "$topic" "$not_in_next" "$not_in_master"
- exit 1
-fi
-
-exit 0
-
-################################################################
-
-This sample hook safeguards topic branches that have been
-published from being rewound.
-
-The workflow assumed here is:
-
- * Once a topic branch forks from "master", "master" is never
- merged into it again (either directly or indirectly).
-
- * Once a topic branch is fully cooked and merged into "master",
- it is deleted. If you need to build on top of it to correct
- earlier mistakes, a new topic branch is created by forking at
- the tip of the "master". This is not strictly necessary, but
- it makes it easier to keep your history simple.
-
- * Whenever you need to test or publish your changes to topic
- branches, merge them into "next" branch.
-
-The script, being an example, hardcodes the publish branch name
-to be "next", but it is trivial to make it configurable via
-$GIT_DIR/config mechanism.
-
-With this workflow, you would want to know:
-
-(1) ... if a topic branch has ever been merged to "next". Young
- topic branches can have stupid mistakes you would rather
- clean up before publishing, and things that have not been
- merged into other branches can be easily rebased without
- affecting other people. But once it is published, you would
- not want to rewind it.
-
-(2) ... if a topic branch has been fully merged to "master".
- Then you can delete it. More importantly, you should not
- build on top of it -- other people may already want to
- change things related to the topic as patches against your
- "master", so if you need further changes, it is better to
- fork the topic (perhaps with the same name) afresh from the
- tip of "master".
-
-Let's look at this example:
-
- o---o---o---o---o---o---o---o---o---o "next"
- / / / /
- / a---a---b A / /
- / / / /
- / / c---c---c---c B /
- / / / \ /
- / / / b---b C \ /
- / / / / \ /
- ---o---o---o---o---o---o---o---o---o---o---o "master"
-
-
-A, B and C are topic branches.
-
- * A has one fix since it was merged up to "next".
-
- * B has finished. It has been fully merged up to "master" and "next",
- and is ready to be deleted.
-
- * C has not merged to "next" at all.
-
-We would want to allow C to be rebased, refuse A, and encourage
-B to be deleted.
-
-To compute (1):
-
- git rev-list ^master ^topic next
- git rev-list ^master next
-
- if these match, topic has not merged in next at all.
-
-To compute (2):
-
- git rev-list master..topic
-
- if this is empty, it is fully merged to "master".
diff --git a/tests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample b/tests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample
deleted file mode 100755
index f093a02ec..000000000
--- a/tests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to prepare the commit log message.
-# Called by "git commit" with the name of the file that has the
-# commit message, followed by the description of the commit
-# message's source. The hook's purpose is to edit the commit
-# message file. If the hook fails with a non-zero status,
-# the commit is aborted.
-#
-# To enable this hook, rename this file to "prepare-commit-msg".
-
-# This hook includes three examples. The first comments out the
-# "Conflicts:" part of a merge commit.
-#
-# The second includes the output of "git diff --name-status -r"
-# into the message, just before the "git status" output. It is
-# commented because it doesn't cope with --amend or with squashed
-# commits.
-#
-# The third example adds a Signed-off-by line to the message, that can
-# still be edited. This is rarely a good idea.
-
-case "$2,$3" in
- merge,)
- /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
-
-# ,|template,)
-# /usr/bin/perl -i.bak -pe '
-# print "\n" . `git diff --cached --name-status -r`
-# if /^#/ && $first++ == 0' "$1" ;;
-
- *) ;;
-esac
-
-# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
-# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
diff --git a/tests-clar/resources/duplicate.git/hooks/update.sample b/tests-clar/resources/duplicate.git/hooks/update.sample
deleted file mode 100755
index 71ab04edc..000000000
--- a/tests-clar/resources/duplicate.git/hooks/update.sample
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to blocks unannotated tags from entering.
-# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
-#
-# To enable this hook, rename this file to "update".
-#
-# Config
-# ------
-# hooks.allowunannotated
-# This boolean sets whether unannotated tags will be allowed into the
-# repository. By default they won't be.
-# hooks.allowdeletetag
-# This boolean sets whether deleting tags will be allowed in the
-# repository. By default they won't be.
-# hooks.allowmodifytag
-# This boolean sets whether a tag may be modified after creation. By default
-# it won't be.
-# hooks.allowdeletebranch
-# This boolean sets whether deleting branches will be allowed in the
-# repository. By default they won't be.
-# hooks.denycreatebranch
-# This boolean sets whether remotely creating branches will be denied
-# in the repository. By default this is allowed.
-#
-
-# --- Command line
-refname="$1"
-oldrev="$2"
-newrev="$3"
-
-# --- Safety check
-if [ -z "$GIT_DIR" ]; then
- echo "Don't run this script from the command line." >&2
- echo " (if you want, you could supply GIT_DIR then run" >&2
- echo " $0 <ref> <oldrev> <newrev>)" >&2
- exit 1
-fi
-
-if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
- echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
- exit 1
-fi
-
-# --- Config
-allowunannotated=$(git config --bool hooks.allowunannotated)
-allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
-denycreatebranch=$(git config --bool hooks.denycreatebranch)
-allowdeletetag=$(git config --bool hooks.allowdeletetag)
-allowmodifytag=$(git config --bool hooks.allowmodifytag)
-
-# check for no description
-projectdesc=$(sed -e '1q' "$GIT_DIR/description")
-case "$projectdesc" in
-"Unnamed repository"* | "")
- echo "*** Project description file hasn't been set" >&2
- exit 1
- ;;
-esac
-
-# --- Check types
-# if $newrev is 0000...0000, it's a commit to delete a ref.
-zero="0000000000000000000000000000000000000000"
-if [ "$newrev" = "$zero" ]; then
- newrev_type=delete
-else
- newrev_type=$(git cat-file -t $newrev)
-fi
-
-case "$refname","$newrev_type" in
- refs/tags/*,commit)
- # un-annotated tag
- short_refname=${refname##refs/tags/}
- if [ "$allowunannotated" != "true" ]; then
- echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
- echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
- exit 1
- fi
- ;;
- refs/tags/*,delete)
- # delete tag
- if [ "$allowdeletetag" != "true" ]; then
- echo "*** Deleting a tag is not allowed in this repository" >&2
- exit 1
- fi
- ;;
- refs/tags/*,tag)
- # annotated tag
- if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
- then
- echo "*** Tag '$refname' already exists." >&2
- echo "*** Modifying a tag is not allowed in this repository." >&2
- exit 1
- fi
- ;;
- refs/heads/*,commit)
- # branch
- if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
- echo "*** Creating a branch is not allowed in this repository" >&2
- exit 1
- fi
- ;;
- refs/heads/*,delete)
- # delete branch
- if [ "$allowdeletebranch" != "true" ]; then
- echo "*** Deleting a branch is not allowed in this repository" >&2
- exit 1
- fi
- ;;
- refs/remotes/*,commit)
- # tracking branch
- ;;
- refs/remotes/*,delete)
- # delete tracking branch
- if [ "$allowdeletebranch" != "true" ]; then
- echo "*** Deleting a tracking branch is not allowed in this repository" >&2
- exit 1
- fi
- ;;
- *)
- # Anything else (is there anything else?)
- echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
- exit 1
- ;;
-esac
-
-# --- Finished
-exit 0
diff --git a/tests-clar/resources/filemodes/.gitted/HEAD b/tests-clar/resources/filemodes/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/filemodes/.gitted/config b/tests-clar/resources/filemodes/.gitted/config
new file mode 100644
index 000000000..af107929f
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/filemodes/.gitted/description b/tests-clar/resources/filemodes/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/filemodes/.gitted/index b/tests-clar/resources/filemodes/.gitted/index
new file mode 100644
index 000000000..b1b175a9b
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/filemodes/.gitted/info/exclude b/tests-clar/resources/filemodes/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/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-clar/resources/filemodes/.gitted/logs/HEAD b/tests-clar/resources/filemodes/.gitted/logs/HEAD
new file mode 100644
index 000000000..1cb6a84c1
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 9962c8453ba6f0cf8dac7c5dcc2fa2897fa9964a Russell Belfer <rb@github.com> 1338847682 -0700 commit (initial): Initial commit of test data
diff --git a/tests-clar/resources/filemodes/.gitted/logs/refs/heads/master b/tests-clar/resources/filemodes/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..1cb6a84c1
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 9962c8453ba6f0cf8dac7c5dcc2fa2897fa9964a Russell Belfer <rb@github.com> 1338847682 -0700 commit (initial): Initial commit of test data
diff --git a/tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964a b/tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964a
new file mode 100644
index 000000000..cbd2b557a
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964a
Binary files differ
diff --git a/tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1 b/tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1
new file mode 100644
index 000000000..a9eaf2cba
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1
Binary files differ
diff --git a/tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182 b/tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182
new file mode 100644
index 000000000..98066029c
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182
Binary files differ
diff --git a/tests-clar/resources/filemodes/.gitted/refs/heads/master b/tests-clar/resources/filemodes/.gitted/refs/heads/master
new file mode 100644
index 000000000..9822d2d3f
--- /dev/null
+++ b/tests-clar/resources/filemodes/.gitted/refs/heads/master
@@ -0,0 +1 @@
+9962c8453ba6f0cf8dac7c5dcc2fa2897fa9964a
diff --git a/tests-clar/resources/filemodes/exec_off b/tests-clar/resources/filemodes/exec_off
new file mode 100644
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_off
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_off2on_staged b/tests-clar/resources/filemodes/exec_off2on_staged
new file mode 100755
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_off2on_staged
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_off2on_workdir b/tests-clar/resources/filemodes/exec_off2on_workdir
new file mode 100755
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_off2on_workdir
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_off_untracked b/tests-clar/resources/filemodes/exec_off_untracked
new file mode 100644
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_off_untracked
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_on b/tests-clar/resources/filemodes/exec_on
new file mode 100755
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_on
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_on2off_staged b/tests-clar/resources/filemodes/exec_on2off_staged
new file mode 100644
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_on2off_staged
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_on2off_workdir b/tests-clar/resources/filemodes/exec_on2off_workdir
new file mode 100644
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_on2off_workdir
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/filemodes/exec_on_untracked b/tests-clar/resources/filemodes/exec_on_untracked
new file mode 100755
index 000000000..a5c5dd0fc
--- /dev/null
+++ b/tests-clar/resources/filemodes/exec_on_untracked
@@ -0,0 +1 @@
+Howdy
diff --git a/tests-clar/resources/icase/.gitted/HEAD b/tests-clar/resources/icase/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/icase/.gitted/config b/tests-clar/resources/icase/.gitted/config
new file mode 100644
index 000000000..bb4d11c1f
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+ precomposeunicode = false
diff --git a/tests-clar/resources/icase/.gitted/description b/tests-clar/resources/icase/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/icase/.gitted/index b/tests-clar/resources/icase/.gitted/index
new file mode 100644
index 000000000..f8288ec13
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/info/exclude b/tests-clar/resources/icase/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/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-clar/resources/icase/.gitted/logs/HEAD b/tests-clar/resources/icase/.gitted/logs/HEAD
new file mode 100644
index 000000000..3b16bd163
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 76d6e1d231b1085fcce151427e9899335de74be6 Russell Belfer <rb@github.com> 1359157123 -0800 commit (initial): initial commit
diff --git a/tests-clar/resources/icase/.gitted/logs/refs/heads/master b/tests-clar/resources/icase/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..3b16bd163
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 76d6e1d231b1085fcce151427e9899335de74be6 Russell Belfer <rb@github.com> 1359157123 -0800 commit (initial): initial commit
diff --git a/tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdce b/tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdce
new file mode 100644
index 000000000..10691c788
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdce
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93 b/tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93
new file mode 100644
index 000000000..8ca70df17
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49 b/tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49
new file mode 100644
index 000000000..e264aeab3
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be6 b/tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be6
new file mode 100644
index 000000000..24a4b3ee3
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be6
@@ -0,0 +1,3 @@
+x•Û 1EýNÓ€’c² ‹X‚dƉÈÈ&ý°/çœËußsãñÔ›8±è}2î SH–‚,Ñ
+am1ЋEÅÑ·Úà9ŽCJ‡”$ nîïÜ·A®û
+ÆábÐëଃÖj®ó¯Oô_SåOî9ø%Ô)Œ9š \ No newline at end of file
diff --git a/tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6 b/tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6
new file mode 100644
index 000000000..32d8c499f
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/refs/heads/master b/tests-clar/resources/icase/.gitted/refs/heads/master
new file mode 100644
index 000000000..37410ec2a
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/refs/heads/master
@@ -0,0 +1 @@
+76d6e1d231b1085fcce151427e9899335de74be6
diff --git a/tests-clar/resources/icase/B b/tests-clar/resources/icase/B
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/B
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/D b/tests-clar/resources/icase/D
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/D
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/F b/tests-clar/resources/icase/F
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/F
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/H b/tests-clar/resources/icase/H
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/H
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/J b/tests-clar/resources/icase/J
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/J
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/L/1 b/tests-clar/resources/icase/L/1
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/1
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/B b/tests-clar/resources/icase/L/B
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/B
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/D b/tests-clar/resources/icase/L/D
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/D
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/a b/tests-clar/resources/icase/L/a
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/a
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/c b/tests-clar/resources/icase/L/c
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/c
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/a b/tests-clar/resources/icase/a
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/a
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/c b/tests-clar/resources/icase/c
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/c
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/e b/tests-clar/resources/icase/e
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/e
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/g b/tests-clar/resources/icase/g
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/g
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/i b/tests-clar/resources/icase/i
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/i
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/k/1 b/tests-clar/resources/icase/k/1
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/1
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/B b/tests-clar/resources/icase/k/B
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/B
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/D b/tests-clar/resources/icase/k/D
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/D
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/a b/tests-clar/resources/icase/k/a
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/a
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/c b/tests-clar/resources/icase/k/c
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/c
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/issue_1397/.gitted/HEAD b/tests-clar/resources/issue_1397/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/issue_1397/.gitted/config b/tests-clar/resources/issue_1397/.gitted/config
new file mode 100644
index 000000000..ba5bbde24
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ bare = false
+ repositoryformatversion = 0
+ filemode = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/issue_1397/.gitted/index b/tests-clar/resources/issue_1397/.gitted/index
new file mode 100644
index 000000000..fa0f541d6
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/issue_1397/.gitted/objects/7f/483a738f867e5b21c8f377d70311f011eb48b5 b/tests-clar/resources/issue_1397/.gitted/objects/7f/483a738f867e5b21c8f377d70311f011eb48b5
new file mode 100644
index 000000000..63bcb5d76
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/objects/7f/483a738f867e5b21c8f377d70311f011eb48b5
@@ -0,0 +1,3 @@
+xÎQNÃ0 €ažs
+¿£!'nâTBÓî°¸ŽC+Öe\Äv€ÿӯǾoÑËèfPƒ¦PL8FΆ‘ÒÌ%ª_Ä‹b4æIÜ—tk²°Uœ¸êLdeIÁòd<3/˜|0¥šjÈää1Ö£ÃõÛ\Gßô³c…wÛe»]ô~úùߊÁS
+)ÏGxEèôÿqØsµÓUÚ‡8šÁmkæ~yIæ \ No newline at end of file
diff --git a/tests-clar/resources/issue_1397/.gitted/objects/83/12e0889a9cbab77c732b6bc39b51a683e3a318 b/tests-clar/resources/issue_1397/.gitted/objects/83/12e0889a9cbab77c732b6bc39b51a683e3a318
new file mode 100644
index 000000000..06b59fede
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/objects/83/12e0889a9cbab77c732b6bc39b51a683e3a318
Binary files differ
diff --git a/tests-clar/resources/issue_1397/.gitted/objects/8a/7ef047fc933edb62e84e7977b0612ec3f6f283 b/tests-clar/resources/issue_1397/.gitted/objects/8a/7ef047fc933edb62e84e7977b0612ec3f6f283
new file mode 100644
index 000000000..19cfbeae2
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/objects/8a/7ef047fc933edb62e84e7977b0612ec3f6f283
Binary files differ
diff --git a/tests-clar/resources/issue_1397/.gitted/objects/8e/8f80088a9274fd23584992f587083ca1bcbbac b/tests-clar/resources/issue_1397/.gitted/objects/8e/8f80088a9274fd23584992f587083ca1bcbbac
new file mode 100644
index 000000000..f5c776b17
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/objects/8e/8f80088a9274fd23584992f587083ca1bcbbac
Binary files differ
diff --git a/tests-clar/resources/issue_1397/.gitted/objects/f2/c62dea0372a0578e053697d5c1ba1ac05e774a b/tests-clar/resources/issue_1397/.gitted/objects/f2/c62dea0372a0578e053697d5c1ba1ac05e774a
new file mode 100644
index 000000000..f932f3618
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/objects/f2/c62dea0372a0578e053697d5c1ba1ac05e774a
Binary files differ
diff --git a/tests-clar/resources/issue_1397/.gitted/objects/ff/3578d64d199d5b48d92bbb569e0a273e411741 b/tests-clar/resources/issue_1397/.gitted/objects/ff/3578d64d199d5b48d92bbb569e0a273e411741
new file mode 100644
index 000000000..fbd731727
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/objects/ff/3578d64d199d5b48d92bbb569e0a273e411741
Binary files differ
diff --git a/tests-clar/resources/issue_1397/.gitted/refs/heads/master b/tests-clar/resources/issue_1397/.gitted/refs/heads/master
new file mode 100644
index 000000000..285bc08ff
--- /dev/null
+++ b/tests-clar/resources/issue_1397/.gitted/refs/heads/master
@@ -0,0 +1 @@
+7f483a738f867e5b21c8f377d70311f011eb48b5
diff --git a/tests-clar/resources/issue_1397/crlf_file.txt b/tests-clar/resources/issue_1397/crlf_file.txt
new file mode 100644
index 000000000..8312e0889
--- /dev/null
+++ b/tests-clar/resources/issue_1397/crlf_file.txt
@@ -0,0 +1,3 @@
+first line
+second line
+both with crlf \ No newline at end of file
diff --git a/tests-clar/resources/issue_1397/some_other_crlf_file.txt b/tests-clar/resources/issue_1397/some_other_crlf_file.txt
new file mode 100644
index 000000000..8e8f80088
--- /dev/null
+++ b/tests-clar/resources/issue_1397/some_other_crlf_file.txt
@@ -0,0 +1,3 @@
+first line
+second line with some change
+both with crlf \ No newline at end of file
diff --git a/tests-clar/resources/issue_592/.gitted/index b/tests-clar/resources/issue_592/.gitted/index
index eaeb5d761..be7a29d99 100644
--- a/tests-clar/resources/issue_592/.gitted/index
+++ b/tests-clar/resources/issue_592/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/issue_592b/.gitted/hooks/post-update.sample b/tests-clar/resources/issue_592b/.gitted/hooks/post-update.sample
deleted file mode 100755
index ec17ec193..000000000
--- a/tests-clar/resources/issue_592b/.gitted/hooks/post-update.sample
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-#
-# An example hook script to prepare a packed repository for use over
-# dumb transports.
-#
-# To enable this hook, rename this file to "post-update".
-
-exec git update-server-info
diff --git a/tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG b/tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG
new file mode 100644
index 000000000..1f7391f92
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG
@@ -0,0 +1 @@
+master
diff --git a/tests-clar/resources/mergedrepo/.gitted/HEAD b/tests-clar/resources/mergedrepo/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD b/tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD
new file mode 100644
index 000000000..a5bdf6e40
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD
@@ -0,0 +1 @@
+e2809157a7766f272e4cfe26e61ef2678a5357ff
diff --git a/tests-clar/resources/mergedrepo/.gitted/MERGE_MODE b/tests-clar/resources/mergedrepo/.gitted/MERGE_MODE
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/MERGE_MODE
diff --git a/tests-clar/resources/mergedrepo/.gitted/MERGE_MSG b/tests-clar/resources/mergedrepo/.gitted/MERGE_MSG
new file mode 100644
index 000000000..7c4d1f5a9
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/MERGE_MSG
@@ -0,0 +1,5 @@
+Merge branch 'branch'
+
+Conflicts:
+ conflicts-one.txt
+ conflicts-two.txt
diff --git a/tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD b/tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD
new file mode 100644
index 000000000..13d4d6721
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD
@@ -0,0 +1 @@
+3a34580a35add43a4cf361e8e9a30060a905c876
diff --git a/tests-clar/resources/mergedrepo/.gitted/config b/tests-clar/resources/mergedrepo/.gitted/config
new file mode 100644
index 000000000..af107929f
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/mergedrepo/.gitted/description b/tests-clar/resources/mergedrepo/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/mergedrepo/.gitted/index b/tests-clar/resources/mergedrepo/.gitted/index
new file mode 100644
index 000000000..3d29f78e7
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/info/exclude b/tests-clar/resources/mergedrepo/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/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-clar/resources/mergedrepo/.gitted/logs/HEAD b/tests-clar/resources/mergedrepo/.gitted/logs/HEAD
new file mode 100644
index 000000000..a385da67b
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/logs/HEAD
@@ -0,0 +1,5 @@
+0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371828 -0500 commit (initial): initial
+9a05ccb4e0f948de03128e095f39dae6976751c5 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371835 -0500 checkout: moving from master to branch
+9a05ccb4e0f948de03128e095f39dae6976751c5 e2809157a7766f272e4cfe26e61ef2678a5357ff Edward Thomson <ethomson@edwardthomson.com> 1351371872 -0500 commit: branch
+e2809157a7766f272e4cfe26e61ef2678a5357ff 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371873 -0500 checkout: moving from branch to master
+9a05ccb4e0f948de03128e095f39dae6976751c5 3a34580a35add43a4cf361e8e9a30060a905c876 Edward Thomson <ethomson@edwardthomson.com> 1351372106 -0500 commit: master
diff --git a/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch
new file mode 100644
index 000000000..26a5e8dc5
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371835 -0500 branch: Created from HEAD
+9a05ccb4e0f948de03128e095f39dae6976751c5 e2809157a7766f272e4cfe26e61ef2678a5357ff Edward Thomson <ethomson@edwardthomson.com> 1351371872 -0500 commit: branch
diff --git a/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..425f7bd89
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371828 -0500 commit (initial): initial
+9a05ccb4e0f948de03128e095f39dae6976751c5 3a34580a35add43a4cf361e8e9a30060a905c876 Edward Thomson <ethomson@edwardthomson.com> 1351372106 -0500 commit: master
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712 b/tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712
new file mode 100644
index 000000000..9232f79d9
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91 b/tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91
new file mode 100644
index 000000000..3e124d9a4
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81 b/tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81
new file mode 100644
index 000000000..7bb19c873
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211e b/tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211e
new file mode 100644
index 000000000..487bcffb1
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211e
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6 b/tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6
new file mode 100644
index 000000000..2eb3954fc
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534 b/tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534
new file mode 100644
index 000000000..ebe83ccb2
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c876 b/tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c876
new file mode 100644
index 000000000..0d4095ffc
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c876
@@ -0,0 +1,2 @@
+x¥ŽK
+1D]ç}¥óíDÜx/Oã"F2¯ooà®ê<*·Zo”‘»Ñ™uI²h²hrÄlÊÊ"r YùT8¢'©Ä#v¾mÎÉ0.Áø¨¥òŒÁ.:”È.#+³ñ9ÖÖáR^±¸®­níGžô“Îü~í[=ÔVjRìÑ"ŠIçÙÁjDÛ”ˆ7|N` \ No newline at end of file
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8c b/tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8c
new file mode 100644
index 000000000..33389c302
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8c
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3 b/tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3
new file mode 100644
index 000000000..5361ea685
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52da b/tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52da
new file mode 100644
index 000000000..a60da877c
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52da
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46ad b/tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46ad
new file mode 100644
index 000000000..85e84d71e
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46ad
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399 b/tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399
new file mode 100644
index 000000000..b16b521e6
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8 b/tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8
new file mode 100644
index 000000000..7c4e85ffb
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4 b/tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4
new file mode 100644
index 000000000..65173fc4d
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71 b/tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71
new file mode 100644
index 000000000..162fa4455
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038c b/tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038c
new file mode 100644
index 000000000..77a519f55
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038c
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cda b/tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cda
new file mode 100644
index 000000000..f624cd4f1
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cda
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673 b/tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673
new file mode 100644
index 000000000..096474c03
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735a b/tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735a
new file mode 100644
index 000000000..a413bc6b0
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735a
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2 b/tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2
new file mode 100644
index 000000000..3ac8f6018
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8 b/tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8
new file mode 100644
index 000000000..589a5ae9b
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9 b/tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9
new file mode 100644
index 000000000..6503985e3
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50 b/tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50
new file mode 100644
index 000000000..2eaa80838
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5 b/tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5
new file mode 100644
index 000000000..7373a80d8
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5
@@ -0,0 +1 @@
+x¥Ñ !Dý¦Šm@³Ë ÉÅøc6Àq#‘#AŒí‹Æü›y/™ µ”Üœ:ô#$–l•tH:é—„*D³XÖh¬VœáŸ}« ®ëË·n[-ºÃý¤KüŠ_;…ZÎ@“¦‰ÉJ GÔˆbÐqÞãŸ3"ï¹goŒ«@I \ No newline at end of file
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092c b/tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092c
new file mode 100644
index 000000000..c5a651f97
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092c
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0d b/tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0d
new file mode 100644
index 000000000..3e14b5dc8
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0d
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51 b/tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51
new file mode 100644
index 000000000..a641adc2e
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff b/tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff
new file mode 100644
index 000000000..fa86662e0
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff
@@ -0,0 +1,3 @@
+x¥ŽK
+1D]ç¹€Òùt> âÆxžN‡q1‰¯ï(ÞÀ]Õ{P·e¹ m½Ù.¢S­Ì0[Dc’õd­
+Å…ˆbM‰Ôº¬Cgdž¼@Í>glÈX].$!ÇÑ0*zŽ¹u})/êE_ç¶<Úª²ÑO:ËWüÚÛrÒÆ¡qѤhõ@mt;;äÏ5uZyVoÓ\Mÿ \ No newline at end of file
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478 b/tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478
new file mode 100644
index 000000000..c9841c698
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406 b/tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406
new file mode 100644
index 000000000..cd587dbec
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406
Binary files differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/refs/heads/branch b/tests-clar/resources/mergedrepo/.gitted/refs/heads/branch
new file mode 100644
index 000000000..a5bdf6e40
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/refs/heads/branch
@@ -0,0 +1 @@
+e2809157a7766f272e4cfe26e61ef2678a5357ff
diff --git a/tests-clar/resources/mergedrepo/.gitted/refs/heads/master b/tests-clar/resources/mergedrepo/.gitted/refs/heads/master
new file mode 100644
index 000000000..13d4d6721
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/refs/heads/master
@@ -0,0 +1 @@
+3a34580a35add43a4cf361e8e9a30060a905c876
diff --git a/tests-clar/resources/mergedrepo/conflicts-one.txt b/tests-clar/resources/mergedrepo/conflicts-one.txt
new file mode 100644
index 000000000..8aad34cc8
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/conflicts-one.txt
@@ -0,0 +1,5 @@
+<<<<<<< HEAD
+This is most certainly a conflict!
+=======
+This is a conflict!!!
+>>>>>>> branch
diff --git a/tests-clar/resources/mergedrepo/conflicts-two.txt b/tests-clar/resources/mergedrepo/conflicts-two.txt
new file mode 100644
index 000000000..e62cac5c8
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/conflicts-two.txt
@@ -0,0 +1,5 @@
+<<<<<<< HEAD
+This is without question another conflict!
+=======
+This is another conflict!!!
+>>>>>>> branch
diff --git a/tests-clar/resources/mergedrepo/one.txt b/tests-clar/resources/mergedrepo/one.txt
new file mode 100644
index 000000000..75938de1e
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/one.txt
@@ -0,0 +1,10 @@
+This is file one!
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one!
diff --git a/tests-clar/resources/mergedrepo/two.txt b/tests-clar/resources/mergedrepo/two.txt
new file mode 100644
index 000000000..7b26923aa
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/two.txt
@@ -0,0 +1,12 @@
+This is file two!
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two!
diff --git a/tests-clar/resources/partial-testrepo/.gitted/HEAD b/tests-clar/resources/partial-testrepo/.gitted/HEAD
new file mode 100644
index 000000000..4bfb9c93f
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/dir
diff --git a/tests-clar/resources/partial-testrepo/.gitted/config b/tests-clar/resources/partial-testrepo/.gitted/config
new file mode 100644
index 000000000..99abaab97
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[branch "dir"]
diff --git a/tests-clar/resources/partial-testrepo/.gitted/index b/tests-clar/resources/partial-testrepo/.gitted/index
new file mode 100644
index 000000000..4f241f914
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 b/tests-clar/resources/partial-testrepo/.gitted/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
new file mode 100644
index 000000000..cedb2a22e
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e b/tests-clar/resources/partial-testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e
new file mode 100644
index 000000000..b7d944fa1
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925 b/tests-clar/resources/partial-testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925
new file mode 100644
index 000000000..d37b93e4f
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 b/tests-clar/resources/partial-testrepo/.gitted/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
new file mode 100644
index 000000000..93a16f146
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/18/10dff58d8a660512d4832e740f692884338ccd b/tests-clar/resources/partial-testrepo/.gitted/objects/18/10dff58d8a660512d4832e740f692884338ccd
new file mode 100644
index 000000000..ba0bfb30c
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/18/10dff58d8a660512d4832e740f692884338ccd
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/tests-clar/resources/partial-testrepo/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
new file mode 100644
index 000000000..7ca4ceed5
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 b/tests-clar/resources/partial-testrepo/.gitted/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
new file mode 100644
index 000000000..8953b6cef
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
@@ -0,0 +1,2 @@
+xŽQ
+Â0DýÎ)öÊ6›Í¦ "xO°‰‰-ØFb¼¿EoàÏ0 ¼Ç¤º,ske×[ÎPn8R,EpD?±gŸ}Ê^3² âÙ<µåµGŽhYKÄèÒ8ЖDAÉ)¿ÉÈ;gôݧÚàšjïp™4ÕŽ¯ô-çû¢óãêr‚ÁŠ;°s°GA4Ûº=ìùÖ(ôin7øIÌKÍFE \ No newline at end of file
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63 b/tests-clar/resources/partial-testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63
new file mode 100644
index 000000000..e9150214b
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 b/tests-clar/resources/partial-testrepo/.gitted/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
new file mode 100644
index 000000000..c1f22c54f
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
@@ -0,0 +1,2 @@
+xŽÛ 1EýNi@™Ék2 "X‚$ÙYW0YcÿíÀ¿Ã…s¸¥ÕzïÚÚõMDÏ€0æœ8!¶†ÉÌÞs‰ XŠªgÚdí::@X0»P¢wÙ"F/‰‰œÍRàˆUz÷¥múZZïú²¤ÒV}|•/œo5݇ÒêI£!¬1z Æ:vùÇUim}ê/¢>
+öF- \ No newline at end of file
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc b/tests-clar/resources/partial-testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc
new file mode 100644
index 000000000..b669961d8
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735 b/tests-clar/resources/partial-testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735
new file mode 100644
index 000000000..9ff5eb2b5
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a b/tests-clar/resources/partial-testrepo/.gitted/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
new file mode 100644
index 000000000..2ef4faa0f
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/81/4889a078c031f61ed08ab5fa863aea9314344d b/tests-clar/resources/partial-testrepo/.gitted/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
new file mode 100644
index 000000000..2f9b6b6e3
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/84/96071c1b46c854b31185ea97743be6a8774479 b/tests-clar/resources/partial-testrepo/.gitted/objects/84/96071c1b46c854b31185ea97743be6a8774479
new file mode 100644
index 000000000..5df58dda5
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/84/96071c1b46c854b31185ea97743be6a8774479
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a b/tests-clar/resources/partial-testrepo/.gitted/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
new file mode 100644
index 000000000..a79612435
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
@@ -0,0 +1,3 @@
+xŽ[
+Â0EýÎ*fÊäÕ¤ "¸W0“‡-ØFâtÿÝ—çpS[–YÀ˜x^
+Díb CLhutɉ}¥8X*4Zí¬sY½¨—UÀ‘AÃÖ ÌX3‡R«Mµ¶) s6è¼¢M¦ÖážšÜ&Jm…ó;}Çõ±Ðü<¥¶\@›à‚ÑÞpÄ€¨vº?”ò«jÛºLð«¨Ø?Hå \ No newline at end of file
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f b/tests-clar/resources/partial-testrepo/.gitted/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
new file mode 100644
index 000000000..f8588696b
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
@@ -0,0 +1,2 @@
+x;j1DëmdÓú·À˜ÇŽ|M«µ3`ŒV{ >€³âQ¯ ¸·vL0I?Í!š4–Z=Ê! ×¦8²F¢Ã’!rÖsQßyÈ9]$DŽ&„l6AÇ>jFWüÒµ IKNiûë§Z¢%¡SˆŒ‘
+‹Ò ­ÅʉøU~̽øä>'¼ï™û ¯wþ ×[ËÇ× ÷öÚDGÚ¡±ðŒQ-ºMù«>dܶ‘OÞáÒò}í\à8g_ШÂoYr \ No newline at end of file
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd b/tests-clar/resources/partial-testrepo/.gitted/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
new file mode 100644
index 000000000..d0d7e736e
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 b/tests-clar/resources/partial-testrepo/.gitted/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
new file mode 100644
index 000000000..18a7f61c2
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd b/tests-clar/resources/partial-testrepo/.gitted/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
new file mode 100644
index 000000000..75f541f10
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
@@ -0,0 +1,3 @@
+xŽQ
+Â0DýÎ)öʦ»I<‚'ØlR+˜Fj¼¿EoàÏ0<xÃh«õÞa Üõµ]È™­åXUlÞPF)Åz‘4yó”µ,\r 'SÂÄ-mI4
+‘Xhô”&òÌFÞ}n+\µõ—Y´-p|é·œoUz;-‘aÑlt{ØË?®I«,:ÃoÚR̳cHK \ No newline at end of file
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9 b/tests-clar/resources/partial-testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9
new file mode 100644
index 000000000..7620c514f
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83 b/tests-clar/resources/partial-testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83
new file mode 100644
index 000000000..00940f0f2
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 b/tests-clar/resources/partial-testrepo/.gitted/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
new file mode 100644
index 000000000..03770969a
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/fa/49b077972391ad58037050f2a75f74e3671e92 b/tests-clar/resources/partial-testrepo/.gitted/objects/fa/49b077972391ad58037050f2a75f74e3671e92
new file mode 100644
index 000000000..112998d42
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/fa/49b077972391ad58037050f2a75f74e3671e92
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/fd/093bff70906175335656e6ce6ae05783708765 b/tests-clar/resources/partial-testrepo/.gitted/objects/fd/093bff70906175335656e6ce6ae05783708765
new file mode 100644
index 000000000..12bf5f3e3
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/fd/093bff70906175335656e6ce6ae05783708765
Binary files differ
diff --git a/tests-clar/resources/partial-testrepo/.gitted/objects/pack/.gitkeep b/tests-clar/resources/partial-testrepo/.gitted/objects/pack/.gitkeep
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/objects/pack/.gitkeep
diff --git a/tests-clar/resources/partial-testrepo/.gitted/refs/heads/dir b/tests-clar/resources/partial-testrepo/.gitted/refs/heads/dir
new file mode 100644
index 000000000..4567d37fa
--- /dev/null
+++ b/tests-clar/resources/partial-testrepo/.gitted/refs/heads/dir
@@ -0,0 +1 @@
+144344043ba4d4a405da03de3844aa829ae8be0e
diff --git a/tests-clar/resources/push.sh b/tests-clar/resources/push.sh
new file mode 100644
index 000000000..607117675
--- /dev/null
+++ b/tests-clar/resources/push.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+#creates push_src repo for libgit2 push tests.
+set -eu
+
+#Create src repo for push
+mkdir push_src
+pushd push_src
+ git init
+
+ echo a > a.txt
+ git add .
+ git commit -m 'added a.txt'
+
+ mkdir fold
+ echo b > fold/b.txt
+ git add .
+ git commit -m 'added fold and fold/b.txt'
+
+ git branch b1 #b1 and b2 are the same
+ git branch b2
+
+ git checkout -b b3
+ echo edit >> a.txt
+ git add .
+ git commit -m 'edited a.txt'
+
+ git checkout -b b4 master
+ echo edit >> fold\b.txt
+ git add .
+ git commit -m 'edited fold\b.txt'
+
+ git checkout -b b5 master
+ git submodule add ../testrepo.git submodule
+ git commit -m "added submodule named 'submodule' pointing to '../testrepo.git'"
+
+ git checkout master
+ git merge -m "merge b3, b4, and b5 to master" b3 b4 b5
+
+ #Log commits to include in testcase
+ git log --format=oneline --decorate --graph
+ #*-. 951bbbb90e2259a4c8950db78946784fb53fcbce (HEAD, master) merge b3, b4, and b5 to master
+ #|\ \
+ #| | * fa38b91f199934685819bea316186d8b008c52a2 (b5) added submodule named 'submodule' pointing to '../testrepo.git'
+ #| * | 27b7ce66243eb1403862d05f958c002312df173d (b4) edited fold\b.txt
+ #| |/
+ #* | d9b63a88223d8367516f50bd131a5f7349b7f3e4 (b3) edited a.txt
+ #|/
+ #* a78705c3b2725f931d3ee05348d83cc26700f247 (b2, b1) added fold and fold/b.txt
+ #* 5c0bb3d1b9449d1cc69d7519fd05166f01840915 added a.txt
+
+ #fix paths so that we can add repo folders under libgit2 repo
+ #rename .git to .gitted
+ find . -name .git -exec mv -i '{}' '{}ted' \;
+ mv -i .gitmodules gitmodules
+popd
diff --git a/tests-clar/resources/push_src/.gitted/COMMIT_EDITMSG b/tests-clar/resources/push_src/.gitted/COMMIT_EDITMSG
new file mode 100644
index 000000000..b1295084c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/COMMIT_EDITMSG
@@ -0,0 +1 @@
+added submodule named 'submodule' pointing to '../testrepo.git'
diff --git a/tests-clar/resources/push_src/.gitted/HEAD b/tests-clar/resources/push_src/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/push_src/.gitted/ORIG_HEAD b/tests-clar/resources/push_src/.gitted/ORIG_HEAD
new file mode 100644
index 000000000..afadf9d26
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/ORIG_HEAD
@@ -0,0 +1 @@
+a78705c3b2725f931d3ee05348d83cc26700f247
diff --git a/tests-clar/resources/push_src/.gitted/config b/tests-clar/resources/push_src/.gitted/config
new file mode 100644
index 000000000..51de0311b
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/config
@@ -0,0 +1,10 @@
+[core]
+ repositoryformatversion = 0
+ filemode = false
+ bare = false
+ logallrefupdates = true
+ symlinks = false
+ ignorecase = true
+ hideDotFiles = dotGitOnly
+[submodule "submodule"]
+ url = m:/dd/libgit2/tests-clar/resources/testrepo.git
diff --git a/tests-clar/resources/push_src/.gitted/description b/tests-clar/resources/push_src/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/push_src/.gitted/index b/tests-clar/resources/push_src/.gitted/index
new file mode 100644
index 000000000..0ef6594b3
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/info/exclude b/tests-clar/resources/push_src/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/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-clar/resources/push_src/.gitted/logs/HEAD b/tests-clar/resources/push_src/.gitted/logs/HEAD
new file mode 100644
index 000000000..4ef336f84
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/HEAD
@@ -0,0 +1,10 @@
+0000000000000000000000000000000000000000 5c0bb3d1b9449d1cc69d7519fd05166f01840915 Congyi Wu <congyiwu@gmail.com> 1352923200 -0500 commit (initial): added a.txt
+5c0bb3d1b9449d1cc69d7519fd05166f01840915 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923200 -0500 commit: added fold and fold/b.txt
+a78705c3b2725f931d3ee05348d83cc26700f247 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 checkout: moving from master to b3
+a78705c3b2725f931d3ee05348d83cc26700f247 d9b63a88223d8367516f50bd131a5f7349b7f3e4 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 commit: edited a.txt
+d9b63a88223d8367516f50bd131a5f7349b7f3e4 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 checkout: moving from b3 to b4
+a78705c3b2725f931d3ee05348d83cc26700f247 27b7ce66243eb1403862d05f958c002312df173d Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 commit: edited fold\b.txt
+27b7ce66243eb1403862d05f958c002312df173d a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 checkout: moving from b4 to b5
+a78705c3b2725f931d3ee05348d83cc26700f247 fa38b91f199934685819bea316186d8b008c52a2 Congyi Wu <congyiwu@gmail.com> 1352923206 -0500 commit: added submodule named 'submodule' pointing to '../testrepo.git'
+fa38b91f199934685819bea316186d8b008c52a2 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923207 -0500 checkout: moving from b5 to master
+a78705c3b2725f931d3ee05348d83cc26700f247 951bbbb90e2259a4c8950db78946784fb53fcbce Congyi Wu <congyiwu@gmail.com> 1352923207 -0500 merge b3 b4 b5: Merge made by the 'octopus' strategy.
diff --git a/tests-clar/resources/push_src/.gitted/logs/refs/heads/b1 b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b1
new file mode 100644
index 000000000..390a03d5c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b1
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923200 -0500 branch: Created from master
diff --git a/tests-clar/resources/push_src/.gitted/logs/refs/heads/b2 b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b2
new file mode 100644
index 000000000..390a03d5c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b2
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923200 -0500 branch: Created from master
diff --git a/tests-clar/resources/push_src/.gitted/logs/refs/heads/b3 b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b3
new file mode 100644
index 000000000..01e302c44
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b3
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 branch: Created from HEAD
+a78705c3b2725f931d3ee05348d83cc26700f247 d9b63a88223d8367516f50bd131a5f7349b7f3e4 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 commit: edited a.txt
diff --git a/tests-clar/resources/push_src/.gitted/logs/refs/heads/b4 b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b4
new file mode 100644
index 000000000..7afddc54e
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b4
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 branch: Created from master
+a78705c3b2725f931d3ee05348d83cc26700f247 27b7ce66243eb1403862d05f958c002312df173d Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 commit: edited fold\b.txt
diff --git a/tests-clar/resources/push_src/.gitted/logs/refs/heads/b5 b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b5
new file mode 100644
index 000000000..bc22567f7
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/refs/heads/b5
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923201 -0500 branch: Created from master
+a78705c3b2725f931d3ee05348d83cc26700f247 fa38b91f199934685819bea316186d8b008c52a2 Congyi Wu <congyiwu@gmail.com> 1352923206 -0500 commit: added submodule named 'submodule' pointing to '../testrepo.git'
diff --git a/tests-clar/resources/push_src/.gitted/logs/refs/heads/master b/tests-clar/resources/push_src/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..8aafa9ca4
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/logs/refs/heads/master
@@ -0,0 +1,3 @@
+0000000000000000000000000000000000000000 5c0bb3d1b9449d1cc69d7519fd05166f01840915 Congyi Wu <congyiwu@gmail.com> 1352923200 -0500 commit (initial): added a.txt
+5c0bb3d1b9449d1cc69d7519fd05166f01840915 a78705c3b2725f931d3ee05348d83cc26700f247 Congyi Wu <congyiwu@gmail.com> 1352923200 -0500 commit: added fold and fold/b.txt
+a78705c3b2725f931d3ee05348d83cc26700f247 951bbbb90e2259a4c8950db78946784fb53fcbce Congyi Wu <congyiwu@gmail.com> 1352923207 -0500 merge b3 b4 b5: Merge made by the 'octopus' strategy.
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/HEAD b/tests-clar/resources/push_src/.gitted/modules/submodule/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/config b/tests-clar/resources/push_src/.gitted/modules/submodule/config
new file mode 100644
index 000000000..59810077d
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/config
@@ -0,0 +1,15 @@
+[core]
+ repositoryformatversion = 0
+ filemode = false
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../submodule
+ symlinks = false
+ ignorecase = true
+ hideDotFiles = dotGitOnly
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = m:/dd/libgit2/tests-clar/resources/testrepo.git
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/description b/tests-clar/resources/push_src/.gitted/modules/submodule/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/index b/tests-clar/resources/push_src/.gitted/modules/submodule/index
new file mode 100644
index 000000000..8e44080f3
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/index
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/info/exclude b/tests-clar/resources/push_src/.gitted/modules/submodule/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/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-clar/resources/push_src/.gitted/modules/submodule/logs/HEAD b/tests-clar/resources/push_src/.gitted/modules/submodule/logs/HEAD
new file mode 100644
index 000000000..aedcdf295
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Congyi Wu <congyiwu@gmail.com> 1352923205 -0500 clone: from m:/dd/libgit2/tests-clar/resources/testrepo.git
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/heads/master b/tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/heads/master
new file mode 100644
index 000000000..aedcdf295
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Congyi Wu <congyiwu@gmail.com> 1352923205 -0500 clone: from m:/dd/libgit2/tests-clar/resources/testrepo.git
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/remotes/origin/HEAD b/tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..aedcdf295
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Congyi Wu <congyiwu@gmail.com> 1352923205 -0500 clone: from m:/dd/libgit2/tests-clar/resources/testrepo.git
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/08/b041783f40edfe12bb406c9c9a8a040177c125 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/08/b041783f40edfe12bb406c9c9a8a040177c125
new file mode 100644
index 000000000..d1c032fce
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/08/b041783f40edfe12bb406c9c9a8a040177c125
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
new file mode 100644
index 000000000..cedb2a22e
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
new file mode 100644
index 000000000..93a16f146
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/10dff58d8a660512d4832e740f692884338ccd b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/10dff58d8a660512d4832e740f692884338ccd
new file mode 100644
index 000000000..ba0bfb30c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/18/10dff58d8a660512d4832e740f692884338ccd
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd
new file mode 100644
index 000000000..3ec541288
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1b/8cbad43e867676df601306689fe7c3def5e689 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1b/8cbad43e867676df601306689fe7c3def5e689
new file mode 100644
index 000000000..6048d4bad
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1b/8cbad43e867676df601306689fe7c3def5e689
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1f/67fc4386b2d171e0d21be1c447e12660561f9b b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1f/67fc4386b2d171e0d21be1c447e12660561f9b
new file mode 100644
index 000000000..225c45734
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/1f/67fc4386b2d171e0d21be1c447e12660561f9b
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10
new file mode 100644
index 000000000..cb1ed5712
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/27/0b8ea76056d5cad83af921837702d3e3c2924d b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/27/0b8ea76056d5cad83af921837702d3e3c2924d
new file mode 100644
index 000000000..df40d99af
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/27/0b8ea76056d5cad83af921837702d3e3c2924d
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7
new file mode 100644
index 000000000..0a1500a6f
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/32/59a6bd5b57fb9c1281bb7ed3167b50f224cb54 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/32/59a6bd5b57fb9c1281bb7ed3167b50f224cb54
new file mode 100644
index 000000000..321eaa867
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/32/59a6bd5b57fb9c1281bb7ed3167b50f224cb54
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022cc b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022cc
new file mode 100644
index 000000000..9bb5b623b
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022cc
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
new file mode 100644
index 000000000..7ca4ceed5
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
new file mode 100644
index 000000000..8953b6cef
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
@@ -0,0 +1,2 @@
+xŽQ
+Â0DýÎ)öÊ6›Í¦ "xO°‰‰-ØFb¼¿EoàÏ0 ¼Ç¤º,ske×[ÎPn8R,EpD?±gŸ}Ê^3² âÙ<µåµGŽhYKÄèÒ8ЖDAÉ)¿ÉÈ;gôݧÚàšjïp™4ÕŽ¯ô-çû¢óãêr‚ÁŠ;°s°GA4Ûº=ìùÖ(ôin7øIÌKÍFE \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/4b/22b35d44b5a4f589edf3dc89196399771796ea b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/4b/22b35d44b5a4f589edf3dc89196399771796ea
new file mode 100644
index 000000000..b4e5aa186
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/4b/22b35d44b5a4f589edf3dc89196399771796ea
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/52/1d87c1ec3aef9824daf6d96cc0ae3710766d91 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/52/1d87c1ec3aef9824daf6d96cc0ae3710766d91
new file mode 100644
index 000000000..351cff823
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/52/1d87c1ec3aef9824daf6d96cc0ae3710766d91
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
new file mode 100644
index 000000000..c1f22c54f
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
@@ -0,0 +1,2 @@
+xŽÛ 1EýNi@™Ék2 "X‚$ÙYW0YcÿíÀ¿Ã…s¸¥ÕzïÚÚõMDÏ€0æœ8!¶†ÉÌÞs‰ XŠªgÚdí::@X0»P¢wÙ"F/‰‰œÍRàˆUz÷¥múZZïú²¤ÒV}|•/œo5݇ÒêI£!¬1z Æ:vùÇUim}ê/¢>
+öF- \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
new file mode 100644
index 000000000..2ef4faa0f
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/76/3d71aadf09a7951596c9746c024e7eece7c7af b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/76/3d71aadf09a7951596c9746c024e7eece7c7af
new file mode 100644
index 000000000..716b0c64b
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/76/3d71aadf09a7951596c9746c024e7eece7c7af
@@ -0,0 +1 @@
+xŽAj!³ö?0¨£ßÂ09Êo}HÚ6¨}ÿôjUPP©ÕZ&Yÿø˜ AÔ›±€pŒÁFdë¼÷pz[fŽYŒ½PÒqLJ.,Z§`™Å®Ð.ù`’vÙ ³q $Æ5+9çOëtœû>Û/úDE/龡W¯ï*e¿§VŸdf1>ð覭Öê²×äÄ›¹úÊ™F« ­ìTŽÙhœk.i¶^0Ô?P¼R, \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/7b/4384978d2493e851f9cca7858815fac9b10980 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/7b/4384978d2493e851f9cca7858815fac9b10980
new file mode 100644
index 000000000..23c462f34
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/7b/4384978d2493e851f9cca7858815fac9b10980
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/81/4889a078c031f61ed08ab5fa863aea9314344d b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
new file mode 100644
index 000000000..2f9b6b6e3
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/96071c1b46c854b31185ea97743be6a8774479 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/96071c1b46c854b31185ea97743be6a8774479
new file mode 100644
index 000000000..5df58dda5
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/96071c1b46c854b31185ea97743be6a8774479
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe
new file mode 100644
index 000000000..71019a636
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe
@@ -0,0 +1,2 @@
+xŒM F]sŠ¹€†Ÿ41ÆxÝ(­I‹ÁéÂÛKݽ/_ÞãP@¡ÚÕø¢!8›)es
+” ¥N&FGSÆ„¹hÑ{+ßCç‰÷ÆZzvØF¡7ZàÎ-¬Îñó‡k™x\ã¡[PÆ8ï´ôGØK/¥^© lÊ>.4 \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162
new file mode 100644
index 000000000..4cc3f4dff
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162
@@ -0,0 +1 @@
+x+)JMU044b040031QrutñueX¡l¨ðmmA‹m›Ì£íJ}Gß;U‘T”˜—œŸ–™“ªWRQÂ`6ýš÷KÇ¥¶^/¾-*|òøWØ¥3P¥y©å`%ËEÛÞ±\&gŽÐ|Ÿ0§ÿ†{Ó1X \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9a/03079b8a8ee85a0bee58bf9be3da8b62414ed4 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9a/03079b8a8ee85a0bee58bf9be3da8b62414ed4
new file mode 100644
index 000000000..bf7b2bb68
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9a/03079b8a8ee85a0bee58bf9be3da8b62414ed4
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2
new file mode 100644
index 000000000..7f1cfb23c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2
@@ -0,0 +1,2 @@
+xŽM
+Â0F]ç³d2¤ñ®<A~&´`­ÄôþVàæãmïËë²ÌÈÒ¡7Uà$äJöL9yM!¢GuœªH¤&UÈæ›>;ÔÂÁ…¬£³X†ÂEÈŽ5R±£ ÛAÑE &n}ZÜæ<E}À=O[ÒÖáüÞéúÓ¼^À,ã^†#¢É¿ƒ]ÿPÍ`>™A¹ \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
new file mode 100644
index 000000000..a79612435
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
@@ -0,0 +1,3 @@
+xŽ[
+Â0EýÎ*fÊäÕ¤ "¸W0“‡-ØFâtÿÝ—çpS[–YÀ˜x^
+Díb CLhutɉ}¥8X*4Zí¬sY½¨—UÀ‘AÃÖ ÌX3‡R«Mµ¶) s6è¼¢M¦ÖážšÜ&Jm…ó;}Çõ±Ðü<¥¶\@›à‚ÑÞpÄ€¨vº?”ò«jÛºLð«¨Ø?Hå \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
new file mode 100644
index 000000000..f8588696b
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
@@ -0,0 +1,2 @@
+x;j1DëmdÓú·À˜ÇŽ|M«µ3`ŒV{ >€³âQ¯ ¸·vL0I?Í!š4–Z=Ê! ×¦8²F¢Ã’!rÖsQßyÈ9]$DŽ&„l6AÇ>jFWüÒµ IKNiûë§Z¢%¡SˆŒ‘
+‹Ò ­ÅʉøU~̽øä>'¼ï™û ¯wþ ×[ËÇ× ÷öÚDGÚ¡±ðŒQ-ºMù«>dܶ‘OÞáÒò}í\à8g_ШÂoYr \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750
new file mode 100644
index 000000000..29c8e824d
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750
@@ -0,0 +1,3 @@
+xŽQ
+!@ûösBQ"‚ŽÐ ÆÙ± rÍîßÒú{<xð¤·öàîƪ
+™HlJSer!ZPTe*Žj°UÝÑEo^¼ê2 (†ˆ¬XSÅ€ED‘ƒO<Y¦šj$2üs_á&} ¸Î,}Ó[~p¹7~<ÒÛ:Ÿ £°·ÉZ³Ùípè?­1_ûåC0 \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
new file mode 100644
index 000000000..d0d7e736e
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
new file mode 100644
index 000000000..18a7f61c2
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/ae/90f12eea699729ed24555e40b9fd669da12a12 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/ae/90f12eea699729ed24555e40b9fd669da12a12
new file mode 100644
index 000000000..d95254674
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/ae/90f12eea699729ed24555e40b9fd669da12a12
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1
new file mode 100644
index 000000000..f460f2547
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1
@@ -0,0 +1,2 @@
+xÌA
+Â0…a×9ÅìIÒ ™€ˆp'î§1Ѷ‘v\x{cáýðVŸpƒvWûgŠ¾ÇŽ0xº[ ]"g†#{rDÆ Cot ­äûN œU $­ò?9-p+1Í^¤ÀQx®¯Ï9O\ÆC¬Ó Œm'D {mµVêú(+´ñælè¶,Þ \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/b6/361fc6a97178d8fc8639fdeed71c775ab52593 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/b6/361fc6a97178d8fc8639fdeed71c775ab52593
new file mode 100644
index 000000000..f613670e2
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/b6/361fc6a97178d8fc8639fdeed71c775ab52593
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
new file mode 100644
index 000000000..0817229bc
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
@@ -0,0 +1,3 @@
+xKj1D³Ö)zçUBëÛ-0ÁuV9¦Õò<#£È÷ÏȲ+ŠW<Jú¶Ý&8Ê/s¨‚e‹µµÈ•KJ­«½S
+ØRvÌÁ{©æQ†îr«äY¹QN$H\Eµ²Íè=6áX5¦òÇK Fr)·(‰dC‡Î†”­–œ—jÊs®}À—ô9ác-Òw8Ëo¸\·r»¿IßÞÁ:
+l}F‚W$Ds´Ç£©ÿÙšOW…e”]V8-ÃÌÈ"U \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
new file mode 100644
index 000000000..75f541f10
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
@@ -0,0 +1,3 @@
+xŽQ
+Â0DýÎ)öʦ»I<‚'ØlR+˜Fj¼¿EoàÏ0<xÃh«õÞa Üõµ]È™­åXUlÞPF)Åz‘4yó”µ,\r 'SÂÄ-mI4
+‘Xhô”&òÌFÞ}n+\µõ—Y´-p|é·œoUz;-‘aÑlt{ØË?®I«,:ÃoÚR̳cHK \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659
new file mode 100644
index 000000000..f3b46b3ca
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d6/c93164c249c8000205dd4ec5cbca1b516d487f b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d6/c93164c249c8000205dd4ec5cbca1b516d487f
new file mode 100644
index 000000000..a67d6e647
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d6/c93164c249c8000205dd4ec5cbca1b516d487f
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759
new file mode 100644
index 000000000..2d47e6faf
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 000000000..711223894
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/e7/b4ad382349ff96dd8199000580b9b1e2042eb0 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/e7/b4ad382349ff96dd8199000580b9b1e2042eb0
new file mode 100644
index 000000000..b135eccda
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/e7/b4ad382349ff96dd8199000580b9b1e2042eb0
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/f1/425cef211cc08caa31e7b545ffb232acb098c3 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/f1/425cef211cc08caa31e7b545ffb232acb098c3
new file mode 100644
index 000000000..82e2790e8
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/f1/425cef211cc08caa31e7b545ffb232acb098c3
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
new file mode 100644
index 000000000..697c94c92
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fa/49b077972391ad58037050f2a75f74e3671e92 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fa/49b077972391ad58037050f2a75f74e3671e92
new file mode 100644
index 000000000..112998d42
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fa/49b077972391ad58037050f2a75f74e3671e92
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/093bff70906175335656e6ce6ae05783708765 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/093bff70906175335656e6ce6ae05783708765
new file mode 100644
index 000000000..12bf5f3e3
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/093bff70906175335656e6ce6ae05783708765
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09 b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09
new file mode 100644
index 000000000..158aef21f
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx
new file mode 100644
index 000000000..5068f2818
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack
new file mode 100644
index 000000000..a6a1f3020
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx
new file mode 100644
index 000000000..94c3c71da
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack
new file mode 100644
index 000000000..74c7fe4f3
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx
new file mode 100644
index 000000000..555cfa977
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack
new file mode 100644
index 000000000..4d539ed0a
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/packed-refs b/tests-clar/resources/push_src/.gitted/modules/submodule/packed-refs
new file mode 100644
index 000000000..506a8607c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/packed-refs
@@ -0,0 +1,24 @@
+# pack-refs with: peeled
+a4a7dce85cf63874e984719f4fdd239f5145052f refs/remotes/origin/br2
+a4a7dce85cf63874e984719f4fdd239f5145052f refs/remotes/origin/cannot-fetch
+e90810b8df3e80c413d903f631643c716887138d refs/remotes/origin/chomped
+258f0e2a959a364e40ed6603d5d44fbb24765b10 refs/remotes/origin/haacked
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750 refs/remotes/origin/master
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750 refs/remotes/origin/not-good
+41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/remotes/origin/packed
+4a202b346bb0fb0db7eff3cffeb3c70babbd2045 refs/remotes/origin/packed-test
+763d71aadf09a7951596c9746c024e7eece7c7af refs/remotes/origin/subtrees
+e90810b8df3e80c413d903f631643c716887138d refs/remotes/origin/test
+9fd738e8f7967c078dceed8190330fc8648ee56a refs/remotes/origin/track-local
+e90810b8df3e80c413d903f631643c716887138d refs/remotes/origin/trailing
+521d87c1ec3aef9824daf6d96cc0ae3710766d91 refs/tags/annotated_tag_to_blob
+^1385f264afb75a56a5bec74243be9b367ba4ca08
+7b4384978d2493e851f9cca7858815fac9b10980 refs/tags/e90810b
+^e90810b8df3e80c413d903f631643c716887138d
+849a5e34a26815e821f865b8479f5815a47af0fe refs/tags/hard_tag
+^a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+1385f264afb75a56a5bec74243be9b367ba4ca08 refs/tags/point_to_blob
+b25fa35b38051e4ae45d4222e795f9df2e43f1d1 refs/tags/test
+^e90810b8df3e80c413d903f631643c716887138d
+849a5e34a26815e821f865b8479f5815a47af0fe refs/tags/wrapped_tag
+^a65fedf39aefe402d3bb6e24df4d4f5fe4547750
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/refs/heads/master b/tests-clar/resources/push_src/.gitted/modules/submodule/refs/heads/master
new file mode 100644
index 000000000..3d8f0a402
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/refs/heads/master
@@ -0,0 +1 @@
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750
diff --git a/tests-clar/resources/push_src/.gitted/modules/submodule/refs/remotes/origin/HEAD b/tests-clar/resources/push_src/.gitted/modules/submodule/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/modules/submodule/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/push_src/.gitted/objects/08/585692ce06452da6f82ae66b90d98b55536fca b/tests-clar/resources/push_src/.gitted/objects/08/585692ce06452da6f82ae66b90d98b55536fca
new file mode 100644
index 000000000..39d126b2b
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/08/585692ce06452da6f82ae66b90d98b55536fca
@@ -0,0 +1 @@
+x+)JMU06f040031QHÔ+©(a¨˜!©”h­õ;A•EÿÛÞö®ƒ3ýZüÝ* \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/27/b7ce66243eb1403862d05f958c002312df173d b/tests-clar/resources/push_src/.gitted/objects/27/b7ce66243eb1403862d05f958c002312df173d
new file mode 100644
index 000000000..01d63b5c4
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/27/b7ce66243eb1403862d05f958c002312df173d
@@ -0,0 +1,4 @@
+x•ŽM
+Â0F]çsËt¦i<„7ù™Ñ‚m¤¤¨··xw÷àKešÆ
+Dý®." ªâmrš1°Ó@’’ê9Ú>RëûÈž¬y†Eæ
+Á mâHŽì&µ™EÐr7äS¢Þ!*u΄µÞËç2ß>#\V8¤ß|­§ÛÆG“Êt„–-ybÂöhÍF·Uþ/ä±J-|M}Wóã+GK \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/28/905c54ea45a4bed8d7b90f51bd8bd81eec8840 b/tests-clar/resources/push_src/.gitted/objects/28/905c54ea45a4bed8d7b90f51bd8bd81eec8840
new file mode 100644
index 000000000..dc10f6831
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/28/905c54ea45a4bed8d7b90f51bd8bd81eec8840
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/36/6226fb970ac0caa9d3f55967ab01334a548f60 b/tests-clar/resources/push_src/.gitted/objects/36/6226fb970ac0caa9d3f55967ab01334a548f60
new file mode 100644
index 000000000..45c4d9208
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/36/6226fb970ac0caa9d3f55967ab01334a548f60
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/5c/0bb3d1b9449d1cc69d7519fd05166f01840915 b/tests-clar/resources/push_src/.gitted/objects/5c/0bb3d1b9449d1cc69d7519fd05166f01840915
new file mode 100644
index 000000000..883182138
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/5c/0bb3d1b9449d1cc69d7519fd05166f01840915
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/61/780798228d17af2d34fce4cfbdf35556832472 b/tests-clar/resources/push_src/.gitted/objects/61/780798228d17af2d34fce4cfbdf35556832472
new file mode 100644
index 000000000..586bf17a4
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/61/780798228d17af2d34fce4cfbdf35556832472
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/64/fd55f9b6390202db5e5666fd1fb339089fba4d b/tests-clar/resources/push_src/.gitted/objects/64/fd55f9b6390202db5e5666fd1fb339089fba4d
new file mode 100644
index 000000000..bcaaa91c2
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/64/fd55f9b6390202db5e5666fd1fb339089fba4d
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/78/981922613b2afb6025042ff6bd878ac1994e85 b/tests-clar/resources/push_src/.gitted/objects/78/981922613b2afb6025042ff6bd878ac1994e85
new file mode 100644
index 000000000..e814d07b0
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/78/981922613b2afb6025042ff6bd878ac1994e85
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/80/5c54522e614f29f70d2413a0470247d8b424ac b/tests-clar/resources/push_src/.gitted/objects/80/5c54522e614f29f70d2413a0470247d8b424ac
new file mode 100644
index 000000000..552670c06
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/80/5c54522e614f29f70d2413a0470247d8b424ac
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/95/1bbbb90e2259a4c8950db78946784fb53fcbce b/tests-clar/resources/push_src/.gitted/objects/95/1bbbb90e2259a4c8950db78946784fb53fcbce
new file mode 100644
index 000000000..596cd43de
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/95/1bbbb90e2259a4c8950db78946784fb53fcbce
@@ -0,0 +1,2 @@
+x•[JÆ0…}î*f¿2—Ì$ÁEøœi’úƒm¥¶ˆ»·
+úîÛáã\8ã:Ï×DôfßZ ½ªöì&¹º65³^©»œ,åî%Ôá­lmÙ¡~;KJÌR“XT²®è•„Šö(!{ìÒ¯Ÿ£Ç±™qæP’qÅsPÓˆÈB\;EùëïE’gê”s–`IeoEÈ(YMŽ˜FåÂC9ö—uƒ§u™>¯ð|Àýø#?ŽÇi.××»q€D9³0F¸EENzþßÛÿ“Ãܶ©Ë<\ ,\a_a.ïgßðëd \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/a7/8705c3b2725f931d3ee05348d83cc26700f247 b/tests-clar/resources/push_src/.gitted/objects/a7/8705c3b2725f931d3ee05348d83cc26700f247
new file mode 100644
index 000000000..6ad835e86
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/a7/8705c3b2725f931d3ee05348d83cc26700f247
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/b4/83ae7ba66decee9aee971f501221dea84b1498 b/tests-clar/resources/push_src/.gitted/objects/b4/83ae7ba66decee9aee971f501221dea84b1498
new file mode 100644
index 000000000..1e0bd3b05
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/b4/83ae7ba66decee9aee971f501221dea84b1498
@@ -0,0 +1,3 @@
+x5K
+1D]ç½¥;1i"^À•'èÎô|d`dŒ ooqQE½Í«*PàÝ¢+
+á 3…$, }ì%¢Rßw¬É+sç9»úy輨«ÍÐrøÃ`+ܦ2ŠÍp/ã[m­p~µuÝê8-—öSˆ™r„=¢Û,?ÃZ+g \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/b4/e1f2b375a64c1ccd40c5ff6aa8bc96839ba4fd b/tests-clar/resources/push_src/.gitted/objects/b4/e1f2b375a64c1ccd40c5ff6aa8bc96839ba4fd
new file mode 100644
index 000000000..4e650aaa1
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/b4/e1f2b375a64c1ccd40c5ff6aa8bc96839ba4fd
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/c1/0409136a7a75e025fa502a1b2fd7b62b77d279 b/tests-clar/resources/push_src/.gitted/objects/c1/0409136a7a75e025fa502a1b2fd7b62b77d279
new file mode 100644
index 000000000..fcb2b32f3
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/c1/0409136a7a75e025fa502a1b2fd7b62b77d279
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/cd/881f90f2933db2e4cc26b8c71fe6037ac7fe4c b/tests-clar/resources/push_src/.gitted/objects/cd/881f90f2933db2e4cc26b8c71fe6037ac7fe4c
new file mode 100644
index 000000000..ad4272638
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/cd/881f90f2933db2e4cc26b8c71fe6037ac7fe4c
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/d9/b63a88223d8367516f50bd131a5f7349b7f3e4 b/tests-clar/resources/push_src/.gitted/objects/d9/b63a88223d8367516f50bd131a5f7349b7f3e4
new file mode 100644
index 000000000..b471e2155
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/d9/b63a88223d8367516f50bd131a5f7349b7f3e4
@@ -0,0 +1,2 @@
+x•ŽA
+Â0E]çsËd¦Ó$ "x×i2Õ‚m¤¤¨··zwŸ÷S™¦±‘ÝÕErŠ½gjÃÐ ![ÍŽ%wbY(z˜C/ÁšG\t®w(‰{r$C`›Y…[Ÿ=§DC¨u&®õV8—ùúá²Â!ýæs=]§8Þ›T¦#|;˜ÐÂÑltûWõÓh«fˆM}Uó¼QDM \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/dc/ab83249f6f9d1ed735d651352a80519339b591 b/tests-clar/resources/push_src/.gitted/objects/dc/ab83249f6f9d1ed735d651352a80519339b591
new file mode 100644
index 000000000..9f6b1502f
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/dc/ab83249f6f9d1ed735d651352a80519339b591
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/f7/8a3106c85fb549c65198b2a2086276c6174928 b/tests-clar/resources/push_src/.gitted/objects/f7/8a3106c85fb549c65198b2a2086276c6174928
new file mode 100644
index 000000000..b9813576d
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/f7/8a3106c85fb549c65198b2a2086276c6174928
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/f8/f7aefc2900a3d737cea9eee45729fd55761e1a b/tests-clar/resources/push_src/.gitted/objects/f8/f7aefc2900a3d737cea9eee45729fd55761e1a
new file mode 100644
index 000000000..888354fc2
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/f8/f7aefc2900a3d737cea9eee45729fd55761e1a
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/fa/38b91f199934685819bea316186d8b008c52a2 b/tests-clar/resources/push_src/.gitted/objects/fa/38b91f199934685819bea316186d8b008c52a2
new file mode 100644
index 000000000..13d9bca20
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/fa/38b91f199934685819bea316186d8b008c52a2
@@ -0,0 +1,2 @@
+x•½J1„­ó§ÛÊ5›ÿ…‹>„urr²n’eo‚øö {»™f[)¹ƒ°â©_DmIiµ7
+7Ĩ8ꔌ÷.ànœÜƒW)²Ó_T;xë,×(ÃlÐi—[”D\K墓ˆÂXΓP–ùÑ?Ûï­ß>ÜðW~·£ø|_±•Wؤ»‚xæšs6éÜ×éÿIæc¤J‹ãNP}™~ù œ-מë½Á²®/ó„³­Gî û§X \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/ff/83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e b/tests-clar/resources/push_src/.gitted/objects/ff/83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e
new file mode 100644
index 000000000..10f25eb7c
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/ff/83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e
@@ -0,0 +1,4 @@
+x5ÍM
+1 `×=Eö¢4ÓNAÄ ¸òýÉüÈÀH ooq‘Ç{›/G@ò»5=$+”SOÝ) n¥xâ≻Ø[Æ@4úy
+h1Ú„v‡ÿ¥ÂmÎS”îyz'©
+çWk×-ŽóziÙQc<ÃÞ¢µfS~Âpv+… \ No newline at end of file
diff --git a/tests-clar/resources/push_src/.gitted/objects/ff/fe95c7fd0a37fa2ed702f8f93b56b2196b3925 b/tests-clar/resources/push_src/.gitted/objects/ff/fe95c7fd0a37fa2ed702f8f93b56b2196b3925
new file mode 100644
index 000000000..1cdc048c0
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/ff/fe95c7fd0a37fa2ed702f8f93b56b2196b3925
Binary files differ
diff --git a/tests-clar/resources/push_src/.gitted/objects/pack/dummy b/tests-clar/resources/push_src/.gitted/objects/pack/dummy
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/objects/pack/dummy
diff --git a/tests-clar/resources/push_src/.gitted/refs/heads/b1 b/tests-clar/resources/push_src/.gitted/refs/heads/b1
new file mode 100644
index 000000000..afadf9d26
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/heads/b1
@@ -0,0 +1 @@
+a78705c3b2725f931d3ee05348d83cc26700f247
diff --git a/tests-clar/resources/push_src/.gitted/refs/heads/b2 b/tests-clar/resources/push_src/.gitted/refs/heads/b2
new file mode 100644
index 000000000..afadf9d26
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/heads/b2
@@ -0,0 +1 @@
+a78705c3b2725f931d3ee05348d83cc26700f247
diff --git a/tests-clar/resources/push_src/.gitted/refs/heads/b3 b/tests-clar/resources/push_src/.gitted/refs/heads/b3
new file mode 100644
index 000000000..3056bb436
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/heads/b3
@@ -0,0 +1 @@
+d9b63a88223d8367516f50bd131a5f7349b7f3e4
diff --git a/tests-clar/resources/push_src/.gitted/refs/heads/b4 b/tests-clar/resources/push_src/.gitted/refs/heads/b4
new file mode 100644
index 000000000..efed6f064
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/heads/b4
@@ -0,0 +1 @@
+27b7ce66243eb1403862d05f958c002312df173d
diff --git a/tests-clar/resources/push_src/.gitted/refs/heads/b5 b/tests-clar/resources/push_src/.gitted/refs/heads/b5
new file mode 100644
index 000000000..cf313ad05
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/heads/b5
@@ -0,0 +1 @@
+fa38b91f199934685819bea316186d8b008c52a2
diff --git a/tests-clar/resources/push_src/.gitted/refs/heads/b6 b/tests-clar/resources/push_src/.gitted/refs/heads/b6
new file mode 100644
index 000000000..711e466ae
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/heads/b6
@@ -0,0 +1 @@
+951bbbb90e2259a4c8950db78946784fb53fcbce
diff --git a/tests-clar/resources/push_src/.gitted/refs/tags/tag-blob b/tests-clar/resources/push_src/.gitted/refs/tags/tag-blob
new file mode 100644
index 000000000..abfebf22e
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/tags/tag-blob
@@ -0,0 +1 @@
+b483ae7ba66decee9aee971f501221dea84b1498
diff --git a/tests-clar/resources/push_src/.gitted/refs/tags/tag-commit b/tests-clar/resources/push_src/.gitted/refs/tags/tag-commit
new file mode 100644
index 000000000..c023b8452
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/tags/tag-commit
@@ -0,0 +1 @@
+805c54522e614f29f70d2413a0470247d8b424ac
diff --git a/tests-clar/resources/push_src/.gitted/refs/tags/tag-lightweight b/tests-clar/resources/push_src/.gitted/refs/tags/tag-lightweight
new file mode 100644
index 000000000..711e466ae
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/tags/tag-lightweight
@@ -0,0 +1 @@
+951bbbb90e2259a4c8950db78946784fb53fcbce
diff --git a/tests-clar/resources/push_src/.gitted/refs/tags/tag-tree b/tests-clar/resources/push_src/.gitted/refs/tags/tag-tree
new file mode 100644
index 000000000..7a530d381
--- /dev/null
+++ b/tests-clar/resources/push_src/.gitted/refs/tags/tag-tree
@@ -0,0 +1 @@
+ff83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e
diff --git a/tests-clar/resources/push_src/a.txt b/tests-clar/resources/push_src/a.txt
new file mode 100644
index 000000000..f7eac1c51
--- /dev/null
+++ b/tests-clar/resources/push_src/a.txt
@@ -0,0 +1,2 @@
+a
+edit
diff --git a/tests-clar/resources/push_src/fold/b.txt b/tests-clar/resources/push_src/fold/b.txt
new file mode 100644
index 000000000..617807982
--- /dev/null
+++ b/tests-clar/resources/push_src/fold/b.txt
@@ -0,0 +1 @@
+b
diff --git a/tests-clar/resources/push_src/foldb.txt b/tests-clar/resources/push_src/foldb.txt
new file mode 100644
index 000000000..5b38718be
--- /dev/null
+++ b/tests-clar/resources/push_src/foldb.txt
@@ -0,0 +1 @@
+edit
diff --git a/tests-clar/resources/push_src/gitmodules b/tests-clar/resources/push_src/gitmodules
new file mode 100644
index 000000000..f1734dfc1
--- /dev/null
+++ b/tests-clar/resources/push_src/gitmodules
@@ -0,0 +1,3 @@
+[submodule "submodule"]
+ path = submodule
+ url = ../testrepo.git
diff --git a/tests-clar/resources/push_src/submodule/.gitted b/tests-clar/resources/push_src/submodule/.gitted
new file mode 100644
index 000000000..3ffcf960a
--- /dev/null
+++ b/tests-clar/resources/push_src/submodule/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/submodule
diff --git a/tests-clar/resources/push_src/submodule/README b/tests-clar/resources/push_src/submodule/README
new file mode 100644
index 000000000..ca8c64728
--- /dev/null
+++ b/tests-clar/resources/push_src/submodule/README
@@ -0,0 +1 @@
+hey there
diff --git a/tests-clar/resources/push_src/submodule/branch_file.txt b/tests-clar/resources/push_src/submodule/branch_file.txt
new file mode 100644
index 000000000..a26902575
--- /dev/null
+++ b/tests-clar/resources/push_src/submodule/branch_file.txt
@@ -0,0 +1,2 @@
+hi
+bye!
diff --git a/tests-clar/resources/push_src/submodule/new.txt b/tests-clar/resources/push_src/submodule/new.txt
new file mode 100644
index 000000000..8e0884e36
--- /dev/null
+++ b/tests-clar/resources/push_src/submodule/new.txt
@@ -0,0 +1 @@
+my new file
diff --git a/tests-clar/resources/renames/.gitted/HEAD b/tests-clar/resources/renames/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/renames/.gitted/config b/tests-clar/resources/renames/.gitted/config
new file mode 100644
index 000000000..bb4d11c1f
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+ precomposeunicode = false
diff --git a/tests-clar/resources/renames/.gitted/description b/tests-clar/resources/renames/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/renames/.gitted/index b/tests-clar/resources/renames/.gitted/index
new file mode 100644
index 000000000..72363c0f5
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/info/exclude b/tests-clar/resources/renames/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/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-clar/resources/renames/.gitted/logs/HEAD b/tests-clar/resources/renames/.gitted/logs/HEAD
new file mode 100644
index 000000000..e69792263
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/logs/HEAD
@@ -0,0 +1,4 @@
+0000000000000000000000000000000000000000 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 Russell Belfer <rb@github.com> 1351024687 -0700 commit (initial): Initial commit
+31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 2bc7f351d20b53f1c72c16c4b036e491c478c49a Russell Belfer <rb@github.com> 1351024817 -0700 commit: copy and rename with no change
+2bc7f351d20b53f1c72c16c4b036e491c478c49a 1c068dee5790ef1580cfc4cd670915b48d790084 Russell Belfer <rb@github.com> 1361485758 -0800 commit: rewrites, copies with changes, etc.
+1c068dee5790ef1580cfc4cd670915b48d790084 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 Russell Belfer <rb@github.com> 1361486360 -0800 commit: more renames and smallish modifications
diff --git a/tests-clar/resources/renames/.gitted/logs/refs/heads/master b/tests-clar/resources/renames/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..e69792263
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/logs/refs/heads/master
@@ -0,0 +1,4 @@
+0000000000000000000000000000000000000000 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 Russell Belfer <rb@github.com> 1351024687 -0700 commit (initial): Initial commit
+31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 2bc7f351d20b53f1c72c16c4b036e491c478c49a Russell Belfer <rb@github.com> 1351024817 -0700 commit: copy and rename with no change
+2bc7f351d20b53f1c72c16c4b036e491c478c49a 1c068dee5790ef1580cfc4cd670915b48d790084 Russell Belfer <rb@github.com> 1361485758 -0800 commit: rewrites, copies with changes, etc.
+1c068dee5790ef1580cfc4cd670915b48d790084 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 Russell Belfer <rb@github.com> 1361486360 -0800 commit: more renames and smallish modifications
diff --git a/tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7 b/tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7
new file mode 100644
index 000000000..2ee86444d
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/19/dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 b/tests-clar/resources/renames/.gitted/objects/19/dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
new file mode 100644
index 000000000..4be4c6952
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/19/dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
@@ -0,0 +1 @@
+x•ŽÑM!Eý¦Ši@3¼Þc,Á\X °ýK þÞ{Nrbo­,xzYC¬<‡h[&“È?=fcvÎyƒèC£W¿<äZ #:J"vs’µ%Œ9š˜Ü½¶ÁPÚ’Q|¯³ø¾ç”ZáKj–ï#|þ”uÞá-ööúpÚ;Â+¢Úëî[ý¯©Z;’›Là+Ál\k™'´žJ.‘Wé×T¯;O
diff --git a/tests-clar/resources/renames/.gitted/objects/1c/068dee5790ef1580cfc4cd670915b48d790084 b/tests-clar/resources/renames/.gitted/objects/1c/068dee5790ef1580cfc4cd670915b48d790084
new file mode 100644
index 000000000..d65ab0a9b
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/1c/068dee5790ef1580cfc4cd670915b48d790084
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49a b/tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49a
new file mode 100644
index 000000000..93f1ccb3f
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49a
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2 b/tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2
new file mode 100644
index 000000000..00ce53212
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/36/020db6cdacaa93497f31edcd8f242ff9bc366d b/tests-clar/resources/renames/.gitted/objects/36/020db6cdacaa93497f31edcd8f242ff9bc366d
new file mode 100644
index 000000000..f4f9303ed
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/36/020db6cdacaa93497f31edcd8f242ff9bc366d
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/3c/04741dd4b96c4ae4b00ec0f6e10c816a30aad2 b/tests-clar/resources/renames/.gitted/objects/3c/04741dd4b96c4ae4b00ec0f6e10c816a30aad2
new file mode 100644
index 000000000..c23602262
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/3c/04741dd4b96c4ae4b00ec0f6e10c816a30aad2
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/42/10ffd5c390b21dd5483375e75288dea9ede512 b/tests-clar/resources/renames/.gitted/objects/42/10ffd5c390b21dd5483375e75288dea9ede512
new file mode 100644
index 000000000..d351a6d13
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/42/10ffd5c390b21dd5483375e75288dea9ede512
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/4e/4cae3e7dd56ed74bff39526d0469e554432953 b/tests-clar/resources/renames/.gitted/objects/4e/4cae3e7dd56ed74bff39526d0469e554432953
new file mode 100644
index 000000000..5e6ebd5e0
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/4e/4cae3e7dd56ed74bff39526d0469e554432953
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/5e/26abc56a5a84d89790f45416648899cbe13109 b/tests-clar/resources/renames/.gitted/objects/5e/26abc56a5a84d89790f45416648899cbe13109
new file mode 100644
index 000000000..2acd3d583
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/5e/26abc56a5a84d89790f45416648899cbe13109
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745 b/tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745
new file mode 100644
index 000000000..24eac54c5
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bba b/tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bba
new file mode 100644
index 000000000..5ee28a76a
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bba
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/9a/69d960ae94b060f56c2a8702545e2bb1abb935 b/tests-clar/resources/renames/.gitted/objects/9a/69d960ae94b060f56c2a8702545e2bb1abb935
new file mode 100644
index 000000000..f75178c59
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/9a/69d960ae94b060f56c2a8702545e2bb1abb935
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113 b/tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113
new file mode 100644
index 000000000..440b7bec3
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/d7/9b202de198fa61b02424b9e25e840dc75e1323 b/tests-clar/resources/renames/.gitted/objects/d7/9b202de198fa61b02424b9e25e840dc75e1323
new file mode 100644
index 000000000..daa2b3997
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/d7/9b202de198fa61b02424b9e25e840dc75e1323
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/objects/ea/f4a3e3bfe68585e90cada20736ace491cd100b b/tests-clar/resources/renames/.gitted/objects/ea/f4a3e3bfe68585e90cada20736ace491cd100b
new file mode 100644
index 000000000..f72df8d82
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/ea/f4a3e3bfe68585e90cada20736ace491cd100b
@@ -0,0 +1,5 @@
+x}RÁªÔ@ô<_QžTÈ.¼“ÂâAáÉ[–‡â
+{ž¼t2C’žez’˜›áú%öLžº'!aº»ª«jê!Ôx{÷îÅ'¢+Îþ;“$œ)Ξ»Ý#±yÿ¿Ç˜³#q#¯h„­c° ÃQDX¶m­R|ŠaD*ÝOˆþ†+±”^ZI~ýøi>3aôÃàã!,R!-áïÉEaIÁ>äyš‰o*«¼4æˆRf¡ m&e¯ IAÑú™ò*!â;¢ždÍݬ‚…´Å
+êH¶o­¤
+ÃÄO®‚U¾DöyTVØHpwqÅH¼7§„Æ·­.ÈʆÎÎts6{Zä +öX\)Šª”ÑC–žì5QªÂä9
+%©ÌÅt*Ã&Ï&è°êv;|šÕÆ'4½ìÆéþþ Dƒu[°7h¯¿e!ÉNK*"C©-=Óòæ`´æ#ØŽ$EëÅe2õáâT|ùêå@NBsús¢¦lµ°Wö|/¶0¬÷aÈ¥üJ±ò¶Nêv)-šÚ¡˜iÛ¤3ÅëbäbO:uWMâˆNÓÜàóæ¶X²7¿Tóº \ No newline at end of file
diff --git a/tests-clar/resources/renames/.gitted/objects/f9/0d4fc20ecddf21eebe6a37e9225d244339d2b5 b/tests-clar/resources/renames/.gitted/objects/f9/0d4fc20ecddf21eebe6a37e9225d244339d2b5
new file mode 100644
index 000000000..f6d933be9
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/f9/0d4fc20ecddf21eebe6a37e9225d244339d2b5
Binary files differ
diff --git a/tests-clar/resources/renames/.gitted/refs/heads/master b/tests-clar/resources/renames/.gitted/refs/heads/master
new file mode 100644
index 000000000..642c3198d
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/refs/heads/master
@@ -0,0 +1 @@
+19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
diff --git a/tests-clar/resources/renames/ikeepsix.txt b/tests-clar/resources/renames/ikeepsix.txt
new file mode 100644
index 000000000..eaf4a3e3b
--- /dev/null
+++ b/tests-clar/resources/renames/ikeepsix.txt
@@ -0,0 +1,27 @@
+I Keep Six Honest Serving-Men
+=============================
+
+She sends'em abroad on her own affairs,
+ From the second she opens her eyes—
+One million Hows, two million Wheres,
+And seven million Whys!
+
+I let them rest from nine till five,
+ For I am busy then,
+As well as breakfast, lunch, and tea,
+ For they are hungry men.
+But different folk have different views;
+I know a person small—
+She keeps ten million serving-men,
+Who get no rest at all!
+
+ -- Rudyard Kipling
+
+I KEEP six honest serving-men
+ (They taught me all I knew);
+Their names are What and Why and When
+ And How and Where and Who.
+I send them over land and sea,
+ I send them east and west;
+But after they have worked for me,
+ I give them all a rest.
diff --git a/tests-clar/resources/renames/sixserving.txt b/tests-clar/resources/renames/sixserving.txt
new file mode 100644
index 000000000..f90d4fc20
--- /dev/null
+++ b/tests-clar/resources/renames/sixserving.txt
@@ -0,0 +1,25 @@
+I KEEP six honest serving-men
+ (They taught me all I knew);
+Their names are What and Why and When
+ And How and Where and Who.
+I send them over land and sea,
+ I send them east and west;
+But after they have worked for me,
+ I give them all a rest.
+
+I let them rest from nine till five,
+ For I am busy then,
+As well as breakfast, lunch, and tea,
+ For they are hungry men.
+But different folk have different views;
+I know a person small—
+She keeps ten million serving-men,
+Who get no rest at all!
+
+She sends'em abroad on her own affairs,
+ From the second she opens her eyes—
+One million Hows, two million Wheres,
+And seven million Whys!
+
+ -- Rudyard Kipling
+
diff --git a/tests-clar/resources/renames/songof7cities.txt b/tests-clar/resources/renames/songof7cities.txt
new file mode 100644
index 000000000..4210ffd5c
--- /dev/null
+++ b/tests-clar/resources/renames/songof7cities.txt
@@ -0,0 +1,49 @@
+The Song of Seven Cities
+------------------------
+
+I WAS Lord of Cities very sumptuously builded.
+Seven roaring Cities paid me tribute from afar.
+Ivory their outposts were--the guardrooms of them gilded,
+And garrisoned with Amazons invincible in war.
+
+All the world went softly when it walked before my Cities--
+Neither King nor Army vexed my peoples at their toil,
+Never horse nor chariot irked or overbore my Cities,
+Never Mob nor Ruler questioned whence they drew their spoil.
+
+Banded, mailed and arrogant from sunrise unto sunset;
+Singing while they sacked it, they possessed the land at large.
+Yet when men would rob them, they resisted, they made onset
+And pierced the smoke of battle with a thousand-sabred charge.
+
+So they warred and trafficked only yesterday, my Cities.
+To-day there is no mark or mound of where my Cities stood.
+For the River rose at midnight and it washed away my Cities.
+They are evened with Atlantis and the towns before the Flood.
+
+Rain on rain-gorged channels raised the water-levels round them,
+Freshet backed on freshet swelled and swept their world from sight,
+Till the emboldened floods linked arms and, flashing forward, drowned them--
+Drowned my Seven Cities and their peoples in one night!
+
+Low among the alders lie their derelict foundations,
+The beams wherein they trusted and the plinths whereon they built--
+My rulers and their treasure and their unborn populations,
+Dead, destroyed, aborted, and defiled with mud and silt!
+
+The Daughters of the Palace whom they cherished in my Cities,
+My silver-tongued Princesses, and the promise of their May--
+Their bridegrooms of the June-tide--all have perished in my Cities,
+With the harsh envenomed virgins that can neither love nor play.
+
+I was Lord of Cities--I will build anew my Cities,
+Seven, set on rocks, above the wrath of any flood.
+Nor will I rest from search till I have filled anew my Cities
+With peoples undefeated of the dark, enduring blood.
+
+To the sound of trumpets shall their seed restore my Cities
+Wealthy and well-weaponed, that once more may I behold
+All the world go softly when it walks before my Cities,
+And the horses and the chariots fleeing from them as of old!
+
+ -- Rudyard Kipling
diff --git a/tests-clar/resources/renames/untimely.txt b/tests-clar/resources/renames/untimely.txt
new file mode 100644
index 000000000..9a69d960a
--- /dev/null
+++ b/tests-clar/resources/renames/untimely.txt
@@ -0,0 +1,24 @@
+Untimely
+========
+
+Nothing in life has been made by man for man's using
+But it was shown long since to man in ages
+Lost as the name of the maker of it,
+Who received oppression and shame for his wages--
+Hate, avoidance, and scorn in his daily dealings--
+Until he perished, wholly confounded
+
+More to be pitied than he are the wise
+Souls which foresaw the evil of loosing
+Knowledge or Art before time, and aborted
+Noble devices and deep-wrought healings,
+Lest offense should arise.
+
+Heaven delivers on earth the Hour that cannot be
+ thwarted,
+Neither advanced, at the price of a world nor a soul,
+ and its Prophet
+Comes through the blood of the vanguards who
+ dreamed--too soon--it had sounded.
+
+ -- Rudyard Kipling
diff --git a/tests-clar/resources/short_tag.git/HEAD b/tests-clar/resources/short_tag.git/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/short_tag.git/config b/tests-clar/resources/short_tag.git/config
new file mode 100644
index 000000000..a4ef456cb
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/config
@@ -0,0 +1,5 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+ logallrefupdates = true
diff --git a/tests-clar/resources/short_tag.git/index b/tests-clar/resources/short_tag.git/index
new file mode 100644
index 000000000..87fef7847
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/index
Binary files differ
diff --git a/tests-clar/resources/short_tag.git/objects/4a/5ed60bafcf4638b7c8356bd4ce1916bfede93c b/tests-clar/resources/short_tag.git/objects/4a/5ed60bafcf4638b7c8356bd4ce1916bfede93c
new file mode 100644
index 000000000..aeb4e4b0b
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/objects/4a/5ed60bafcf4638b7c8356bd4ce1916bfede93c
Binary files differ
diff --git a/tests-clar/resources/short_tag.git/objects/4d/5fcadc293a348e88f777dc0920f11e7d71441c b/tests-clar/resources/short_tag.git/objects/4d/5fcadc293a348e88f777dc0920f11e7d71441c
new file mode 100644
index 000000000..806ce71a5
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/objects/4d/5fcadc293a348e88f777dc0920f11e7d71441c
Binary files differ
diff --git a/tests-clar/resources/short_tag.git/objects/5d/a7760512a953e3c7c4e47e4392c7a4338fb729 b/tests-clar/resources/short_tag.git/objects/5d/a7760512a953e3c7c4e47e4392c7a4338fb729
new file mode 100644
index 000000000..1192707c9
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/objects/5d/a7760512a953e3c7c4e47e4392c7a4338fb729
@@ -0,0 +1 @@
+xÌM‚0@aלb. ií%1Æ—pcÚé@Š”˜˜èé-Ëï-û¤6§&Bí E+‚pÐV¹Ð¡SƆ¨‘d/m(R¯°áïJ€%çÄ ×ÇR^‘vÜÒÊ©,GiƒÇ–Þðñ <Ó´3\©º­n‡ïcöinëåRé„SögÑ Ñüëu1 \ No newline at end of file
diff --git a/tests-clar/resources/short_tag.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests-clar/resources/short_tag.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 000000000..711223894
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
Binary files differ
diff --git a/tests-clar/resources/short_tag.git/packed-refs b/tests-clar/resources/short_tag.git/packed-refs
new file mode 100644
index 000000000..ca5197e3c
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/packed-refs
@@ -0,0 +1 @@
+5da7760512a953e3c7c4e47e4392c7a4338fb729 refs/tags/no_description
diff --git a/tests-clar/resources/short_tag.git/refs/heads/master b/tests-clar/resources/short_tag.git/refs/heads/master
new file mode 100644
index 000000000..fcefd1ef0
--- /dev/null
+++ b/tests-clar/resources/short_tag.git/refs/heads/master
@@ -0,0 +1 @@
+4a5ed60bafcf4638b7c8356bd4ce1916bfede93c
diff --git a/tests-clar/resources/status/.gitted/index b/tests-clar/resources/status/.gitted/index
index 9a383ec0c..2af99a183 100644
--- a/tests-clar/resources/status/.gitted/index
+++ b/tests-clar/resources/status/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/status/è¿™ b/tests-clar/resources/status/è¿™
new file mode 100644
index 000000000..f0ff9a197
--- /dev/null
+++ b/tests-clar/resources/status/è¿™
@@ -0,0 +1 @@
+This
diff --git a/tests-clar/resources/submod2/.gitted/HEAD b/tests-clar/resources/submod2/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/config b/tests-clar/resources/submod2/.gitted/config
new file mode 100644
index 000000000..abc420734
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/config
@@ -0,0 +1,20 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[submodule "sm_missing_commits"]
+ url = ../submod2_target
+[submodule "sm_unchanged"]
+ url = ../submod2_target
+[submodule "sm_changed_file"]
+ url = ../submod2_target
+[submodule "sm_changed_index"]
+ url = ../submod2_target
+[submodule "sm_changed_head"]
+ url = ../submod2_target
+[submodule "sm_changed_untracked_file"]
+ url = ../submod2_target
+[submodule "sm_added_and_uncommited"]
+ url = ../submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/description b/tests-clar/resources/submod2/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/index b/tests-clar/resources/submod2/.gitted/index
new file mode 100644
index 000000000..0c17e8629
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/info/exclude b/tests-clar/resources/submod2/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/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-clar/resources/submod2/.gitted/logs/HEAD b/tests-clar/resources/submod2/.gitted/logs/HEAD
new file mode 100644
index 000000000..2cf2ca74d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/logs/HEAD
@@ -0,0 +1,4 @@
+0000000000000000000000000000000000000000 14fe9ccf104058df25e0a08361c4494e167ef243 Russell Belfer <rb@github.com> 1342559771 -0700 commit (initial): Initial commit
+14fe9ccf104058df25e0a08361c4494e167ef243 a9104bf89e911387244ef499413960ba472066d9 Russell Belfer <rb@github.com> 1342559831 -0700 commit: Adding a submodule
+a9104bf89e911387244ef499413960ba472066d9 5901da4f1c67756eeadc5121d206bec2431f253b Russell Belfer <rb@github.com> 1342560036 -0700 commit: Updating submodule
+5901da4f1c67756eeadc5121d206bec2431f253b 7484482eb8db738cafa696993664607500a3f2b9 Russell Belfer <rb@github.com> 1342560288 -0700 commit: Adding a bunch more test content
diff --git a/tests-clar/resources/submod2/.gitted/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..2cf2ca74d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/logs/refs/heads/master
@@ -0,0 +1,4 @@
+0000000000000000000000000000000000000000 14fe9ccf104058df25e0a08361c4494e167ef243 Russell Belfer <rb@github.com> 1342559771 -0700 commit (initial): Initial commit
+14fe9ccf104058df25e0a08361c4494e167ef243 a9104bf89e911387244ef499413960ba472066d9 Russell Belfer <rb@github.com> 1342559831 -0700 commit: Adding a submodule
+a9104bf89e911387244ef499413960ba472066d9 5901da4f1c67756eeadc5121d206bec2431f253b Russell Belfer <rb@github.com> 1342560036 -0700 commit: Updating submodule
+5901da4f1c67756eeadc5121d206bec2431f253b 7484482eb8db738cafa696993664607500a3f2b9 Russell Belfer <rb@github.com> 1342560288 -0700 commit: Adding a bunch more test content
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/config b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/config
new file mode 100644
index 000000000..2d0583e99
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_added_and_uncommited
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/description b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/index b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/index
new file mode 100644
index 000000000..65140a510
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/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-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/HEAD
new file mode 100644
index 000000000..53753e7dd
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560316 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/heads/master
new file mode 100644
index 000000000..53753e7dd
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560316 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..53753e7dd
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560316 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_added_and_uncommited/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/config b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/config
new file mode 100644
index 000000000..10cc2508e
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_changed_file
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/description b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/index b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/index
new file mode 100644
index 000000000..6914a3b6e
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/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-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/HEAD
new file mode 100644
index 000000000..e5cb63f8d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560173 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/heads/master
new file mode 100644
index 000000000..e5cb63f8d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560173 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..e5cb63f8d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560173 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_file/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/COMMIT_EDITMSG b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/COMMIT_EDITMSG
new file mode 100644
index 000000000..6b8d1e3fc
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/COMMIT_EDITMSG
@@ -0,0 +1 @@
+Making a change in a submodule
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/config b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/config
new file mode 100644
index 000000000..7d002536a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_changed_head
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/description b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/index b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/index
new file mode 100644
index 000000000..728fa292f
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/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-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/HEAD
new file mode 100644
index 000000000..cabdeb2b5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/HEAD
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560179 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+480095882d281ed676fe5b863569520e54a7d5c0 3d9386c507f6b093471a3e324085657a3c2b4247 Russell Belfer <rb@github.com> 1342560431 -0700 commit: Making a change in a submodule
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/heads/master
new file mode 100644
index 000000000..cabdeb2b5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/heads/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560179 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+480095882d281ed676fe5b863569520e54a7d5c0 3d9386c507f6b093471a3e324085657a3c2b4247 Russell Belfer <rb@github.com> 1342560431 -0700 commit: Making a change in a submodule
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..257ca21d1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560179 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/3d/9386c507f6b093471a3e324085657a3c2b4247 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/3d/9386c507f6b093471a3e324085657a3c2b4247
new file mode 100644
index 000000000..a2c371642
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/3d/9386c507f6b093471a3e324085657a3c2b4247
@@ -0,0 +1,3 @@
+x•ŽKj!E3vµ„jµüÀ#<Þ<“ì@­êéO°uÿq ™.çÂ)×ql ´‰o­Š€÷sFa#Èv‰ÓÅ )g#{':ªßTål`b¤4ë0 ;ïf¡ár‘4
+Ùä™
+ªÔÛzUøî÷-û/Ùg©ð¨ù¹lmíù£\Ç'LÆjrhÍïèÕXG_êŸê+ýlç ÊšÎE`;ß=÷]ÔÞJç \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/77/fb0ed3e58568d6ad362c78de08ab8649d76e29 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/77/fb0ed3e58568d6ad362c78de08ab8649d76e29
new file mode 100644
index 000000000..f8a236f3d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/77/fb0ed3e58568d6ad362c78de08ab8649d76e29
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/8e/b1e637ed9fc8e5454fa20d38f809091f9395f4 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/8e/b1e637ed9fc8e5454fa20d38f809091f9395f4
new file mode 100644
index 000000000..8155b3e87
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/8e/b1e637ed9fc8e5454fa20d38f809091f9395f4
@@ -0,0 +1,2 @@
+xMM;
+1µÎ)Þ ÁZPÐÞÆr²3kÉ l²En¿ƒl!¼æýc±ˆóõrz§Üà ,¹º¡çe +ÚlEZxuPY…x QC³*ðf·uLácfR3ŠÍT0'Ò¯øjƒŠ°ð~G¦^s1Šèb2z’ƒÿùVkî]Ü5<·ûv¨'>ã \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/heads/master
new file mode 100644
index 000000000..ae079bd79
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/heads/master
@@ -0,0 +1 @@
+3d9386c507f6b093471a3e324085657a3c2b4247
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_head/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/config b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/config
new file mode 100644
index 000000000..0274ff7e3
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_changed_index
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/description b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/index b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/index
new file mode 100644
index 000000000..6fad3b43e
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/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-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/HEAD
new file mode 100644
index 000000000..80eb54102
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560175 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/heads/master
new file mode 100644
index 000000000..80eb54102
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560175 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..80eb54102
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560175 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/a0/2d31770687965547ab7a04cee199b29ee458d6 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/a0/2d31770687965547ab7a04cee199b29ee458d6
new file mode 100644
index 000000000..cb3f5a002
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/a0/2d31770687965547ab7a04cee199b29ee458d6
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_index/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/config b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/config
new file mode 100644
index 000000000..7f2584476
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_changed_untracked_file
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/description b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/index b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/index
new file mode 100644
index 000000000..598e30a32
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/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-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/HEAD
new file mode 100644
index 000000000..d1beafbd6
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560186 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/heads/master
new file mode 100644
index 000000000..d1beafbd6
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560186 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..d1beafbd6
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560186 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_changed_untracked_file/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/config b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/config
new file mode 100644
index 000000000..45fbb30cf
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_missing_commits
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/description b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/index b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/index
new file mode 100644
index 000000000..490356524
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/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-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/HEAD
new file mode 100644
index 000000000..ee08c9706
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 5e4963595a9774b90524d35a807169049de8ccad Russell Belfer <rb@github.com> 1342559796 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/heads/master
new file mode 100644
index 000000000..ee08c9706
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 5e4963595a9774b90524d35a807169049de8ccad Russell Belfer <rb@github.com> 1342559796 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..ee08c9706
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 5e4963595a9774b90524d35a807169049de8ccad Russell Belfer <rb@github.com> 1342559796 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/packed-refs
new file mode 100644
index 000000000..66fbf5daf
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+5e4963595a9774b90524d35a807169049de8ccad refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/heads/master
new file mode 100644
index 000000000..3913aca5d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/heads/master
@@ -0,0 +1 @@
+5e4963595a9774b90524d35a807169049de8ccad
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_missing_commits/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/config b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/config
new file mode 100644
index 000000000..fc706c9dd
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../sm_unchanged
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/description b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/index b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/index
new file mode 100644
index 000000000..629c849ec
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/index
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/info/exclude b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/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-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/HEAD
new file mode 100644
index 000000000..72653286a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560169 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/heads/master
new file mode 100644
index 000000000..72653286a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560169 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..72653286a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342560169 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/submod2_target
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/packed-refs b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/heads/master b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/remotes/origin/HEAD b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/modules/sm_unchanged/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/submod2/.gitted/objects/09/460e5b6cbcb05a3e404593c32a3aa7221eca0e b/tests-clar/resources/submod2/.gitted/objects/09/460e5b6cbcb05a3e404593c32a3aa7221eca0e
new file mode 100644
index 000000000..f1ea5f4c8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/09/460e5b6cbcb05a3e404593c32a3aa7221eca0e
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/14/fe9ccf104058df25e0a08361c4494e167ef243 b/tests-clar/resources/submod2/.gitted/objects/14/fe9ccf104058df25e0a08361c4494e167ef243
new file mode 100644
index 000000000..d3c8582e3
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/14/fe9ccf104058df25e0a08361c4494e167ef243
@@ -0,0 +1 @@
+x•M F]sŠ¹€fh¡ccŒ;·Þ€ŸÁ’@I(Ü_OàöË{ïs%çØ@’>µÊ ^!¹²F'½‘!諲l£_¼q4Íä´ÇE˜Þ¶Rá݃S‚'§ÀnÕ>>±mÝ^\Éw³š´^‰$œ‘ÅXÇ_迦xí±E“à—_.à9} \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/objects/22/ce3e0311dda73a5992d54a4a595518d3876ea7 b/tests-clar/resources/submod2/.gitted/objects/22/ce3e0311dda73a5992d54a4a595518d3876ea7
new file mode 100644
index 000000000..fce6a94b5
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/22/ce3e0311dda73a5992d54a4a595518d3876ea7
@@ -0,0 +1,4 @@
+xµË
+Â0Eݶ_Qº·.
+.ü W"!1 æ!3 øù>+¶Š.¤Û9Ã=3Wº(«nÕ-¶”¥:;¨jòÜ[" WÑ{›¨Þ•ÅQ¤¾ZWï°,2º iviyh •“ÐT/‚=Ž{Ž‡ ¶!@b(¡bÎJcSËP¢¥rÅŒ
+è‡ð¡ã{ë`ì|%³imÐpú콡ÙÄ=ˆIÇÿW2›6‡„B@)|¼óÿ)g£ý™ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/objects/25/5546424b0efb847b1bfc91dbf7348b277f8970 b/tests-clar/resources/submod2/.gitted/objects/25/5546424b0efb847b1bfc91dbf7348b277f8970
new file mode 100644
index 000000000..2965becf6
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/25/5546424b0efb847b1bfc91dbf7348b277f8970
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/2a/30f1e6f94b20917005a21273f65b406d0f8bad b/tests-clar/resources/submod2/.gitted/objects/2a/30f1e6f94b20917005a21273f65b406d0f8bad
new file mode 100644
index 000000000..08faf0fa8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/2a/30f1e6f94b20917005a21273f65b406d0f8bad
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/42/cfb95cd01bf9225b659b5ee3edcc78e8eeb478 b/tests-clar/resources/submod2/.gitted/objects/42/cfb95cd01bf9225b659b5ee3edcc78e8eeb478
new file mode 100644
index 000000000..ee7848ae6
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/42/cfb95cd01bf9225b659b5ee3edcc78e8eeb478
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/57/958699c2dc394f81cfc76950e9c3ac3025c398 b/tests-clar/resources/submod2/.gitted/objects/57/958699c2dc394f81cfc76950e9c3ac3025c398
new file mode 100644
index 000000000..ca9203a6e
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/57/958699c2dc394f81cfc76950e9c3ac3025c398
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/59/01da4f1c67756eeadc5121d206bec2431f253b b/tests-clar/resources/submod2/.gitted/objects/59/01da4f1c67756eeadc5121d206bec2431f253b
new file mode 100644
index 000000000..9f88f6bdf
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/59/01da4f1c67756eeadc5121d206bec2431f253b
@@ -0,0 +1,2 @@
+x•ŽÛ 1EýNÓ€2yg@D,A°€$;YöE6éßmÁß{Λ·e™(å/­2ƒõdƒ#ÊjÈšL 2—ìYdÊ:fÊž ˆ=V^D’hR Ä$¥^ÃÅ©ÉaŠÆ+tn {ûnÞý8xžáÅsá
+÷šžãÔ¾=Ýò¶<@j£¬CÔ®èŹžÿÚ©þ[ŠÏ>Ä6­#=-ÛÐg?,¯FŒ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/objects/60/7d96653d4d0a4f733107f7890c2e67b55b620d b/tests-clar/resources/submod2/.gitted/objects/60/7d96653d4d0a4f733107f7890c2e67b55b620d
new file mode 100644
index 000000000..30bee40e9
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/60/7d96653d4d0a4f733107f7890c2e67b55b620d
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/74/84482eb8db738cafa696993664607500a3f2b9 b/tests-clar/resources/submod2/.gitted/objects/74/84482eb8db738cafa696993664607500a3f2b9
new file mode 100644
index 000000000..79018042d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/74/84482eb8db738cafa696993664607500a3f2b9
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/7b/a4c5c3561daa5ab1a86215cfb0587e96d404d6 b/tests-clar/resources/submod2/.gitted/objects/7b/a4c5c3561daa5ab1a86215cfb0587e96d404d6
new file mode 100644
index 000000000..cde89e5bb
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/7b/a4c5c3561daa5ab1a86215cfb0587e96d404d6
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/87/3585b94bdeabccea991ea5e3ec1a277895b698 b/tests-clar/resources/submod2/.gitted/objects/87/3585b94bdeabccea991ea5e3ec1a277895b698
new file mode 100644
index 000000000..41af98aa9
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/87/3585b94bdeabccea991ea5e3ec1a277895b698
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/97/4cf7c73de336b0c4e019f918f3cee367d72e84 b/tests-clar/resources/submod2/.gitted/objects/97/4cf7c73de336b0c4e019f918f3cee367d72e84
new file mode 100644
index 000000000..160f1caf4
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/97/4cf7c73de336b0c4e019f918f3cee367d72e84
@@ -0,0 +1,2 @@
+xµË
+Â0Eݶ_º·Bqåg¸ yŒi ™IÀÏ÷Y±Up!ÝÎs¸£|R¬ï7«=’)XCAGä¢:…à25‡º:É<°-û„uUÐ_IÛò‡¤Y¢…\Ϥ%êAF fª{Gß qTœPsï”u¹ã(ÓZ{‰RA ô#ø̉£ó0m¾“Ų.8ïÞÑbáäìÇãÞù?{vÊŒ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/objects/9d/bc299bc013ea253583b40bf327b5a6e4037b89 b/tests-clar/resources/submod2/.gitted/objects/9d/bc299bc013ea253583b40bf327b5a6e4037b89
new file mode 100644
index 000000000..1ee52218d
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/9d/bc299bc013ea253583b40bf327b5a6e4037b89
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/a9/104bf89e911387244ef499413960ba472066d9 b/tests-clar/resources/submod2/.gitted/objects/a9/104bf89e911387244ef499413960ba472066d9
new file mode 100644
index 000000000..2239e14a8
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/a9/104bf89e911387244ef499413960ba472066d9
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/b6/14088620bbdc1d29549d223ceba0f4419fd4cb b/tests-clar/resources/submod2/.gitted/objects/b6/14088620bbdc1d29549d223ceba0f4419fd4cb
new file mode 100644
index 000000000..a03ea66e4
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/b6/14088620bbdc1d29549d223ceba0f4419fd4cb
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/d4/07f19e50c1da1ff584beafe0d6dac7237c5d06 b/tests-clar/resources/submod2/.gitted/objects/d4/07f19e50c1da1ff584beafe0d6dac7237c5d06
new file mode 100644
index 000000000..292303eb9
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/d4/07f19e50c1da1ff584beafe0d6dac7237c5d06
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/d9/3e95571d92cceb5de28c205f1d5f3cc8b88bc8 b/tests-clar/resources/submod2/.gitted/objects/d9/3e95571d92cceb5de28c205f1d5f3cc8b88bc8
new file mode 100644
index 000000000..b92c7eebd
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/d9/3e95571d92cceb5de28c205f1d5f3cc8b88bc8
@@ -0,0 +1,2 @@
+x•ÏÛ
+!€ánק}€ "‚.z’uRÉCx€}üΑۼøt¸ œ.׫Ù6î‚,iŸs&%ãÁ9“S¿#ݲ¦úIW¢=—a˜ßËf2A‹¼BYsÏñßÐa{c±¶^K3g¼Äñ³wMÍ F˜Üúøߥ4sÅçâ€òÇáõÎ÷'Nê°I \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/objects/e3/b83bf274ee065eee48734cf8c6dfaf5e81471c b/tests-clar/resources/submod2/.gitted/objects/e3/b83bf274ee065eee48734cf8c6dfaf5e81471c
new file mode 100644
index 000000000..3c7750b12
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/e3/b83bf274ee065eee48734cf8c6dfaf5e81471c
Binary files differ
diff --git a/tests-clar/resources/submod2/.gitted/objects/f5/4414c25e6d24fe39f5c3f128d7c8a17bc23833 b/tests-clar/resources/submod2/.gitted/objects/f5/4414c25e6d24fe39f5c3f128d7c8a17bc23833
new file mode 100644
index 000000000..219620b25
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/f5/4414c25e6d24fe39f5c3f128d7c8a17bc23833
@@ -0,0 +1,2 @@
+xeÍÁ
+Â0„a¯íS„ÞíbOzð1<I Iº¤¤‘Íû+ˆ‚õ:?|ãsõæt9îh¾Ô¥e6Š- H[´¡–’ÃÜw§«¹šÿØwMò«Œ#½‘ɪ“ÈÚïж…Õm‘—_î; º$ž rò1éDÊPCvB¨Mcø‡ýI^ \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/objects/f9/90a25a74d1a8281ce2ab018ea8df66795cd60b b/tests-clar/resources/submod2/.gitted/objects/f9/90a25a74d1a8281ce2ab018ea8df66795cd60b
new file mode 100644
index 000000000..883a40bfc
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/objects/f9/90a25a74d1a8281ce2ab018ea8df66795cd60b
@@ -0,0 +1 @@
+xEŒA€ =óŠý„ÿáZ)¤RE¿/ñb2·É «1¶uÙsé˜xôÁ§Å¡—îˆä>ßä2<E™nG=2,ýÉœTÄ’’4©Žî4!¼N¬$` \ No newline at end of file
diff --git a/tests-clar/resources/submod2/.gitted/refs/heads/master b/tests-clar/resources/submod2/.gitted/refs/heads/master
new file mode 100644
index 000000000..d1d38aa49
--- /dev/null
+++ b/tests-clar/resources/submod2/.gitted/refs/heads/master
@@ -0,0 +1 @@
+7484482eb8db738cafa696993664607500a3f2b9
diff --git a/tests-clar/resources/submod2/README.txt b/tests-clar/resources/submod2/README.txt
new file mode 100644
index 000000000..f990a25a7
--- /dev/null
+++ b/tests-clar/resources/submod2/README.txt
@@ -0,0 +1,3 @@
+This is the submodule test data
+This repo will have a bunch of submodules in different states
+
diff --git a/tests-clar/resources/submod2/gitmodules b/tests-clar/resources/submod2/gitmodules
new file mode 100644
index 000000000..4c31108ed
--- /dev/null
+++ b/tests-clar/resources/submod2/gitmodules
@@ -0,0 +1,24 @@
+[submodule "sm_missing_commits"]
+ path = sm_missing_commits
+ url = ../submod2_target
+[submodule "sm_unchanged"]
+ path = sm_unchanged
+ url = ../submod2_target
+[submodule "sm_changed_file"]
+ path = sm_changed_file
+ url = ../submod2_target
+[submodule "sm_changed_index"]
+ path = sm_changed_index
+ url = ../submod2_target
+[submodule "sm_changed_head"]
+ path = sm_changed_head
+ url = ../submod2_target
+[submodule "sm_changed_untracked_file"]
+ path = sm_changed_untracked_file
+ url = ../submod2_target
+[submodule "sm_added_and_uncommited"]
+ path = sm_added_and_uncommited
+ url = ../submod2_target
+[submodule "sm_gitmodules_only"]
+ path = sm_gitmodules_only
+ url = ../submod2_target
diff --git a/tests-clar/resources/submod2/just_a_dir/contents b/tests-clar/resources/submod2/just_a_dir/contents
new file mode 100644
index 000000000..7ba4c5c35
--- /dev/null
+++ b/tests-clar/resources/submod2/just_a_dir/contents
@@ -0,0 +1 @@
+This is a file in a plain directory
diff --git a/tests-clar/resources/submod2/just_a_file b/tests-clar/resources/submod2/just_a_file
new file mode 100644
index 000000000..42cfb95cd
--- /dev/null
+++ b/tests-clar/resources/submod2/just_a_file
@@ -0,0 +1 @@
+This is just a plain file
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/HEAD b/tests-clar/resources/submod2/not-submodule/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/config b/tests-clar/resources/submod2/not-submodule/.gitted/config
new file mode 100644
index 000000000..af107929f
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/description b/tests-clar/resources/submod2/not-submodule/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/index b/tests-clar/resources/submod2/not-submodule/.gitted/index
new file mode 100644
index 000000000..f3fafa536
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/info/exclude b/tests-clar/resources/submod2/not-submodule/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/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-clar/resources/submod2/not-submodule/.gitted/logs/HEAD b/tests-clar/resources/submod2/not-submodule/.gitted/logs/HEAD
new file mode 100644
index 000000000..1749e7dff
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 68e92c611b80ee1ed8f38314ff9577f0d15b2444 Russell Belfer <rb@github.com> 1342560358 -0700 commit (initial): Initial commit
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master b/tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..1749e7dff
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 68e92c611b80ee1ed8f38314ff9577f0d15b2444 Russell Belfer <rb@github.com> 1342560358 -0700 commit (initial): Initial commit
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444 b/tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444
new file mode 100644
index 000000000..8892531a7
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444
Binary files differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627 b/tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627
new file mode 100644
index 000000000..c4e1a77d7
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627
Binary files differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e b/tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e
new file mode 100644
index 000000000..e9f1942a9
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e
Binary files differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master b/tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master
new file mode 100644
index 000000000..0bd8514bd
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master
@@ -0,0 +1 @@
+68e92c611b80ee1ed8f38314ff9577f0d15b2444
diff --git a/tests-clar/resources/submod2/not-submodule/README.txt b/tests-clar/resources/submod2/not-submodule/README.txt
new file mode 100644
index 000000000..71ff9927d
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/README.txt
@@ -0,0 +1 @@
+This is a git repo but not a submodule
diff --git a/tests-clar/resources/submod2/not/.gitted/notempty b/tests-clar/resources/submod2/not/.gitted/notempty
new file mode 100644
index 000000000..9b33ac4e4
--- /dev/null
+++ b/tests-clar/resources/submod2/not/.gitted/notempty
@@ -0,0 +1 @@
+fooled you
diff --git a/tests-clar/resources/submod2/not/README.txt b/tests-clar/resources/submod2/not/README.txt
new file mode 100644
index 000000000..4f6935b98
--- /dev/null
+++ b/tests-clar/resources/submod2/not/README.txt
@@ -0,0 +1 @@
+what am I really
diff --git a/tests-clar/resources/submod2/sm_added_and_uncommited/.gitted b/tests-clar/resources/submod2/sm_added_and_uncommited/.gitted
new file mode 100644
index 000000000..2b2a4cf90
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_added_and_uncommited/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_added_and_uncommited
diff --git a/tests-clar/resources/submod2/sm_added_and_uncommited/README.txt b/tests-clar/resources/submod2/sm_added_and_uncommited/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_added_and_uncommited/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_added_and_uncommited/file_to_modify b/tests-clar/resources/submod2/sm_added_and_uncommited/file_to_modify
new file mode 100644
index 000000000..789efbdad
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_added_and_uncommited/file_to_modify
@@ -0,0 +1,3 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
diff --git a/tests-clar/resources/submod2/sm_changed_file/.gitted b/tests-clar/resources/submod2/sm_changed_file/.gitted
new file mode 100644
index 000000000..dc98b1674
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_file/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_changed_file
diff --git a/tests-clar/resources/submod2/sm_changed_file/README.txt b/tests-clar/resources/submod2/sm_changed_file/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_file/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_changed_file/file_to_modify b/tests-clar/resources/submod2/sm_changed_file/file_to_modify
new file mode 100644
index 000000000..e5ba67168
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_file/file_to_modify
@@ -0,0 +1,4 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
+In this case, the file is changed in the workdir
diff --git a/tests-clar/resources/submod2/sm_changed_head/.gitted b/tests-clar/resources/submod2/sm_changed_head/.gitted
new file mode 100644
index 000000000..d5419b62d
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_head/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_changed_head
diff --git a/tests-clar/resources/submod2/sm_changed_head/README.txt b/tests-clar/resources/submod2/sm_changed_head/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_head/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_changed_head/file_to_modify b/tests-clar/resources/submod2/sm_changed_head/file_to_modify
new file mode 100644
index 000000000..8eb1e637e
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_head/file_to_modify
@@ -0,0 +1,4 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
+This one has been changed and the change has been committed to HEAD.
diff --git a/tests-clar/resources/submod2/sm_changed_index/.gitted b/tests-clar/resources/submod2/sm_changed_index/.gitted
new file mode 100644
index 000000000..2c7a5b271
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_index/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_changed_index
diff --git a/tests-clar/resources/submod2/sm_changed_index/README.txt b/tests-clar/resources/submod2/sm_changed_index/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_index/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_changed_index/file_to_modify b/tests-clar/resources/submod2/sm_changed_index/file_to_modify
new file mode 100644
index 000000000..a02d31770
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_index/file_to_modify
@@ -0,0 +1,4 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
+Here the file is changed in the index and the workdir
diff --git a/tests-clar/resources/submod2/sm_changed_untracked_file/.gitted b/tests-clar/resources/submod2/sm_changed_untracked_file/.gitted
new file mode 100644
index 000000000..9a1070647
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_untracked_file/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_changed_untracked_file
diff --git a/tests-clar/resources/submod2/sm_changed_untracked_file/README.txt b/tests-clar/resources/submod2/sm_changed_untracked_file/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_untracked_file/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_changed_untracked_file/file_to_modify b/tests-clar/resources/submod2/sm_changed_untracked_file/file_to_modify
new file mode 100644
index 000000000..789efbdad
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_untracked_file/file_to_modify
@@ -0,0 +1,3 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
diff --git a/tests-clar/resources/submod2/sm_changed_untracked_file/i_am_untracked b/tests-clar/resources/submod2/sm_changed_untracked_file/i_am_untracked
new file mode 100644
index 000000000..d2bae6167
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_changed_untracked_file/i_am_untracked
@@ -0,0 +1 @@
+This file is untracked, but in a submodule
diff --git a/tests-clar/resources/submod2/sm_missing_commits/.gitted b/tests-clar/resources/submod2/sm_missing_commits/.gitted
new file mode 100644
index 000000000..70193be84
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_missing_commits/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_missing_commits
diff --git a/tests-clar/resources/submod2/sm_missing_commits/README.txt b/tests-clar/resources/submod2/sm_missing_commits/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_missing_commits/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_missing_commits/file_to_modify b/tests-clar/resources/submod2/sm_missing_commits/file_to_modify
new file mode 100644
index 000000000..8834b635d
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_missing_commits/file_to_modify
@@ -0,0 +1,3 @@
+This is a file to modify in submodules
+It already has some history.
+
diff --git a/tests-clar/resources/submod2/sm_unchanged/.gitted b/tests-clar/resources/submod2/sm_unchanged/.gitted
new file mode 100644
index 000000000..51a679c80
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_unchanged/.gitted
@@ -0,0 +1 @@
+gitdir: ../.git/modules/sm_unchanged
diff --git a/tests-clar/resources/submod2/sm_unchanged/README.txt b/tests-clar/resources/submod2/sm_unchanged/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_unchanged/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2/sm_unchanged/file_to_modify b/tests-clar/resources/submod2/sm_unchanged/file_to_modify
new file mode 100644
index 000000000..789efbdad
--- /dev/null
+++ b/tests-clar/resources/submod2/sm_unchanged/file_to_modify
@@ -0,0 +1,3 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
diff --git a/tests-clar/resources/submod2_target/.gitted/HEAD b/tests-clar/resources/submod2_target/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2_target/.gitted/config b/tests-clar/resources/submod2_target/.gitted/config
new file mode 100644
index 000000000..af107929f
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/submod2_target/.gitted/description b/tests-clar/resources/submod2_target/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2_target/.gitted/index b/tests-clar/resources/submod2_target/.gitted/index
new file mode 100644
index 000000000..eb3ff8c10
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/info/exclude b/tests-clar/resources/submod2_target/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/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-clar/resources/submod2_target/.gitted/logs/HEAD b/tests-clar/resources/submod2_target/.gitted/logs/HEAD
new file mode 100644
index 000000000..0ecd1113f
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/logs/HEAD
@@ -0,0 +1,4 @@
+0000000000000000000000000000000000000000 6b31c659545507c381e9cd34ec508f16c04e149e Russell Belfer <rb@github.com> 1342559662 -0700 commit (initial): Initial commit
+6b31c659545507c381e9cd34ec508f16c04e149e 41bd4bc3df978de695f67ace64c560913da11653 Russell Belfer <rb@github.com> 1342559709 -0700 commit: Adding test file
+41bd4bc3df978de695f67ace64c560913da11653 5e4963595a9774b90524d35a807169049de8ccad Russell Belfer <rb@github.com> 1342559726 -0700 commit: Updating test file
+5e4963595a9774b90524d35a807169049de8ccad 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342559925 -0700 commit: One more update
diff --git a/tests-clar/resources/submod2_target/.gitted/logs/refs/heads/master b/tests-clar/resources/submod2_target/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..0ecd1113f
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/logs/refs/heads/master
@@ -0,0 +1,4 @@
+0000000000000000000000000000000000000000 6b31c659545507c381e9cd34ec508f16c04e149e Russell Belfer <rb@github.com> 1342559662 -0700 commit (initial): Initial commit
+6b31c659545507c381e9cd34ec508f16c04e149e 41bd4bc3df978de695f67ace64c560913da11653 Russell Belfer <rb@github.com> 1342559709 -0700 commit: Adding test file
+41bd4bc3df978de695f67ace64c560913da11653 5e4963595a9774b90524d35a807169049de8ccad Russell Belfer <rb@github.com> 1342559726 -0700 commit: Updating test file
+5e4963595a9774b90524d35a807169049de8ccad 480095882d281ed676fe5b863569520e54a7d5c0 Russell Belfer <rb@github.com> 1342559925 -0700 commit: One more update
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/submod2_target/.gitted/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/submod2_target/.gitted/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/submod2_target/.gitted/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/submod2_target/.gitted/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/submod2_target/.gitted/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/submod2_target/.gitted/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/submod2_target/.gitted/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/submod2_target/.gitted/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/submod2_target/.gitted/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/submod2_target/.gitted/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/submod2_target/.gitted/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/submod2_target/.gitted/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/submod2_target/.gitted/refs/heads/master b/tests-clar/resources/submod2_target/.gitted/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/submod2_target/.gitted/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/submod2_target/README.txt b/tests-clar/resources/submod2_target/README.txt
new file mode 100644
index 000000000..780d7397f
--- /dev/null
+++ b/tests-clar/resources/submod2_target/README.txt
@@ -0,0 +1,3 @@
+This is the target for submod2 submodule links.
+Don't add commits casually because you make break tests.
+
diff --git a/tests-clar/resources/submod2_target/file_to_modify b/tests-clar/resources/submod2_target/file_to_modify
new file mode 100644
index 000000000..789efbdad
--- /dev/null
+++ b/tests-clar/resources/submod2_target/file_to_modify
@@ -0,0 +1,3 @@
+This is a file to modify in submodules
+It already has some history.
+You can add local changes as needed.
diff --git a/tests-clar/resources/template/branches/.gitignore b/tests-clar/resources/template/branches/.gitignore
new file mode 100644
index 000000000..16868cedb
--- /dev/null
+++ b/tests-clar/resources/template/branches/.gitignore
@@ -0,0 +1,2 @@
+# This file should not be copied, nor should the
+# containing directory, since it is effectively "empty"
diff --git a/tests-clar/resources/template/description b/tests-clar/resources/template/description
new file mode 100644
index 000000000..ff04c4c13
--- /dev/null
+++ b/tests-clar/resources/template/description
@@ -0,0 +1 @@
+Edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/template/hooks/link.sample b/tests-clar/resources/template/hooks/link.sample
new file mode 120000
index 000000000..771acc43b
--- /dev/null
+++ b/tests-clar/resources/template/hooks/link.sample
@@ -0,0 +1 @@
+update.sample \ No newline at end of file
diff --git a/tests-clar/resources/template/hooks/update.sample b/tests-clar/resources/template/hooks/update.sample
new file mode 100755
index 000000000..3b5f41202
--- /dev/null
+++ b/tests-clar/resources/template/hooks/update.sample
@@ -0,0 +1,9 @@
+#!/bin/sh
+#
+# A sample hook to make sure that the `git_repository_init_ext()` function
+# can correctly copy a hook over and set it up with the correct permissions.
+#
+# To enable a hook, you copy the file and remove the ".sample" suffix, but
+# in this case, we're just making sure it gets copied correctly.
+
+echo "$GIT_DIR"
diff --git a/tests-clar/resources/template/info/exclude b/tests-clar/resources/template/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/template/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-clar/resources/testrepo.git/FETCH_HEAD b/tests-clar/resources/testrepo.git/FETCH_HEAD
new file mode 100644
index 000000000..48446265c
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/FETCH_HEAD
@@ -0,0 +1,2 @@
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750 branch 'master' of git://example.com/git/testrepo.git
+258f0e2a959a364e40ed6603d5d44fbb24765b10 not-for-merge branch 'haacked' of git://example.com/git/testrepo.git
diff --git a/tests-clar/resources/testrepo.git/head-tracker b/tests-clar/resources/testrepo.git/HEAD_TRACKER
index 40d876b4c..40d876b4c 100644
--- a/tests-clar/resources/testrepo.git/head-tracker
+++ b/tests-clar/resources/testrepo.git/HEAD_TRACKER
diff --git a/tests-clar/resources/testrepo.git/config b/tests-clar/resources/testrepo.git/config
index 1a5aacdfa..904a4e3f3 100644
--- a/tests-clar/resources/testrepo.git/config
+++ b/tests-clar/resources/testrepo.git/config
@@ -6,3 +6,31 @@
[remote "test"]
url = git://github.com/libgit2/libgit2
fetch = +refs/heads/*:refs/remotes/test/*
+[remote "joshaber"]
+ url = git://github.com/libgit2/libgit2
+[remote "empty-remote-url"]
+ url =
+
+[remote "test_with_pushurl"]
+ url = git://github.com/libgit2/fetchlibgit2
+ pushurl = git://github.com/libgit2/pushlibgit2
+ fetch = +refs/heads/*:refs/remotes/test_with_pushurl/*
+
+[branch "master"]
+ remote = test
+ merge = refs/heads/master
+[branch "track-local"]
+ remote = .
+ merge = refs/heads/master
+[branch "cannot-fetch"]
+ remote = joshaber
+ merge = refs/heads/cannot-fetch
+[branch "remoteless"]
+ remote =
+ merge = refs/heads/master
+[branch "mergeless"]
+ remote = test
+ merge =
+[branch "mergeandremoteless"]
+ remote =
+ merge =
diff --git a/tests-clar/resources/testrepo.git/logs/HEAD b/tests-clar/resources/testrepo.git/logs/HEAD
new file mode 100644
index 000000000..9413b72cc
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/logs/HEAD
@@ -0,0 +1,7 @@
+0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0700 clone: from /Users/ben/src/libgit2/tests/resources/testrepo.git
+be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806603 -0900 commit:
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750 5b5b025afb0b4c913b4c338a42934a3863bf3644 Ben Straub <bstraub@github.com> 1335806604 -0900 checkout: moving from master to 5b5b025
+5b5b025afb0b4c913b4c338a42934a3863bf3644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806605 -0900 checkout: moving from 5b5b025 to master
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750 c47800c7266a2be04c571c04d5a6614691ea99bd Ben Straub <bstraub@github.com> 1335806608 -0900 checkout: moving from master to br2
+c47800c7266a2be04c571c04d5a6614691ea99bd a4a7dce85cf63874e984719f4fdd239f5145052f Ben Straub <bstraub@github.com> 1335806617 -0900 commit: checking in
+a4a7dce85cf63874e984719f4fdd239f5145052f a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806621 -0900 checkout: moving from br2 to master
diff --git a/tests-clar/resources/testrepo.git/logs/refs/heads/br2 b/tests-clar/resources/testrepo.git/logs/refs/heads/br2
new file mode 100644
index 000000000..4e27f6b8d
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/logs/refs/heads/br2
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 c47800c7266a2be04c571c04d5a6614691ea99bd Ben Straub <bstraub@github.com> 1335806608 -0700 branch: Created from refs/remotes/origin/br2
+a4a7dce85cf63874e984719f4fdd239f5145052f a4a7dce85cf63874e984719f4fdd239f5145052f Ben Straub <bstraub@github.com> 1335806617 -0700 commit: checking in
diff --git a/tests-clar/resources/testrepo.git/logs/refs/heads/master b/tests-clar/resources/testrepo.git/logs/refs/heads/master
new file mode 100644
index 000000000..e1c729a45
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/logs/refs/heads/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0800 clone: from /Users/ben/src/libgit2/tests/resources/testrepo.git
+be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806603 -0800 commit: checking in
diff --git a/tests-clar/resources/testrepo.git/logs/refs/heads/not-good b/tests-clar/resources/testrepo.git/logs/refs/heads/not-good
new file mode 100644
index 000000000..bfbeacb8a
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/logs/refs/heads/not-good
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1336761944 -0700 branch: Created from master
diff --git a/tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD b/tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..f1aac6d0f
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0700 clone: from /Users/ben/src/libgit2/tests/resources/testrepo.git
diff --git a/tests-clar/resources/testrepo.git/logs/refs/remotes/test/master b/tests-clar/resources/testrepo.git/logs/refs/remotes/test/master
new file mode 100644
index 000000000..8d49ba3e0
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/logs/refs/remotes/test/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806565 -0800 update by push
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806688 -0800 update by push
diff --git a/tests-clar/resources/testrepo.git/objects/08/b041783f40edfe12bb406c9c9a8a040177c125 b/tests-clar/resources/testrepo.git/objects/08/b041783f40edfe12bb406c9c9a8a040177c125
new file mode 100644
index 000000000..d1c032fce
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/08/b041783f40edfe12bb406c9c9a8a040177c125
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd b/tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd
new file mode 100644
index 000000000..3ec541288
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/1b/8cbad43e867676df601306689fe7c3def5e689 b/tests-clar/resources/testrepo.git/objects/1b/8cbad43e867676df601306689fe7c3def5e689
new file mode 100644
index 000000000..6048d4bad
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/1b/8cbad43e867676df601306689fe7c3def5e689
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10 b/tests-clar/resources/testrepo.git/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10
new file mode 100644
index 000000000..cb1ed5712
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/25/8f0e2a959a364e40ed6603d5d44fbb24765b10
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7 b/tests-clar/resources/testrepo.git/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7
new file mode 100644
index 000000000..0a1500a6f
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/2d/59075e0681f540482d4f6223a68e0fef790bc7
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679 b/tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679
new file mode 100644
index 000000000..18e3964b3
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/4b/22b35d44b5a4f589edf3dc89196399771796ea b/tests-clar/resources/testrepo.git/objects/4b/22b35d44b5a4f589edf3dc89196399771796ea
new file mode 100644
index 000000000..b4e5aa186
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/4b/22b35d44b5a4f589edf3dc89196399771796ea
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe b/tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe
new file mode 100644
index 000000000..71019a636
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe
@@ -0,0 +1,2 @@
+xŒM F]sŠ¹€†Ÿ41ÆxÝ(­I‹ÁéÂÛKݽ/_ÞãP@¡ÚÕø¢!8›)es
+” ¥N&FGSÆ„¹hÑ{+ßCç‰÷ÆZzvØF¡7ZàÎ-¬Îñó‡k™x\ã¡[PÆ8ï´ôGØK/¥^© lÊ>.4 \ No newline at end of file
diff --git a/tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2 b/tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2
new file mode 100644
index 000000000..7f1cfb23c
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2
@@ -0,0 +1,2 @@
+xŽM
+Â0F]ç³d2¤ñ®<A~&´`­ÄôþVàæãmïËë²ÌÈÒ¡7Uà$äJöL9yM!¢GuœªH¤&UÈæ›>;ÔÂÁ…¬£³X†ÂEÈŽ5R±£ ÛAÑE &n}ZÜæ<E}À=O[ÒÖáüÞéúÓ¼^À,ã^†#¢É¿ƒ]ÿPÍ`>™A¹ \ No newline at end of file
diff --git a/tests-clar/resources/testrepo.git/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659 b/tests-clar/resources/testrepo.git/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659
new file mode 100644
index 000000000..f3b46b3ca
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/d0/7b0f9a8c89f1d9e74dc4fce6421dec5ef8a659
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759 b/tests-clar/resources/testrepo.git/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759
new file mode 100644
index 000000000..2d47e6faf
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/d7/1aab4f9b04b45ce09bcaa636a9be6231474759
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09 b/tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09
new file mode 100644
index 000000000..158aef21f
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09
Binary files differ
diff --git a/tests-clar/resources/testrepo.git/refs/heads/cannot-fetch b/tests-clar/resources/testrepo.git/refs/heads/cannot-fetch
new file mode 100644
index 000000000..aab87e5e7
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/cannot-fetch
@@ -0,0 +1 @@
+a4a7dce85cf63874e984719f4fdd239f5145052f
diff --git a/tests-clar/resources/testrepo.git/refs/heads/chomped b/tests-clar/resources/testrepo.git/refs/heads/chomped
new file mode 100644
index 000000000..0166a7f92
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/chomped
@@ -0,0 +1 @@
+e90810b8df3e80c413d903f631643c716887138d \ No newline at end of file
diff --git a/tests-clar/resources/testrepo.git/refs/heads/haacked b/tests-clar/resources/testrepo.git/refs/heads/haacked
new file mode 100644
index 000000000..17f591222
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/haacked
@@ -0,0 +1 @@
+258f0e2a959a364e40ed6603d5d44fbb24765b10
diff --git a/tests-clar/resources/testrepo.git/refs/heads/not-good b/tests-clar/resources/testrepo.git/refs/heads/not-good
new file mode 100644
index 000000000..3d8f0a402
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/not-good
@@ -0,0 +1 @@
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750
diff --git a/tests-clar/resources/testrepo.git/refs/heads/track-local b/tests-clar/resources/testrepo.git/refs/heads/track-local
new file mode 100644
index 000000000..f37febb2c
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/track-local
@@ -0,0 +1 @@
+9fd738e8f7967c078dceed8190330fc8648ee56a
diff --git a/tests-clar/resources/testrepo.git/refs/heads/trailing b/tests-clar/resources/testrepo.git/refs/heads/trailing
new file mode 100644
index 000000000..2a4a6e62f
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/trailing
@@ -0,0 +1 @@
+e90810b8df3e80c413d903f631643c716887138d
diff --git a/tests-clar/resources/testrepo.git/refs/notes/fanout b/tests-clar/resources/testrepo.git/refs/notes/fanout
new file mode 100644
index 000000000..1f1703631
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/notes/fanout
@@ -0,0 +1 @@
+d07b0f9a8c89f1d9e74dc4fce6421dec5ef8a659
diff --git a/tests-clar/resources/testrepo.git/refs/remotes/test/master b/tests-clar/resources/testrepo.git/refs/remotes/test/master
new file mode 100644
index 000000000..9536ad89c
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/remotes/test/master
@@ -0,0 +1 @@
+be3563ae3f795b2b4353bcce3a527ad0a4f7f644
diff --git a/tests-clar/resources/testrepo.git/refs/tags/hard_tag b/tests-clar/resources/testrepo.git/refs/tags/hard_tag
new file mode 100644
index 000000000..59ce65649
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/tags/hard_tag
@@ -0,0 +1 @@
+849a5e34a26815e821f865b8479f5815a47af0fe
diff --git a/tests-clar/resources/testrepo.git/refs/tags/taggerless b/tests-clar/resources/testrepo.git/refs/tags/taggerless
new file mode 100644
index 000000000..f960c7d62
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/tags/taggerless
@@ -0,0 +1 @@
+4a23e2e65ad4e31c4c9db7dc746650bfad082679
diff --git a/tests-clar/resources/testrepo.git/refs/tags/wrapped_tag b/tests-clar/resources/testrepo.git/refs/tags/wrapped_tag
new file mode 100644
index 000000000..59ce65649
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/tags/wrapped_tag
@@ -0,0 +1 @@
+849a5e34a26815e821f865b8479f5815a47af0fe
diff --git a/tests-clar/resources/testrepo/.gitted/head-tracker b/tests-clar/resources/testrepo/.gitted/HEAD_TRACKER
index 40d876b4c..40d876b4c 100644
--- a/tests-clar/resources/testrepo/.gitted/head-tracker
+++ b/tests-clar/resources/testrepo/.gitted/HEAD_TRACKER
diff --git a/tests-clar/resources/testrepo/.gitted/config b/tests-clar/resources/testrepo/.gitted/config
index 1a5aacdfa..d0114012f 100644
--- a/tests-clar/resources/testrepo/.gitted/config
+++ b/tests-clar/resources/testrepo/.gitted/config
@@ -1,7 +1,7 @@
[core]
repositoryformatversion = 0
filemode = true
- bare = true
+ bare = false
logallrefupdates = true
[remote "test"]
url = git://github.com/libgit2/libgit2
diff --git a/tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff b/tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff
new file mode 100644
index 000000000..c60c78fb5
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff
@@ -0,0 +1 @@
+xÎQ P¿9Å^@³ÂB!1F½‚'€î¢ÒJ?¼½Õ#ø7™ÉK¦ŸJhM›VE€,³·.3û¼§Þ¦ˆ‚ÔuVsHè-;õŠUÆÑÙ,œMˆ’…P³Iɉ&ÎÄ”×ìסŠK»O.2µո$8¤ùN·¡Ý—´ë§r„½!½l±CTk»lòUgfˆ0¿ËsêÓG( \ No newline at end of file
diff --git a/tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e b/tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e
new file mode 100644
index 000000000..b7d944fa1
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/14/4344043ba4d4a405da03de3844aa829ae8be0e
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925 b/tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925
new file mode 100644
index 000000000..d37b93e4f
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/16/8e4ebd1c667499548ae12403b19b22a5c5e925
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6 b/tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6
new file mode 100644
index 000000000..a83ed9763
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63 b/tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63
new file mode 100644
index 000000000..e9150214b
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/4e/0883eeeeebc1fb1735161cea82f7cb5fab7e63
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc b/tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc
new file mode 100644
index 000000000..b669961d8
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/62/eb56dabb4b9929bc15dd9263c2c733b13d2dcc
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735 b/tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735
new file mode 100644
index 000000000..9ff5eb2b5
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/66/3adb09143767984f7be83a91effa47e128c735
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80 b/tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80
new file mode 100644
index 000000000..3042f5790
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e b/tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e
new file mode 100644
index 000000000..0401ab489
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9 b/tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9
new file mode 100644
index 000000000..7620c514f
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/cf/80f8de9f1185bf3a05f993f6121880dd0cfbc9
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83 b/tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83
new file mode 100644
index 000000000..00940f0f2
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/objects/d5/2a8fe84ceedf260afe4f0287bbfca04a117e83
Binary files differ
diff --git a/tests-clar/resources/testrepo/.gitted/packed-refs b/tests-clar/resources/testrepo/.gitted/packed-refs
index 52f5e876f..6018a19d2 100644
--- a/tests-clar/resources/testrepo/.gitted/packed-refs
+++ b/tests-clar/resources/testrepo/.gitted/packed-refs
@@ -1,3 +1,4 @@
# pack-refs with: peeled
41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/heads/packed
5b5b025afb0b4c913b4c338a42934a3863bf3644 refs/heads/packed-test
+b25fa35b38051e4ae45d4222e795f9df2e43f1d1 refs/tags/packed-tag
diff --git a/tests-clar/resources/testrepo/.gitted/refs/heads/dir b/tests-clar/resources/testrepo/.gitted/refs/heads/dir
new file mode 100644
index 000000000..4567d37fa
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/refs/heads/dir
@@ -0,0 +1 @@
+144344043ba4d4a405da03de3844aa829ae8be0e
diff --git a/tests-clar/resources/testrepo/.gitted/refs/heads/master b/tests-clar/resources/testrepo/.gitted/refs/heads/master
index 3d8f0a402..f31fe781b 100644
--- a/tests-clar/resources/testrepo/.gitted/refs/heads/master
+++ b/tests-clar/resources/testrepo/.gitted/refs/heads/master
@@ -1 +1 @@
-a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+099fabac3a9ea935598528c27f866e34089c2eff
diff --git a/tests-clar/resources/testrepo/.gitted/refs/tags/foo/bar b/tests-clar/resources/testrepo/.gitted/refs/tags/foo/bar
new file mode 100644
index 000000000..6ee952a03
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/refs/tags/foo/bar
@@ -0,0 +1 @@
+b25fa35b38051e4ae45d4222e795f9df2e43f1d1
diff --git a/tests-clar/resources/testrepo/.gitted/refs/tags/foo/foo/bar b/tests-clar/resources/testrepo/.gitted/refs/tags/foo/foo/bar
new file mode 100644
index 000000000..6ee952a03
--- /dev/null
+++ b/tests-clar/resources/testrepo/.gitted/refs/tags/foo/foo/bar
@@ -0,0 +1 @@
+b25fa35b38051e4ae45d4222e795f9df2e43f1d1
diff --git a/tests-clar/resources/twowaymerge.git/HEAD b/tests-clar/resources/twowaymerge.git/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/twowaymerge.git/config b/tests-clar/resources/twowaymerge.git/config
new file mode 100644
index 000000000..c53d818dd
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/config
@@ -0,0 +1,5 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+ ignorecase = true
diff --git a/tests-clar/resources/twowaymerge.git/description b/tests-clar/resources/twowaymerge.git/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/twowaymerge.git/info/exclude b/tests-clar/resources/twowaymerge.git/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/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-clar/resources/twowaymerge.git/objects/0c/8a3f1f3d5f421cf83048c7c73ee3b55a5e0f29 b/tests-clar/resources/twowaymerge.git/objects/0c/8a3f1f3d5f421cf83048c7c73ee3b55a5e0f29
new file mode 100644
index 000000000..12698affa
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/0c/8a3f1f3d5f421cf83048c7c73ee3b55a5e0f29
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/10/2dce8e3081f398e4bdd9fd894dc85ac3ca6a67 b/tests-clar/resources/twowaymerge.git/objects/10/2dce8e3081f398e4bdd9fd894dc85ac3ca6a67
new file mode 100644
index 000000000..3806ee74c
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/10/2dce8e3081f398e4bdd9fd894dc85ac3ca6a67
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/17/7d8634a28e26ec7819284752757ebe01a479d5 b/tests-clar/resources/twowaymerge.git/objects/17/7d8634a28e26ec7819284752757ebe01a479d5
new file mode 100644
index 000000000..e91e06db2
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/17/7d8634a28e26ec7819284752757ebe01a479d5
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/1c/30b88f5f3ee66d78df6520a7de9e89b890818b b/tests-clar/resources/twowaymerge.git/objects/1c/30b88f5f3ee66d78df6520a7de9e89b890818b
new file mode 100644
index 000000000..57d1a0f1e
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/1c/30b88f5f3ee66d78df6520a7de9e89b890818b
@@ -0,0 +1,3 @@
+xŽM
+Â0F]çsËÌä§ ˆ¸Üz‚Iš¶Ši¤¦÷·^Áå{<>¾TKy4`6‡¶æ š,y’9j§GJì8ÁÇÞb¢‘\Œfõ–5/ Ç^‰8v¹'ö‚ÙËœì`SÆ%[›ë
+÷T[ƒ[×úŠ,púüÌsºL6o±Kµœ´5Ø;ŽèÕn÷›-ÿ= ²úÿDà \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/1f/4c0311a24b63f6fc209a59a1e404942d4a5006 b/tests-clar/resources/twowaymerge.git/objects/1f/4c0311a24b63f6fc209a59a1e404942d4a5006
new file mode 100644
index 000000000..99288fdd7
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/1f/4c0311a24b63f6fc209a59a1e404942d4a5006
@@ -0,0 +1,2 @@
+xÍ=Â0 @aæœÂ ²Mê6BlH¬œ ¿m!RqïO¹ë7¼[­‹ rÐ5g°N’Xƒ‹Å±)Eg]ÏDY2c R8xã7Û
+ØTáÞÁ­½Rõo8~òœ®Ó¢óºØêèÔ[”™àˆ#¢Ùußjþ;`¼ùÔÙ7ó \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/22/24e191514cb4bd8c566d80dac22dfcb1e9bb83 b/tests-clar/resources/twowaymerge.git/objects/22/24e191514cb4bd8c566d80dac22dfcb1e9bb83
new file mode 100644
index 000000000..48466ea51
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/22/24e191514cb4bd8c566d80dac22dfcb1e9bb83
@@ -0,0 +1,3 @@
+xŽK
+Â0@]çsK&¤ ˆ¸Üz‚™4éÛHMïo½‚Û÷àñbY–©‚1tª[JàbŽlɈµâ¥í4vÉ¡±Lâ³ ì'—Õ›·´V`B¦û .
+ëÎIöm ï1õZ¨Ç x¯cÙàK­ðhà^^ýÂ+\>?2·aªã.M,Ë°µtTB‹pÖ^kuÐc³¦¿jV_«sFh \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/29/6e56023cdc034d2735fee8c0d85a659d1b07f4 b/tests-clar/resources/twowaymerge.git/objects/29/6e56023cdc034d2735fee8c0d85a659d1b07f4
new file mode 100644
index 000000000..aa3fccdf0
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/29/6e56023cdc034d2735fee8c0d85a659d1b07f4
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/31/51880ae2b363f1c262cf98b750c1f169a0d432 b/tests-clar/resources/twowaymerge.git/objects/31/51880ae2b363f1c262cf98b750c1f169a0d432
new file mode 100644
index 000000000..235d42bff
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/31/51880ae2b363f1c262cf98b750c1f169a0d432
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/3b/287f8730c81d0b763c2d294618a5e32b67b4f8 b/tests-clar/resources/twowaymerge.git/objects/3b/287f8730c81d0b763c2d294618a5e32b67b4f8
new file mode 100644
index 000000000..56ddac5ee
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/3b/287f8730c81d0b763c2d294618a5e32b67b4f8
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/42/b7311aa626e712891940c1ec5d5cba201946a4 b/tests-clar/resources/twowaymerge.git/objects/42/b7311aa626e712891940c1ec5d5cba201946a4
new file mode 100644
index 000000000..a8e6581f8
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/42/b7311aa626e712891940c1ec5d5cba201946a4
@@ -0,0 +1,3 @@
+xν Â0@ajOq cßù"!D‡DËþKÂ1
+Îþ„h_ñéÅZÊ£AßÛC[s†aÌÈžp´I³±‰#‹„lB…œqÈêí×¼4ðZ"¡Ç(œyGF¢¢ød#y«ò[›ë
+÷X[ƒ[×úJÅ/púüÊsºL6o¡‹µœA²èX„ሂ¨öºo¶ü7 ’úÔ¸Ec \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/49/6d6428b9cf92981dc9495211e6e1120fb6f2ba b/tests-clar/resources/twowaymerge.git/objects/49/6d6428b9cf92981dc9495211e6e1120fb6f2ba
new file mode 100644
index 000000000..978bc3448
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/49/6d6428b9cf92981dc9495211e6e1120fb6f2ba
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/59/b0cf7d74659e1cdb13305319d6d4ce2733c118 b/tests-clar/resources/twowaymerge.git/objects/59/b0cf7d74659e1cdb13305319d6d4ce2733c118
new file mode 100644
index 000000000..30b507c06
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/59/b0cf7d74659e1cdb13305319d6d4ce2733c118
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/6a/b5d28acbf3c3bdff276f7ccfdf29c1520e542f b/tests-clar/resources/twowaymerge.git/objects/6a/b5d28acbf3c3bdff276f7ccfdf29c1520e542f
new file mode 100644
index 000000000..ff6a386ac
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/6a/b5d28acbf3c3bdff276f7ccfdf29c1520e542f
@@ -0,0 +1 @@
+xÎM‚0@a×=Å\@2ýcÜ™¸õeÚ†Rƒåþâܾŗǵ”¹RæÔ¶”@¢Šœ(i$™uOÉ 1ö9Ro"“ ¬9¸à¼x‡-­ ü@¬µcc3;ê-KvHÊ+‡9ÙèÁFe¼{›êO®­Á£ƒ{]b +\>¿òoãܦ}踖+Hm zšàŒ„(Žzl¶ô7 ñ•œF- \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/6c/fca542b55b8b37017e6125a4b8f59a6eae6f11 b/tests-clar/resources/twowaymerge.git/objects/6c/fca542b55b8b37017e6125a4b8f59a6eae6f11
new file mode 100644
index 000000000..9a969a279
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/6c/fca542b55b8b37017e6125a4b8f59a6eae6f11
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/76/5b32c65d38f04c4f287abda055818ec0f26912 b/tests-clar/resources/twowaymerge.git/objects/76/5b32c65d38f04c4f287abda055818ec0f26912
new file mode 100644
index 000000000..493bbc076
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/76/5b32c65d38f04c4f287abda055818ec0f26912
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/7b/8c336c45fc6895c1c60827260fe5d798e5d247 b/tests-clar/resources/twowaymerge.git/objects/7b/8c336c45fc6895c1c60827260fe5d798e5d247
new file mode 100644
index 000000000..19e7ef463
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/7b/8c336c45fc6895c1c60827260fe5d798e5d247
@@ -0,0 +1,3 @@
+xÎA @Qלb.`3 S(‰1îLÜz‚B[µÅTzëܾÅÏež§
+D|¨kJCß3f‰´íȵœ‚uÙ ›L>YGMÌV½eMK9¢ÑZˆƒ5ÙæHè¥õ¢#{¦ž¥E´J¶:–î±Ô
+·®åÕϲÀéó“Çp¦:n¡‰e>ƒ6-£sH GìÕ®ûfMÔS}ZE² \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/82/bf9a1a10a4b25c1f14c9607b60970705e92545 b/tests-clar/resources/twowaymerge.git/objects/82/bf9a1a10a4b25c1f14c9607b60970705e92545
new file mode 100644
index 000000000..89b0b9f9b
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/82/bf9a1a10a4b25c1f14c9607b60970705e92545
@@ -0,0 +1 @@
+xŽË Â09»Šm€hã_ÖBܸRן„cœþ1-p§yšPKy4RÚ–D›GŒF»ÀJvÉFE>‡1#q²Ž j§ÅÛoimbvSŽŠYSbEr²Š¸»Q"eÓÑ{+üÞ–ºÁ=ÔÖà6Àµ¾bñ+œ>?òœ/ó£-;¡–3ŒÊhœ¬C‚#¢è´g¶ô÷XÄÌyF¤ \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/8b/82fb1794cb1c8c7f172ec730a4c2db0ae3e650 b/tests-clar/resources/twowaymerge.git/objects/8b/82fb1794cb1c8c7f172ec730a4c2db0ae3e650
new file mode 100644
index 000000000..8e9b758ea
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/8b/82fb1794cb1c8c7f172ec730a4c2db0ae3e650
@@ -0,0 +1,3 @@
+xν Â0@ajOq ù7BtH´Lp¾ó%A8FÁÙŸ°íW<=ª¥Ì ¬õ‡¶æ x"ÊŽØ$—%1†dÄcÏDNLˆ:Yv=©7®yiÐc
+l¤$Ž\b{‰DÂbOd‚Õ9x+
+·6ÕT[ƒ{·úâ‚ œ??yŽ×qnÓ–:ªåƯcÔÞÁQZ«]÷Í–ÿ¨¢¾7 H† \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/9a/40a2f11c191f180c47e54b11567cb3c1e89b30 b/tests-clar/resources/twowaymerge.git/objects/9a/40a2f11c191f180c47e54b11567cb3c1e89b30
new file mode 100644
index 000000000..1de1224f7
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/9a/40a2f11c191f180c47e54b11567cb3c1e89b30
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/9b/219343610c88a1187c996d0dc58330b55cee28 b/tests-clar/resources/twowaymerge.git/objects/9b/219343610c88a1187c996d0dc58330b55cee28
new file mode 100644
index 000000000..8b64b4381
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/9b/219343610c88a1187c996d0dc58330b55cee28
@@ -0,0 +1,2 @@
+xÏKj1Ьç½óÊFj}Z‚¼3²Ê ¤VÏÇdFA#ß?’\ ËzÅu]—FÓSo" ‰JðÆ& ‚^˜‚Ž,9$G’Eéd)7|¦&[6”(FU"&Žh< ¯FÉc4AÆ¿>"ZÑQ;m9Û\;ïKP%1b9k‰93¤GŸkƒw®½Ãënõ£¬iƒçý[îÓuZúüÈ®ë hã¬"RÞÂY¥†C[]þ=0¼I›rKÏp—¶÷óO:Á²õ
+»pÝʯ _¾(c‡ \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/9f/e06a50f4d1634d6c6879854d01d80857388706 b/tests-clar/resources/twowaymerge.git/objects/9f/e06a50f4d1634d6c6879854d01d80857388706
new file mode 100644
index 000000000..055de0158
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/9f/e06a50f4d1634d6c6879854d01d80857388706
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/a4/1a49f8f5cd9b6cb14a076bf8394881ed0b4d19 b/tests-clar/resources/twowaymerge.git/objects/a4/1a49f8f5cd9b6cb14a076bf8394881ed0b4d19
new file mode 100644
index 000000000..cb4d34e77
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/a4/1a49f8f5cd9b6cb14a076bf8394881ed0b4d19
@@ -0,0 +1,3 @@
+xν Â0@ajOq Ýù7'!D‡DËöÙ A$FÁÙŸ°íW<=©ó<5ÐÚÚZ
+8N(CÈÁzÇ…$'2!Î>[):#D½zǵ, zŽ £MÚ d…=†ä‘t…µ³NÅ­=ê
+w©­Á­ƒk}å9.púüä9^Æ©=¶ÔIÏ@ÆY ž‰áˆ=¢ÚußlåÔ°Dâ \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/a9/53a018c5b10b20c86e69fef55ebc8ad4c5a417 b/tests-clar/resources/twowaymerge.git/objects/a9/53a018c5b10b20c86e69fef55ebc8ad4c5a417
new file mode 100644
index 000000000..8235f1839
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/a9/53a018c5b10b20c86e69fef55ebc8ad4c5a417
@@ -0,0 +1 @@
+xÍJÄ0…]÷)înV3$¹is"îÁ•Oû“NŶ’ɼ¿ñ\žï|8²¯ëÒ!dzèÍ ªÔdXG/ޫϹp*‰¢C³X³ˆº@ZÂ8|•f[VŸ0HD™H“E]6¯”g¶I#g«*ñÏ­9UEæHÆH!MḦÕñh‚ºR¦¡Üûuoð.{ïðz—ýSײÁãí‡|ÌÏóÒ¯w¾È¾>Ç1º4‘C8;rn8èq«Û¿†7k³·²ÉNui·~þM§áÜ^­ \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/a9/cce3cd1b3efbda5b1f4a6dcc3f1570b2d3d74c b/tests-clar/resources/twowaymerge.git/objects/a9/cce3cd1b3efbda5b1f4a6dcc3f1570b2d3d74c
new file mode 100644
index 000000000..4da7e826a
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/a9/cce3cd1b3efbda5b1f4a6dcc3f1570b2d3d74c
@@ -0,0 +1 @@
+x+)JMU044c040031QHdx6÷ÑìM¯9{wk®+ºqèIOðD¨d6>É|’¹X%>½9j \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/bd/1732c43c68d712ad09e1d872b9be6d4b9efdc4 b/tests-clar/resources/twowaymerge.git/objects/bd/1732c43c68d712ad09e1d872b9be6d4b9efdc4
new file mode 100644
index 000000000..b9b60122d
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/bd/1732c43c68d712ad09e1d872b9be6d4b9efdc4
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/c3/7a783c20d92ac92362a78a32860f7eebf938ef b/tests-clar/resources/twowaymerge.git/objects/c3/7a783c20d92ac92362a78a32860f7eebf938ef
new file mode 100644
index 000000000..041e890ab
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/c3/7a783c20d92ac92362a78a32860f7eebf938ef
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/cb/dd40facab1682754eb67f7a43f29e672903cf6 b/tests-clar/resources/twowaymerge.git/objects/cb/dd40facab1682754eb67f7a43f29e672903cf6
new file mode 100644
index 000000000..ccb156d88
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/cb/dd40facab1682754eb67f7a43f29e672903cf6
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/cd/f97fd3bb48eb3827638bb33d208f5fd32d0aa6 b/tests-clar/resources/twowaymerge.git/objects/cd/f97fd3bb48eb3827638bb33d208f5fd32d0aa6
new file mode 100644
index 000000000..0e028dc01
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/cd/f97fd3bb48eb3827638bb33d208f5fd32d0aa6
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/d6/f10d549cb335b9e6d38afc1f0088be69b50494 b/tests-clar/resources/twowaymerge.git/objects/d6/f10d549cb335b9e6d38afc1f0088be69b50494
new file mode 100644
index 000000000..b298c520e
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/d6/f10d549cb335b9e6d38afc1f0088be69b50494
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/d9/acdc7ae7632adfeec67fa73c1e343cf4d1f47e b/tests-clar/resources/twowaymerge.git/objects/d9/acdc7ae7632adfeec67fa73c1e343cf4d1f47e
new file mode 100644
index 000000000..de94528a4
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/d9/acdc7ae7632adfeec67fa73c1e343cf4d1f47e
@@ -0,0 +1 @@
+x+)JMU044c040031QHdx6÷ÑìM¯9{wk®+ºqèIOðD¨d>É4|’éX%:79U \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests-clar/resources/twowaymerge.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 000000000..711223894
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/objects/ef/0488f0b722f0be8bcb90a7730ac7efafd1d694 b/tests-clar/resources/twowaymerge.git/objects/ef/0488f0b722f0be8bcb90a7730ac7efafd1d694
new file mode 100644
index 000000000..00f7d3615
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/ef/0488f0b722f0be8bcb90a7730ac7efafd1d694
@@ -0,0 +1 @@
+xŽM F]sŠ¹€Í0Ã_cÜ™¸õ@¡ÕH1•Þ_¼‚Û—ï}y±–òh@¤mK 8³ÙYÆèä„ÁŽ4ѨŒt^'¦`lPÙ‰·ßÒÚ Ï<g™yÒY‘ŒÙ1*m´œ­»„™Fá÷¶Ô ·®õ5¿Âéó#Ïù2?Ú²‡!ÖrÉZ¡5ÆŽpD‡(:í™-ý} ²ø#E¸ \ No newline at end of file
diff --git a/tests-clar/resources/twowaymerge.git/objects/fc/f7e3f51c11d199ab7a78403ee4f9ccd028da25 b/tests-clar/resources/twowaymerge.git/objects/fc/f7e3f51c11d199ab7a78403ee4f9ccd028da25
new file mode 100644
index 000000000..54989ea87
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/objects/fc/f7e3f51c11d199ab7a78403ee4f9ccd028da25
Binary files differ
diff --git a/tests-clar/resources/twowaymerge.git/refs/heads/first-branch b/tests-clar/resources/twowaymerge.git/refs/heads/first-branch
new file mode 100644
index 000000000..ef0dead7f
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/refs/heads/first-branch
@@ -0,0 +1 @@
+2224e191514cb4bd8c566d80dac22dfcb1e9bb83
diff --git a/tests-clar/resources/twowaymerge.git/refs/heads/master b/tests-clar/resources/twowaymerge.git/refs/heads/master
new file mode 100644
index 000000000..ebf18f58e
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/refs/heads/master
@@ -0,0 +1 @@
+1c30b88f5f3ee66d78df6520a7de9e89b890818b
diff --git a/tests-clar/resources/twowaymerge.git/refs/heads/second-branch b/tests-clar/resources/twowaymerge.git/refs/heads/second-branch
new file mode 100644
index 000000000..586a14a84
--- /dev/null
+++ b/tests-clar/resources/twowaymerge.git/refs/heads/second-branch
@@ -0,0 +1 @@
+9b219343610c88a1187c996d0dc58330b55cee28
diff --git a/tests-clar/resources/typechanges/.gitted/HEAD b/tests-clar/resources/typechanges/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/config b/tests-clar/resources/typechanges/.gitted/config
new file mode 100644
index 000000000..4cc6e1ddf
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/config
@@ -0,0 +1,12 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[submodule "e"]
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[submodule "d"]
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[submodule "b"]
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
diff --git a/tests-clar/resources/typechanges/.gitted/description b/tests-clar/resources/typechanges/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/index b/tests-clar/resources/typechanges/.gitted/index
new file mode 100644
index 000000000..4f6d12a3b
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/info/exclude b/tests-clar/resources/typechanges/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/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-clar/resources/typechanges/.gitted/modules/b/HEAD b/tests-clar/resources/typechanges/.gitted/modules/b/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/config b/tests-clar/resources/typechanges/.gitted/modules/b/config
new file mode 100644
index 000000000..f57cd4a6f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../b
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/description b/tests-clar/resources/typechanges/.gitted/modules/b/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/index b/tests-clar/resources/typechanges/.gitted/modules/b/index
new file mode 100644
index 000000000..c16a026b7
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/index
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/info/exclude b/tests-clar/resources/typechanges/.gitted/modules/b/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/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-clar/resources/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/packed-refs b/tests-clar/resources/typechanges/.gitted/modules/b/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master b/tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD b/tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/HEAD b/tests-clar/resources/typechanges/.gitted/modules/d/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/config b/tests-clar/resources/typechanges/.gitted/modules/d/config
new file mode 100644
index 000000000..42e1bddda
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../d
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/description b/tests-clar/resources/typechanges/.gitted/modules/d/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/index b/tests-clar/resources/typechanges/.gitted/modules/d/index
new file mode 100644
index 000000000..86d0266e8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/index
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/info/exclude b/tests-clar/resources/typechanges/.gitted/modules/d/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/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-clar/resources/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/packed-refs b/tests-clar/resources/typechanges/.gitted/modules/d/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master b/tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD b/tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/HEAD b/tests-clar/resources/typechanges/.gitted/modules/e/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/config b/tests-clar/resources/typechanges/.gitted/modules/e/config
new file mode 100644
index 000000000..89b3b9b4f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/config
@@ -0,0 +1,13 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../e
+ ignorecase = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/description b/tests-clar/resources/typechanges/.gitted/modules/e/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/index b/tests-clar/resources/typechanges/.gitted/modules/e/index
new file mode 100644
index 000000000..cd6e2da6c
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/index
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/info/exclude b/tests-clar/resources/typechanges/.gitted/modules/e/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/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-clar/resources/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 000000000..f4b7094c5
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 000000000..56c845e49
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 000000000..bd179b5f5
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 000000000..ccf49bd15
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 000000000..53029069a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 000000000..38c791eba
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccad
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 000000000..a26d29993
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+x•Q
+!EûvoÅÓy*Ñ_¿í@Çg#h‚£ûOhý^Î9w«¥¤ÒêSoÌ€f1*²ŠÁ[”‰¬§èIc Ô¤ìê¤p£ïµÁkç Α\›¿¿S߇¿lµÜ@.¤´^QpF‹(æ:ÿúDÿ5Åó“zr~ ñen8 \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 000000000..83d1ba481
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babf
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 000000000..6d27af8a8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-Ë1Â0 FaæžâßØ0pŽÀìÄÐ(N-ÅöÐÛÓ¡Ò“¾é±ãq]>ksÅ*š? |m“‡Õçiª@ÛÖý¶¼m»¨V£…£'©î`)”.Ø-1¨ x
+u„xãòt(+ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 000000000..17458840b
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x Œ± …0 )ÞŠ?= ¥ÉÄNŠlO¤k®¸‹jÛúÿ¹8&„«¨ ãr ”
+ïqJWñ°7¾B<ÉáöfÙìK8­#Q1C-‘"eª·Ì«£Š°ð>¼'@ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 000000000..83cc29fb1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 000000000..55bda40ef
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/packed-refs b/tests-clar/resources/typechanges/.gitted/modules/e/packed-refs
new file mode 100644
index 000000000..5a4ebc47c
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master b/tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master
new file mode 100644
index 000000000..e12c44d7a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD b/tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8 b/tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8
new file mode 100644
index 000000000..f2d02f4f7
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403aff b/tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403aff
new file mode 100644
index 000000000..527964c92
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403aff
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586 b/tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586
new file mode 100644
index 000000000..2694e4fa0
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97 b/tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97
new file mode 100644
index 000000000..032a960b4
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475 b/tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475
new file mode 100644
index 000000000..d32622e67
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02 b/tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02
new file mode 100644
index 000000000..42d5f92f3
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95 b/tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95
new file mode 100644
index 000000000..0a8f32e15
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592 b/tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592
new file mode 100644
index 000000000..52af51f74
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5 b/tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5
new file mode 100644
index 000000000..afafa89f4
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3e b/tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3e
new file mode 100644
index 000000000..9e518fc28
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3e
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeeb b/tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeeb
new file mode 100644
index 000000000..a245727a1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeeb
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0 b/tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0
new file mode 100644
index 000000000..ea35cd311
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0 b/tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0
new file mode 100644
index 000000000..c54817598
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4 b/tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4
new file mode 100644
index 000000000..9fdd8f245
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729 b/tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729
new file mode 100644
index 000000000..d43630f44
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2 b/tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2
new file mode 100644
index 000000000..355ce4b5b
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb b/tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb
new file mode 100644
index 000000000..2b07ad256
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb
@@ -0,0 +1,2 @@
+x•A E]sŠ¹€f€JbŒqçÖ í`I@
+÷—ĸýyïýµäH;ŸZeBrž6L˜P«Yº%8½²&v‹4JmÖ¢ÔÛ^*¼úqpJðà¸Âµúû;¶½ûËZò ¤žœ’Æ 3ZD1Öñ×ú¯)žŸØ"%ø%Ä–38_ \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963ad b/tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963ad
new file mode 100644
index 000000000..6d2da6c93
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963ad
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37ea b/tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37ea
new file mode 100644
index 000000000..3dc333bc6
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37ea
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3 b/tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3
new file mode 100644
index 000000000..02ad0e97a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4a b/tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4a
new file mode 100644
index 000000000..d06b06a52
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4a
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6f b/tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6f
new file mode 100644
index 000000000..5f9ffd4ed
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6f
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7 b/tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7
new file mode 100644
index 000000000..ac17defac
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a b/tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a
new file mode 100644
index 000000000..7ab83aefe
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a
@@ -0,0 +1,5 @@
+x•ŽI
+1E]箕LTˆè ¼A†J·Ðƒ¤Ó÷7WpûyïñÓ¶,ŸZÑ©Uf cXcR ƒC4¼3Y2æ"£NN:ÔHɈo¨¼6 ,µ’žs’ˆòÁjf—#îk½G›¶
+ïcßyžáÉsá
+·ã§MG¼¦m¹ƒ2–´Bò
+.ÒK)úÚÿµŽþkŠ×Ö‘w8ñžCCà \ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29 b/tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29
new file mode 100644
index 000000000..aed4d8165
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447 b/tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447
new file mode 100644
index 000000000..3e02a41b2
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00d b/tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00d
new file mode 100644
index 000000000..fb24100fc
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00d
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707 b/tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707
new file mode 100644
index 000000000..b6b7db785
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0d b/tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0d
new file mode 100644
index 000000000..e1334057c
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0d
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095 b/tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095
new file mode 100644
index 000000000..65f1f530f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7c b/tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7c
new file mode 100644
index 000000000..355faa61f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7c
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3bad b/tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3bad
new file mode 100644
index 000000000..c68fdcfab
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3bad
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7b b/tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7b
new file mode 100644
index 000000000..c9229ba25
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7b
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 000000000..711223894
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46e b/tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46e
new file mode 100644
index 000000000..3962ba6b4
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46e
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779d b/tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779d
new file mode 100644
index 000000000..e3663da9f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779d
Binary files differ
diff --git a/tests-clar/resources/typechanges/.gitted/refs/heads/master b/tests-clar/resources/typechanges/.gitted/refs/heads/master
new file mode 100644
index 000000000..546481a33
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/refs/heads/master
@@ -0,0 +1 @@
+6eae26c90e8ccc4d16208972119c40635489c6f0
diff --git a/tests-clar/resources/typechanges/README.md b/tests-clar/resources/typechanges/README.md
new file mode 100644
index 000000000..1f5a95a9f
--- /dev/null
+++ b/tests-clar/resources/typechanges/README.md
@@ -0,0 +1,43 @@
+This is a test repo for libgit2 where tree entries have type changes
+
+Types
+-----
+
+The key types that could be found in tree entries are:
+
+1. GIT_FILEMODE_NEW = 0000000 (i.e. file does not exist)
+2. GIT_FILEMODE_TREE = 0040000
+3. GIT_FILEMODE_BLOB = 0100644
+4. GIT_FILEMODE_BLOB_EXECUTABLE = 0100755
+5. GIT_FILEMODE_LINK = 0120000
+6. GIT_FILEMODE_COMMIT = 0160000
+
+I will try to have every type of transition somewhere in the history
+of this repo.
+
+Commits
+-------
+
+* `a(1--1) b(1--1) c(1--1) d(1--1) e(1--1)`
+ **Initial commit**<br>
+ `79b9f23e85f55ea36a472a902e875bc1121a94cb`
+* `a(1->2) b(1->3) c(1->4) d(1->5) e(1->6)`
+ **Create content**<br>
+ `9bdb75b73836a99e3dbeea640a81de81031fdc29`
+* `a(2->3) b(3->4) c(4->5) d(5->6) e(6->2)`
+ **Changes #1**<br>
+ `0e7ed140b514b8cae23254cb8656fe1674403aff`
+* `a(3->5) b(4->6) c(5->2) d(6->3) e(2->4)`
+ **Changes #2**<br>
+ `9d0235c7a7edc0889a18f97a42ee6db9fe688447`
+* `a(5->3) b(6->4) c(2->5) d(3->6) e(4->2)`
+ **Changes #3**<br>
+ `9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a`
+* `a(3->2) b(4->3) c(5->4) d(6->5) e(2->6)`
+ **Changes #4**<br>
+ `1b63caae4a5ca96f78e8dfefc376c6a39a142475`<br>
+ Matches **Changes #1** except README.md
+* `a(2->1) b(3->1) c(4->1) d(5->1) e(6->1)`
+ **Changes #5**<br>
+ `6eae26c90e8ccc4d16208972119c40635489c6f0`<br>
+ Matches **Initial commit** except README.md and .gitmodules
diff --git a/tests-clar/resources/typechanges/gitmodules b/tests-clar/resources/typechanges/gitmodules
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests-clar/resources/typechanges/gitmodules
diff --git a/tests-clar/resources/unsymlinked.git/HEAD b/tests-clar/resources/unsymlinked.git/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/unsymlinked.git/config b/tests-clar/resources/unsymlinked.git/config
new file mode 100644
index 000000000..f57351fd5
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/config
@@ -0,0 +1,6 @@
+[core]
+ bare = true
+ repositoryformatversion = 0
+ filemode = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/unsymlinked.git/description b/tests-clar/resources/unsymlinked.git/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/unsymlinked.git/info/exclude b/tests-clar/resources/unsymlinked.git/info/exclude
new file mode 100644
index 000000000..6d05881d3
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/info/exclude
@@ -0,0 +1,2 @@
+# File patterns to ignore; see `git help ignore` for more information.
+# Lines that start with '#' are comments.
diff --git a/tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf b/tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf
new file mode 100644
index 000000000..953262fa9
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b b/tests-clar/resources/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b
new file mode 100644
index 000000000..91ec8fa5e
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c b/tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c
new file mode 100644
index 000000000..94afd01e8
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 b/tests-clar/resources/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773
new file mode 100644
index 000000000..5b33d027c
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c b/tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c
new file mode 100644
index 000000000..67eb14930
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 b/tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27
new file mode 100644
index 000000000..c1ea0de75
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d b/tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d
new file mode 100644
index 000000000..028505563
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 b/tests-clar/resources/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3
new file mode 100644
index 000000000..e866a75a6
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 b/tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230
new file mode 100644
index 000000000..189ab044d
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 b/tests-clar/resources/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6
new file mode 100644
index 000000000..a2ef6be45
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6
@@ -0,0 +1,2 @@
+x•Ž[
+Â0EýÎ*æ_“¤yˆÝ€{˜4ShZ))¸| ®À¯ ÎáN[ks=èKß™Á¶Åš¨[’ÉÈQ"4&&—M*¤i/Þ´óÚ! ‹1† S‰*Ÿ™Añ€ÞGt)¢ò-'UŒ £×m‡ñ7O cc¸Õ¹=zåå´µ;(ãPY«‡+*DqÒó^ç¿E!¥œ*­/Î0¯}Z?<ÒÂPæ…¥øšÈJp \ No newline at end of file
diff --git a/tests-clar/resources/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 b/tests-clar/resources/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7
new file mode 100644
index 000000000..ec274cb1d
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a b/tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a
new file mode 100644
index 000000000..c1b6a5101
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 b/tests-clar/resources/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9
new file mode 100644
index 000000000..ad751adbe
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 b/tests-clar/resources/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006
new file mode 100644
index 000000000..f87cd42fb
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006
Binary files differ
diff --git a/tests-clar/resources/unsymlinked.git/refs/heads/exe-file b/tests-clar/resources/unsymlinked.git/refs/heads/exe-file
new file mode 100644
index 000000000..b96ef46ca
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/refs/heads/exe-file
@@ -0,0 +1 @@
+a8595ccca04f40818ae0155c8f9c77a230e597b6
diff --git a/tests-clar/resources/unsymlinked.git/refs/heads/master b/tests-clar/resources/unsymlinked.git/refs/heads/master
new file mode 100644
index 000000000..96c17ab17
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/refs/heads/master
@@ -0,0 +1 @@
+7fccd75616ec188b8f1b23d67506a334cc34a49d
diff --git a/tests-clar/resources/unsymlinked.git/refs/heads/reg-file b/tests-clar/resources/unsymlinked.git/refs/heads/reg-file
new file mode 100644
index 000000000..b428c00d5
--- /dev/null
+++ b/tests-clar/resources/unsymlinked.git/refs/heads/reg-file
@@ -0,0 +1 @@
+806999882bf91d24241e4077906b9017605eb1f3
diff --git a/tests-clar/revwalk/basic.c b/tests-clar/revwalk/basic.c
index a5a9b2eda..e82776260 100644
--- a/tests-clar/revwalk/basic.c
+++ b/tests-clar/revwalk/basic.c
@@ -1,15 +1,14 @@
#include "clar_libgit2.h"
/*
- $ git log --oneline --graph --decorate
- * a4a7dce (HEAD, br2) Merge branch 'master' into br2
+ * a4a7dce [0] Merge branch 'master' into br2
|\
- | * 9fd738e (master) a fourth commit
- | * 4a202b3 a third commit
- * | c47800c branch commit one
+ | * 9fd738e [1] a fourth commit
+ | * 4a202b3 [2] a third commit
+ * | c47800c [3] branch commit one
|/
- * 5b5b025 another commit
- * 8496071 testing
+ * 5b5b025 [5] another commit
+ * 8496071 [4] testing
*/
static const char *commit_head = "a4a7dce85cf63874e984719f4fdd239f5145052f";
@@ -39,6 +38,10 @@ static const int commit_sorting_time_reverse[][6] = {
{4, 5, 2, 1, 3, 0}
};
+static const int commit_sorting_segment[][6] = {
+ {1, 2, -1, -1, -1, -1}
+};
+
#define commit_count 6
static const int result_bytes = 24;
@@ -57,22 +60,17 @@ static int get_commit_index(git_oid *raw_oid)
return -1;
}
-static int test_walk(git_revwalk *walk, const git_oid *root,
- int flags, const int possible_results[][6], int results_count)
+static int test_walk_only(git_revwalk *walk,
+ const int possible_results[][commit_count], int results_count)
{
git_oid oid;
-
int i;
int result_array[commit_count];
- git_revwalk_sorting(walk, flags);
- git_revwalk_push(walk, root);
-
for (i = 0; i < commit_count; ++i)
result_array[i] = -1;
i = 0;
-
while (git_revwalk_next(&oid, walk) == 0) {
result_array[i++] = get_commit_index(&oid);
/*{
@@ -91,6 +89,15 @@ static int test_walk(git_revwalk *walk, const git_oid *root,
return GIT_ERROR;
}
+static int test_walk(git_revwalk *walk, const git_oid *root,
+ int flags, const int possible_results[][6], int results_count)
+{
+ git_revwalk_sorting(walk, flags);
+ git_revwalk_push(walk, root);
+
+ return test_walk_only(walk, possible_results, results_count);
+}
+
static git_repository *_repo;
static git_revwalk *_walk;
@@ -103,7 +110,9 @@ void test_revwalk_basic__initialize(void)
void test_revwalk_basic__cleanup(void)
{
git_revwalk_free(_walk);
+ _walk = NULL;
git_repository_free(_repo);
+ _repo = NULL;
}
void test_revwalk_basic__sorting_modes(void)
@@ -129,8 +138,8 @@ void test_revwalk_basic__glob_heads(void)
i++;
}
- /* git log --branches --oneline | wc -l => 13 */
- cl_assert(i == 13);
+ /* git log --branches --oneline | wc -l => 14 */
+ cl_assert(i == 14);
}
void test_revwalk_basic__push_head(void)
@@ -179,3 +188,19 @@ void test_revwalk_basic__push_head_hide_ref_nobase(void)
/* git log HEAD --oneline --not refs/heads/packed | wc -l => 7 */
cl_assert(i == 7);
}
+
+void test_revwalk_basic__disallow_non_commit(void)
+{
+ git_oid oid;
+
+ cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"));
+ cl_git_fail(git_revwalk_push(_walk, &oid));
+}
+
+void test_revwalk_basic__push_range(void)
+{
+ git_revwalk_reset(_walk);
+ git_revwalk_sorting(_walk, 0);
+ cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e"));
+ cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 1));
+}
diff --git a/tests-clar/revwalk/mergebase.c b/tests-clar/revwalk/mergebase.c
index e807e3ad2..e2617ab0e 100644
--- a/tests-clar/revwalk/mergebase.c
+++ b/tests-clar/revwalk/mergebase.c
@@ -1,73 +1,204 @@
#include "clar_libgit2.h"
+#include "vector.h"
+#include <stdarg.h>
static git_repository *_repo;
+static git_repository *_repo2;
void test_revwalk_mergebase__initialize(void)
{
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_open(&_repo2, cl_fixture("twowaymerge.git")));
}
void test_revwalk_mergebase__cleanup(void)
{
git_repository_free(_repo);
+ _repo = NULL;
+
+ git_repository_free(_repo2);
+ _repo2 = NULL;
}
void test_revwalk_mergebase__single1(void)
{
git_oid result, one, two, expected;
+ size_t ahead, behind;
- git_oid_fromstr(&one, "c47800c7266a2be04c571c04d5a6614691ea99bd ");
- git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a");
- git_oid_fromstr(&expected, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ cl_git_pass(git_oid_fromstr(&one, "c47800c7266a2be04c571c04d5a6614691ea99bd "));
+ cl_git_pass(git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
+ cl_git_pass(git_oid_fromstr(&expected, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
cl_git_pass(git_merge_base(&result, _repo, &one, &two));
cl_assert(git_oid_cmp(&result, &expected) == 0);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two));
+ cl_assert_equal_sz(ahead, 2);
+ cl_assert_equal_sz(behind, 1);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &two, &one));
+ cl_assert_equal_sz(ahead, 1);
+ cl_assert_equal_sz(behind, 2);
}
void test_revwalk_mergebase__single2(void)
{
git_oid result, one, two, expected;
+ size_t ahead, behind;
- git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af");
- git_oid_fromstr(&two, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
- git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ cl_git_pass(git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af"));
+ cl_git_pass(git_oid_fromstr(&two, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
+ cl_git_pass(git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_merge_base(&result, _repo, &one, &two));
cl_assert(git_oid_cmp(&result, &expected) == 0);
+
+ cl_git_pass(git_graph_ahead_behind( &ahead, &behind, _repo, &one, &two));
+ cl_assert_equal_sz(ahead, 4);
+ cl_assert_equal_sz(behind, 1);
+
+ cl_git_pass(git_graph_ahead_behind( &ahead, &behind, _repo, &two, &one));
+ cl_assert_equal_sz(ahead, 1);
+ cl_assert_equal_sz(behind, 4);
}
void test_revwalk_mergebase__merged_branch(void)
{
git_oid result, one, two, expected;
+ size_t ahead, behind;
- git_oid_fromstr(&one, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
- git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a");
- git_oid_fromstr(&expected, "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ cl_git_pass(git_oid_fromstr(&one, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
+ cl_git_pass(git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
+ cl_git_pass(git_oid_fromstr(&expected, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
cl_git_pass(git_merge_base(&result, _repo, &one, &two));
cl_assert(git_oid_cmp(&result, &expected) == 0);
cl_git_pass(git_merge_base(&result, _repo, &two, &one));
cl_assert(git_oid_cmp(&result, &expected) == 0);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two));
+ cl_assert_equal_sz(ahead, 0);
+ cl_assert_equal_sz(behind, 3);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &two, &one));
+ cl_assert_equal_sz(ahead, 3);
+ cl_assert_equal_sz(behind, 0);
+}
+
+void test_revwalk_mergebase__two_way_merge(void)
+{
+ git_oid one, two;
+ size_t ahead, behind;
+
+ cl_git_pass(git_oid_fromstr(&one, "9b219343610c88a1187c996d0dc58330b55cee28"));
+ cl_git_pass(git_oid_fromstr(&two, "a953a018c5b10b20c86e69fef55ebc8ad4c5a417"));
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo2, &one, &two));
+
+ cl_assert_equal_sz(ahead, 2);
+ cl_assert_equal_sz(behind, 8);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo2, &two, &one));
+
+ cl_assert_equal_sz(ahead, 8);
+ cl_assert_equal_sz(behind, 2);
}
void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void)
{
- git_oid result, one, two, expected;
+ git_oid result, one, two;
+ size_t ahead, behind;
int error;
- git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af");
- git_oid_fromstr(&two, "e90810b8df3e80c413d903f631643c716887138d");
- git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ cl_git_pass(git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af"));
+ cl_git_pass(git_oid_fromstr(&two, "e90810b8df3e80c413d903f631643c716887138d"));
error = git_merge_base(&result, _repo, &one, &two);
cl_git_fail(error);
cl_assert_equal_i(GIT_ENOTFOUND, error);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two));
+ cl_assert_equal_sz(2, ahead);
+ cl_assert_equal_sz(4, behind);
+}
+
+void test_revwalk_mergebase__no_off_by_one_missing(void)
+{
+ git_oid result, one, two;
+
+ cl_git_pass(git_oid_fromstr(&one, "1a443023183e3f2bfbef8ac923cd81c1018a18fd"));
+ cl_git_pass(git_oid_fromstr(&two, "9f13f7d0a9402c681f91dc590cf7b5470e6a77d2"));
+ cl_git_pass(git_merge_base(&result, _repo, &one, &two));
+}
+
+static void assert_mergebase_many(const char *expected_sha, int count, ...)
+{
+ va_list ap;
+ int i;
+ git_oid *oids;
+ git_oid oid, expected;
+ char *partial_oid;
+ git_object *object;
+
+ oids = git__malloc(count * sizeof(git_oid));
+ cl_assert(oids != NULL);
+
+ memset(oids, 0x0, count * sizeof(git_oid));
+
+ va_start(ap, count);
+
+ for (i = 0; i < count; ++i) {
+ partial_oid = va_arg(ap, char *);
+ cl_git_pass(git_oid_fromstrn(&oid, partial_oid, strlen(partial_oid)));
+
+ cl_git_pass(git_object_lookup_prefix(&object, _repo, &oid, strlen(partial_oid), GIT_OBJ_COMMIT));
+ git_oid_cpy(&oids[i], git_object_id(object));
+ git_object_free(object);
+ }
+
+ va_end(ap);
+
+ if (expected_sha == NULL)
+ cl_assert_equal_i(GIT_ENOTFOUND, git_merge_base_many(&oid, _repo, oids, count));
+ else {
+ cl_git_pass(git_merge_base_many(&oid, _repo, oids, count));
+ cl_git_pass(git_oid_fromstr(&expected, expected_sha));
+
+ cl_assert(git_oid_cmp(&expected, &oid) == 0);
+ }
+
+ git__free(oids);
+}
+
+void test_revwalk_mergebase__many_no_common_ancestor_returns_ENOTFOUND(void)
+{
+ assert_mergebase_many(NULL, 3, "41bc8c", "e90810", "a65fed");
+ assert_mergebase_many(NULL, 3, "e90810", "41bc8c", "a65fed");
+ assert_mergebase_many(NULL, 3, "e90810", "a65fed", "41bc8c");
+ assert_mergebase_many(NULL, 3, "a65fed", "e90810", "41bc8c");
+ assert_mergebase_many(NULL, 3, "a65fed", "e90810", "41bc8c");
+ assert_mergebase_many(NULL, 3, "a65fed", "41bc8c", "e90810");
+
+ assert_mergebase_many(NULL, 3, "e90810", "763d71", "a65fed");
+}
+
+void test_revwalk_mergebase__many_merge_branch(void)
+{
+ assert_mergebase_many("c47800c7266a2be04c571c04d5a6614691ea99bd", 3, "a65fed", "763d71", "849607");
+
+ assert_mergebase_many("c47800c7266a2be04c571c04d5a6614691ea99bd", 3, "763d71", "e90810", "a65fed");
+ assert_mergebase_many("c47800c7266a2be04c571c04d5a6614691ea99bd", 3, "763d71", "a65fed", "e90810");
+
+ assert_mergebase_many("c47800c7266a2be04c571c04d5a6614691ea99bd", 3, "a65fed", "763d71", "849607");
+ assert_mergebase_many("c47800c7266a2be04c571c04d5a6614691ea99bd", 3, "a65fed", "849607", "763d71");
+ assert_mergebase_many("8496071c1b46c854b31185ea97743be6a8774479", 3, "849607", "a65fed", "763d71");
+
+ assert_mergebase_many("5b5b025afb0b4c913b4c338a42934a3863bf3644", 5, "5b5b02", "763d71", "a4a7dc", "a65fed", "41bc8c");
}
/*
- * $ git log --graph --all
+ * testrepo.git $ git log --graph --all
* * commit 763d71aadf09a7951596c9746c024e7eece7c7af
* | Author: nulltoken <emeric.fermas@gmail.com>
* | Date: Sun Oct 9 12:54:47 2011 +0200
@@ -146,3 +277,104 @@ void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void)
*
* packed commit one
*/
+
+/*
+ * twowaymerge.git $ git log --graph --all
+ * * commit 9b219343610c88a1187c996d0dc58330b55cee28
+ * |\ Merge: c37a783 2224e19
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:31:04 2012 -0800
+ * | |
+ * | | Merge branch 'first-branch' into second-branch
+ * | |
+ * | * commit 2224e191514cb4bd8c566d80dac22dfcb1e9bb83
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:28:51 2012 -0800
+ * | |
+ * | | j
+ * | |
+ * | * commit a41a49f8f5cd9b6cb14a076bf8394881ed0b4d19
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:28:39 2012 -0800
+ * | |
+ * | | i
+ * | |
+ * | * commit 82bf9a1a10a4b25c1f14c9607b60970705e92545
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:28:28 2012 -0800
+ * | |
+ * | | h
+ * | |
+ * * | commit c37a783c20d92ac92362a78a32860f7eebf938ef
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:30:57 2012 -0800
+ * | |
+ * | | n
+ * | |
+ * * | commit 8b82fb1794cb1c8c7f172ec730a4c2db0ae3e650
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:30:43 2012 -0800
+ * | |
+ * | | m
+ * | |
+ * * | commit 6ab5d28acbf3c3bdff276f7ccfdf29c1520e542f
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:30:38 2012 -0800
+ * | |
+ * | | l
+ * | |
+ * * | commit 7b8c336c45fc6895c1c60827260fe5d798e5d247
+ * | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 20:30:24 2012 -0800
+ * | |
+ * | | k
+ * | |
+ * | | * commit 1c30b88f5f3ee66d78df6520a7de9e89b890818b
+ * | | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | | Date: Tue Nov 27 20:28:10 2012 -0800
+ * | | |
+ * | | | e
+ * | | |
+ * | | * commit 42b7311aa626e712891940c1ec5d5cba201946a4
+ * | | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | | Date: Tue Nov 27 20:28:06 2012 -0800
+ * | | |
+ * | | | d
+ * | | |
+ * | | * commit a953a018c5b10b20c86e69fef55ebc8ad4c5a417
+ * | | |\ Merge: bd1732c cdf97fd
+ * | | |/ Author: Scott J. Goldman <scottjg@github.com>
+ * | |/| Date: Tue Nov 27 20:26:43 2012 -0800
+ * | | |
+ * | | | Merge branch 'first-branch'
+ * | | |
+ * | * | commit cdf97fd3bb48eb3827638bb33d208f5fd32d0aa6
+ * | | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | | Date: Tue Nov 27 20:24:46 2012 -0800
+ * | | |
+ * | | | g
+ * | | |
+ * | * | commit ef0488f0b722f0be8bcb90a7730ac7efafd1d694
+ * | | | Author: Scott J. Goldman <scottjg@github.com>
+ * | | | Date: Tue Nov 27 20:24:39 2012 -0800
+ * | | |
+ * | | | f
+ * | | |
+ * | | * commit bd1732c43c68d712ad09e1d872b9be6d4b9efdc4
+ * | |/ Author: Scott J. Goldman <scottjg@github.com>
+ * | | Date: Tue Nov 27 17:43:58 2012 -0800
+ * | |
+ * | | c
+ * | |
+ * | * commit 0c8a3f1f3d5f421cf83048c7c73ee3b55a5e0f29
+ * |/ Author: Scott J. Goldman <scottjg@github.com>
+ * | Date: Tue Nov 27 17:43:48 2012 -0800
+ * |
+ * | b
+ * |
+ * * commit 1f4c0311a24b63f6fc209a59a1e404942d4a5006
+ * Author: Scott J. Goldman <scottjg@github.com>
+ * Date: Tue Nov 27 17:43:41 2012 -0800
+ *
+ * a
+ */
diff --git a/tests-clar/revwalk/signatureparsing.c b/tests-clar/revwalk/signatureparsing.c
new file mode 100644
index 000000000..5c7d8813d
--- /dev/null
+++ b/tests-clar/revwalk/signatureparsing.c
@@ -0,0 +1,47 @@
+#include "clar_libgit2.h"
+
+static git_repository *_repo;
+static git_revwalk *_walk;
+
+void test_revwalk_signatureparsing__initialize(void)
+{
+ cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_revwalk_new(&_walk, _repo));
+}
+
+void test_revwalk_signatureparsing__cleanup(void)
+{
+ git_revwalk_free(_walk);
+ _walk = NULL;
+
+ git_repository_free(_repo);
+ _repo = NULL;
+}
+
+void test_revwalk_signatureparsing__do_not_choke_when_name_contains_angle_brackets(void)
+{
+ git_reference *ref;
+ git_oid commit_oid;
+ git_commit *commit;
+ const git_signature *signature;
+
+ /*
+ * The branch below points at a commit with angle brackets in the committer/author name
+ * committer <Yu V. Bin Haacked> <foo@example.com> 1323847743 +0100
+ */
+ cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/haacked"));
+
+ git_revwalk_push(_walk, git_reference_target(ref));
+ cl_git_pass(git_revwalk_next(&commit_oid, _walk));
+
+ cl_git_pass(git_commit_lookup(&commit, _repo, git_reference_target(ref)));
+
+ signature = git_commit_committer(commit);
+ cl_assert_equal_s("foo@example.com", signature->email);
+ cl_assert_equal_s("<Yu V. Bin Haacked>", signature->name);
+ cl_assert_equal_i(1323847743, (int)signature->when.time);
+ cl_assert_equal_i(60, signature->when.offset);
+
+ git_commit_free(commit);
+ git_reference_free(ref);
+}
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c
new file mode 100644
index 000000000..12f922630
--- /dev/null
+++ b/tests-clar/stash/drop.c
@@ -0,0 +1,168 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "stash_helpers.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_signature *signature;
+
+void test_stash_drop__initialize(void)
+{
+ cl_git_pass(git_repository_init(&repo, "stash", 0));
+ cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
+}
+
+void test_stash_drop__cleanup(void)
+{
+ git_signature_free(signature);
+ signature = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_git_pass(git_futils_rmdir_r("stash", NULL, GIT_RMDIR_REMOVE_FILES));
+}
+
+void test_stash_drop__cannot_drop_from_an_empty_stash(void)
+{
+ cl_git_fail_with(git_stash_drop(repo, 0), GIT_ENOTFOUND);
+}
+
+static void push_three_states(void)
+{
+ git_oid oid;
+ git_index *index;
+
+ cl_git_mkfile("stash/zero.txt", "content\n");
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add_bypath(index, "zero.txt"));
+ commit_staged_files(&oid, index, signature);
+ cl_assert(git_path_exists("stash/zero.txt"));
+
+ cl_git_mkfile("stash/one.txt", "content\n");
+ cl_git_pass(git_stash_save(&oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED));
+ cl_assert(!git_path_exists("stash/one.txt"));
+ cl_assert(git_path_exists("stash/zero.txt"));
+
+ cl_git_mkfile("stash/two.txt", "content\n");
+ cl_git_pass(git_stash_save(&oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED));
+ cl_assert(!git_path_exists("stash/two.txt"));
+ cl_assert(git_path_exists("stash/zero.txt"));
+
+ cl_git_mkfile("stash/three.txt", "content\n");
+ cl_git_pass(git_stash_save(&oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED));
+ cl_assert(!git_path_exists("stash/three.txt"));
+ cl_assert(git_path_exists("stash/zero.txt"));
+
+ git_index_free(index);
+}
+
+void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void)
+{
+ push_three_states();
+
+ cl_git_fail_with(git_stash_drop(repo, 666), GIT_ENOTFOUND);
+ cl_git_fail_with(git_stash_drop(repo, 42), GIT_ENOTFOUND);
+ cl_git_fail_with(git_stash_drop(repo, 3), GIT_ENOTFOUND);
+}
+
+void test_stash_drop__can_purge_the_stash_from_the_top(void)
+{
+ push_three_states();
+
+ cl_git_pass(git_stash_drop(repo, 0));
+ cl_git_pass(git_stash_drop(repo, 0));
+ cl_git_pass(git_stash_drop(repo, 0));
+
+ cl_git_fail_with(git_stash_drop(repo, 0), GIT_ENOTFOUND);
+}
+
+void test_stash_drop__can_purge_the_stash_from_the_bottom(void)
+{
+ push_three_states();
+
+ cl_git_pass(git_stash_drop(repo, 2));
+ cl_git_pass(git_stash_drop(repo, 1));
+ cl_git_pass(git_stash_drop(repo, 0));
+
+ cl_git_fail_with(git_stash_drop(repo, 0), GIT_ENOTFOUND);
+}
+
+void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void)
+{
+ git_reference *stash;
+ git_reflog *reflog;
+ const git_reflog_entry *entry;
+ git_oid oid;
+ size_t count;
+
+ push_three_states();
+
+ cl_git_pass(git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE));
+
+ cl_git_pass(git_reflog_read(&reflog, stash));
+ entry = git_reflog_entry_byindex(reflog, 1);
+
+ git_oid_cpy(&oid, git_reflog_entry_id_old(entry));
+ count = git_reflog_entrycount(reflog);
+
+ git_reflog_free(reflog);
+
+ cl_git_pass(git_stash_drop(repo, 1));
+
+ cl_git_pass(git_reflog_read(&reflog, stash));
+ entry = git_reflog_entry_byindex(reflog, 0);
+
+ cl_assert_equal_i(0, git_oid_cmp(&oid, git_reflog_entry_id_old(entry)));
+ cl_assert_equal_sz(count - 1, git_reflog_entrycount(reflog));
+
+ git_reflog_free(reflog);
+
+ git_reference_free(stash);
+}
+
+void test_stash_drop__dropping_the_last_entry_removes_the_stash(void)
+{
+ git_reference *stash;
+
+ push_three_states();
+
+ cl_git_pass(git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE));
+ git_reference_free(stash);
+
+ cl_git_pass(git_stash_drop(repo, 0));
+ cl_git_pass(git_stash_drop(repo, 0));
+ cl_git_pass(git_stash_drop(repo, 0));
+
+ cl_git_fail_with(
+ git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE), GIT_ENOTFOUND);
+}
+
+void retrieve_top_stash_id(git_oid *out)
+{
+ git_object *top_stash;
+
+ cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}"));
+ cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE));
+
+ cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0);
+}
+
+void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
+{
+ git_object *next_top_stash;
+ git_oid oid;
+
+ push_three_states();
+
+ retrieve_top_stash_id(&oid);
+
+ cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}"));
+ cl_assert_equal_i(false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0);
+
+ cl_git_pass(git_stash_drop(repo, 0));
+
+ retrieve_top_stash_id(&oid);
+
+ cl_git_pass(git_oid_cmp(&oid, git_object_id(next_top_stash)));
+}
diff --git a/tests-clar/stash/foreach.c b/tests-clar/stash/foreach.c
new file mode 100644
index 000000000..f1983625f
--- /dev/null
+++ b/tests-clar/stash/foreach.c
@@ -0,0 +1,124 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "stash_helpers.h"
+
+struct callback_data
+{
+ char **oids;
+ int invokes;
+};
+
+static git_repository *repo;
+static git_signature *signature;
+static git_oid stash_tip_oid;
+struct callback_data data;
+
+#define REPO_NAME "stash"
+
+void test_stash_foreach__initialize(void)
+{
+ cl_git_pass(git_signature_new(
+ &signature,
+ "nulltoken",
+ "emeric.fermas@gmail.com",
+ 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
+
+ memset(&data, 0, sizeof(struct callback_data));
+}
+
+void test_stash_foreach__cleanup(void)
+{
+ git_signature_free(signature);
+ signature = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_git_pass(git_futils_rmdir_r(REPO_NAME, NULL, GIT_RMDIR_REMOVE_FILES));
+}
+
+static int callback_cb(
+ size_t index,
+ const char* message,
+ const git_oid *stash_oid,
+ void *payload)
+{
+ struct callback_data *data = (struct callback_data *)payload;
+
+ GIT_UNUSED(index);
+ GIT_UNUSED(message);
+
+ cl_assert_equal_i(0, git_oid_streq(stash_oid, data->oids[data->invokes++]));
+
+ return 0;
+}
+
+void test_stash_foreach__enumerating_a_empty_repository_doesnt_fail(void)
+{
+ char *oids[] = { NULL };
+
+ data.oids = oids;
+
+ cl_git_pass(git_repository_init(&repo, REPO_NAME, 0));
+
+ cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
+
+ cl_assert_equal_i(0, data.invokes);
+}
+
+void test_stash_foreach__can_enumerate_a_repository(void)
+{
+ char *oids_default[] = {
+ "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL };
+
+ char *oids_untracked[] = {
+ "7f89a8b15c878809c5c54d1ff8f8c9674154017b",
+ "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL };
+
+ char *oids_ignored[] = {
+ "c95599a8fef20a7e57582c6727b1a0d02e0a5828",
+ "7f89a8b15c878809c5c54d1ff8f8c9674154017b",
+ "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL };
+
+ cl_git_pass(git_repository_init(&repo, REPO_NAME, 0));
+
+ setup_stash(repo, signature);
+
+ cl_git_pass(git_stash_save(
+ &stash_tip_oid,
+ repo,
+ signature,
+ NULL,
+ GIT_STASH_DEFAULT));
+
+ data.oids = oids_default;
+
+ cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
+ cl_assert_equal_i(1, data.invokes);
+
+ data.oids = oids_untracked;
+ data.invokes = 0;
+
+ cl_git_pass(git_stash_save(
+ &stash_tip_oid,
+ repo,
+ signature,
+ NULL,
+ GIT_STASH_INCLUDE_UNTRACKED));
+
+ cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
+ cl_assert_equal_i(2, data.invokes);
+
+ data.oids = oids_ignored;
+ data.invokes = 0;
+
+ cl_git_pass(git_stash_save(
+ &stash_tip_oid,
+ repo,
+ signature,
+ NULL,
+ GIT_STASH_INCLUDE_IGNORED));
+
+ cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
+ cl_assert_equal_i(3, data.invokes);
+}
diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c
new file mode 100644
index 000000000..eae116ac5
--- /dev/null
+++ b/tests-clar/stash/save.c
@@ -0,0 +1,373 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "stash_helpers.h"
+
+static git_repository *repo;
+static git_signature *signature;
+static git_oid stash_tip_oid;
+
+/*
+ * Friendly reminder, in order to ease the reading of the following tests:
+ *
+ * "stash" points to the worktree commit
+ * "stash^1" points to the base commit (HEAD when the stash was created)
+ * "stash^2" points to the index commit
+ * "stash^3" points to the untracked commit
+ */
+
+void test_stash_save__initialize(void)
+{
+ cl_git_pass(git_repository_init(&repo, "stash", 0));
+ cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
+
+ setup_stash(repo, signature);
+}
+
+void test_stash_save__cleanup(void)
+{
+ git_signature_free(signature);
+ signature = NULL;
+
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_git_pass(git_futils_rmdir_r("stash", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_fixture_cleanup("sorry-it-is-a-non-bare-only-party");
+}
+
+static void assert_object_oid(const char* revision, const char* expected_oid, git_otype type)
+{
+ int result;
+ git_object *obj;
+
+ result = git_revparse_single(&obj, repo, revision);
+
+ if (!expected_oid) {
+ cl_assert_equal_i(GIT_ENOTFOUND, result);
+ return;
+ } else
+ cl_assert_equal_i(0, result);
+
+ cl_git_pass(git_oid_streq(git_object_id(obj), expected_oid));
+ cl_assert_equal_i(type, git_object_type(obj));
+ git_object_free(obj);
+}
+
+static void assert_blob_oid(const char* revision, const char* expected_oid)
+{
+ assert_object_oid(revision, expected_oid, GIT_OBJ_BLOB);
+}
+
+void test_stash_save__does_not_keep_index_by_default(void)
+{
+/*
+$ git stash
+
+$ git show refs/stash:what
+see you later
+
+$ git show refs/stash:how
+not so small and
+
+$ git show refs/stash:who
+funky world
+
+$ git show refs/stash:when
+fatal: Path 'when' exists on disk, but not in 'stash'.
+
+$ git show refs/stash^2:what
+goodbye
+
+$ git show refs/stash^2:how
+not so small and
+
+$ git show refs/stash^2:who
+world
+
+$ git show refs/stash^2:when
+fatal: Path 'when' exists on disk, but not in 'stash^2'.
+
+$ git status --short
+?? when
+
+*/
+ unsigned int status;
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+ cl_git_pass(git_status_file(&status, repo, "when"));
+
+ assert_blob_oid("refs/stash:what", "bc99dc98b3eba0e9157e94769cd4d49cb49de449"); /* see you later */
+ assert_blob_oid("refs/stash:how", "e6d64adb2c7f3eb8feb493b556cc8070dca379a3"); /* not so small and */
+ assert_blob_oid("refs/stash:who", "a0400d4954659306a976567af43125a0b1aa8595"); /* funky world */
+ assert_blob_oid("refs/stash:when", NULL);
+ assert_blob_oid("refs/stash:just.ignore", NULL);
+
+ assert_blob_oid("refs/stash^2:what", "dd7e1c6f0fefe118f0b63d9f10908c460aa317a6"); /* goodbye */
+ assert_blob_oid("refs/stash^2:how", "e6d64adb2c7f3eb8feb493b556cc8070dca379a3"); /* not so small and */
+ assert_blob_oid("refs/stash^2:who", "cc628ccd10742baea8241c5924df992b5c019f71"); /* world */
+ assert_blob_oid("refs/stash^2:when", NULL);
+ assert_blob_oid("refs/stash^2:just.ignore", NULL);
+
+ assert_blob_oid("refs/stash^3", NULL);
+
+ cl_assert_equal_i(GIT_STATUS_WT_NEW, status);
+}
+
+static void assert_status(
+ const char *path,
+ int status_flags)
+{
+ unsigned int status;
+ int error;
+
+ error = git_status_file(&status, repo, path);
+
+ if (status_flags < 0) {
+ cl_assert_equal_i(status_flags, error);
+ return;
+ }
+
+ cl_assert_equal_i(0, error);
+ cl_assert_equal_i((unsigned int)status_flags, status);
+}
+
+void test_stash_save__can_keep_index(void)
+{
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_KEEP_INDEX));
+
+ assert_status("what", GIT_STATUS_INDEX_MODIFIED);
+ assert_status("how", GIT_STATUS_INDEX_MODIFIED);
+ assert_status("who", GIT_STATUS_CURRENT);
+ assert_status("when", GIT_STATUS_WT_NEW);
+ assert_status("just.ignore", GIT_STATUS_IGNORED);
+}
+
+static void assert_commit_message_contains(const char *revision, const char *fragment)
+{
+ git_commit *commit;
+
+ cl_git_pass(git_revparse_single((git_object**)&commit, repo, revision));
+
+ cl_assert(strstr(git_commit_message(commit), fragment) != NULL);
+
+ git_commit_free(commit);
+}
+
+void test_stash_save__can_include_untracked_files(void)
+{
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
+
+ assert_commit_message_contains("refs/stash^3", "untracked files on master: ");
+
+ assert_blob_oid("refs/stash^3:what", NULL);
+ assert_blob_oid("refs/stash^3:how", NULL);
+ assert_blob_oid("refs/stash^3:who", NULL);
+ assert_blob_oid("refs/stash^3:when", "b6ed15e81e2593d7bb6265eb4a991d29dc3e628b");
+ assert_blob_oid("refs/stash^3:just.ignore", NULL);
+}
+
+void test_stash_save__can_include_untracked_and_ignored_files(void)
+{
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED));
+
+ assert_commit_message_contains("refs/stash^3", "untracked files on master: ");
+
+ assert_blob_oid("refs/stash^3:what", NULL);
+ assert_blob_oid("refs/stash^3:how", NULL);
+ assert_blob_oid("refs/stash^3:who", NULL);
+ assert_blob_oid("refs/stash^3:when", "b6ed15e81e2593d7bb6265eb4a991d29dc3e628b");
+ assert_blob_oid("refs/stash^3:just.ignore", "78925fb1236b98b37a35e9723033e627f97aa88b");
+}
+
+#define MESSAGE "Look Ma! I'm on TV!"
+void test_stash_save__can_accept_a_message(void)
+{
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, MESSAGE, GIT_STASH_DEFAULT));
+
+ assert_commit_message_contains("refs/stash^2", "index on master: ");
+ assert_commit_message_contains("refs/stash", "On master: " MESSAGE);
+}
+
+void test_stash_save__cannot_stash_against_an_unborn_branch(void)
+{
+ git_reference *head;
+
+ cl_git_pass(git_reference_symbolic_create(&head, repo, "HEAD", "refs/heads/unborn", 1));
+
+ cl_assert_equal_i(GIT_EORPHANEDHEAD,
+ git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+
+ git_reference_free(head);
+}
+
+void test_stash_save__cannot_stash_against_a_bare_repository(void)
+{
+ git_repository *local;
+
+ cl_git_pass(git_repository_init(&local, "sorry-it-is-a-non-bare-only-party", 1));
+
+ cl_assert_equal_i(GIT_EBAREREPO,
+ git_stash_save(&stash_tip_oid, local, signature, NULL, GIT_STASH_DEFAULT));
+
+ git_repository_free(local);
+}
+
+void test_stash_save__can_stash_against_a_detached_head(void)
+{
+ git_repository_detach_head(repo);
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+
+ assert_commit_message_contains("refs/stash^2", "index on (no branch): ");
+ assert_commit_message_contains("refs/stash", "WIP on (no branch): ");
+}
+
+void test_stash_save__stashing_updates_the_reflog(void)
+{
+ char *sha;
+
+ assert_object_oid("refs/stash@{0}", NULL, GIT_OBJ_COMMIT);
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+
+ sha = git_oid_allocfmt(&stash_tip_oid);
+
+ assert_object_oid("refs/stash@{0}", sha, GIT_OBJ_COMMIT);
+ assert_object_oid("refs/stash@{1}", NULL, GIT_OBJ_COMMIT);
+
+ git__free(sha);
+}
+
+void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
+{
+ git_index *index;
+ git_oid commit_oid, stash_tip_oid;
+
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /*
+ * 'what' and 'who' are being committed.
+ * 'when' remain untracked.
+ */
+ cl_git_pass(git_index_add_bypath(index, "what"));
+ cl_git_pass(git_index_add_bypath(index, "who"));
+ cl_git_pass(git_index_write(index));
+ commit_staged_files(&commit_oid, index, signature);
+ git_index_free(index);
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+
+ p_unlink("stash/when");
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
+}
+
+void test_stash_save__can_stage_normal_then_stage_untracked(void)
+{
+ /*
+ * $ git ls-tree stash@{1}^0
+ * 100644 blob ac4d88de61733173d9959e4b77c69b9f17a00980 .gitignore
+ * 100644 blob e6d64adb2c7f3eb8feb493b556cc8070dca379a3 how
+ * 100644 blob bc99dc98b3eba0e9157e94769cd4d49cb49de449 what
+ * 100644 blob a0400d4954659306a976567af43125a0b1aa8595 who
+ *
+ * $ git ls-tree stash@{1}^1
+ * 100644 blob ac4d88de61733173d9959e4b77c69b9f17a00980 .gitignore
+ * 100644 blob ac790413e2d7a26c3767e78c57bb28716686eebc how
+ * 100644 blob ce013625030ba8dba906f756967f9e9ca394464a what
+ * 100644 blob cc628ccd10742baea8241c5924df992b5c019f71 who
+ *
+ * $ git ls-tree stash@{1}^2
+ * 100644 blob ac4d88de61733173d9959e4b77c69b9f17a00980 .gitignore
+ * 100644 blob e6d64adb2c7f3eb8feb493b556cc8070dca379a3 how
+ * 100644 blob dd7e1c6f0fefe118f0b63d9f10908c460aa317a6 what
+ * 100644 blob cc628ccd10742baea8241c5924df992b5c019f71 who
+ *
+ * $ git ls-tree stash@{1}^3
+ * fatal: Not a valid object name stash@{1}^3
+ *
+ * $ git ls-tree stash@{0}^0
+ * 100644 blob ac4d88de61733173d9959e4b77c69b9f17a00980 .gitignore
+ * 100644 blob ac790413e2d7a26c3767e78c57bb28716686eebc how
+ * 100644 blob ce013625030ba8dba906f756967f9e9ca394464a what
+ * 100644 blob cc628ccd10742baea8241c5924df992b5c019f71 who
+ *
+ * $ git ls-tree stash@{0}^1
+ * 100644 blob ac4d88de61733173d9959e4b77c69b9f17a00980 .gitignore
+ * 100644 blob ac790413e2d7a26c3767e78c57bb28716686eebc how
+ * 100644 blob ce013625030ba8dba906f756967f9e9ca394464a what
+ * 100644 blob cc628ccd10742baea8241c5924df992b5c019f71 who
+ *
+ * $ git ls-tree stash@{0}^2
+ * 100644 blob ac4d88de61733173d9959e4b77c69b9f17a00980 .gitignore
+ * 100644 blob ac790413e2d7a26c3767e78c57bb28716686eebc how
+ * 100644 blob ce013625030ba8dba906f756967f9e9ca394464a what
+ * 100644 blob cc628ccd10742baea8241c5924df992b5c019f71 who
+ *
+ * $ git ls-tree stash@{0}^3
+ * 100644 blob b6ed15e81e2593d7bb6265eb4a991d29dc3e628b when
+ */
+
+ assert_status("what", GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_MODIFIED);
+ assert_status("how", GIT_STATUS_INDEX_MODIFIED);
+ assert_status("who", GIT_STATUS_WT_MODIFIED);
+ assert_status("when", GIT_STATUS_WT_NEW);
+ assert_status("just.ignore", GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+ assert_status("what", GIT_STATUS_CURRENT);
+ assert_status("how", GIT_STATUS_CURRENT);
+ assert_status("who", GIT_STATUS_CURRENT);
+ assert_status("when", GIT_STATUS_WT_NEW);
+ assert_status("just.ignore", GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
+ assert_status("what", GIT_STATUS_CURRENT);
+ assert_status("how", GIT_STATUS_CURRENT);
+ assert_status("who", GIT_STATUS_CURRENT);
+ assert_status("when", GIT_ENOTFOUND);
+ assert_status("just.ignore", GIT_STATUS_IGNORED);
+
+
+ assert_blob_oid("stash@{1}^0:what", "bc99dc98b3eba0e9157e94769cd4d49cb49de449"); /* see you later */
+ assert_blob_oid("stash@{1}^0:how", "e6d64adb2c7f3eb8feb493b556cc8070dca379a3"); /* not so small and */
+ assert_blob_oid("stash@{1}^0:who", "a0400d4954659306a976567af43125a0b1aa8595"); /* funky world */
+ assert_blob_oid("stash@{1}^0:when", NULL);
+
+ assert_blob_oid("stash@{1}^2:what", "dd7e1c6f0fefe118f0b63d9f10908c460aa317a6"); /* goodbye */
+ assert_blob_oid("stash@{1}^2:how", "e6d64adb2c7f3eb8feb493b556cc8070dca379a3"); /* not so small and */
+ assert_blob_oid("stash@{1}^2:who", "cc628ccd10742baea8241c5924df992b5c019f71"); /* world */
+ assert_blob_oid("stash@{1}^2:when", NULL);
+
+ assert_object_oid("stash@{1}^3", NULL, GIT_OBJ_COMMIT);
+
+ assert_blob_oid("stash@{0}^0:what", "ce013625030ba8dba906f756967f9e9ca394464a"); /* hello */
+ assert_blob_oid("stash@{0}^0:how", "ac790413e2d7a26c3767e78c57bb28716686eebc"); /* small */
+ assert_blob_oid("stash@{0}^0:who", "cc628ccd10742baea8241c5924df992b5c019f71"); /* world */
+ assert_blob_oid("stash@{0}^0:when", NULL);
+
+ assert_blob_oid("stash@{0}^2:what", "ce013625030ba8dba906f756967f9e9ca394464a"); /* hello */
+ assert_blob_oid("stash@{0}^2:how", "ac790413e2d7a26c3767e78c57bb28716686eebc"); /* small */
+ assert_blob_oid("stash@{0}^2:who", "cc628ccd10742baea8241c5924df992b5c019f71"); /* world */
+ assert_blob_oid("stash@{0}^2:when", NULL);
+
+ assert_blob_oid("stash@{0}^3:when", "b6ed15e81e2593d7bb6265eb4a991d29dc3e628b"); /* now */
+}
+
+#define EMPTY_TREE "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
+
+void test_stash_save__including_untracked_without_any_untracked_file_creates_an_empty_tree(void)
+{
+ cl_git_pass(p_unlink("stash/when"));
+
+ assert_status("what", GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_MODIFIED);
+ assert_status("how", GIT_STATUS_INDEX_MODIFIED);
+ assert_status("who", GIT_STATUS_WT_MODIFIED);
+ assert_status("when", GIT_ENOTFOUND);
+ assert_status("just.ignore", GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
+
+ assert_object_oid("stash^3^{tree}", EMPTY_TREE, GIT_OBJ_TREE);
+}
diff --git a/tests-clar/stash/stash_helpers.c b/tests-clar/stash/stash_helpers.c
new file mode 100644
index 000000000..f462a1351
--- /dev/null
+++ b/tests-clar/stash/stash_helpers.c
@@ -0,0 +1,68 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "stash_helpers.h"
+
+void commit_staged_files(
+ git_oid *commit_oid,
+ git_index *index,
+ git_signature *signature)
+{
+ git_tree *tree;
+ git_oid tree_oid;
+ git_repository *repo;
+
+ repo = git_index_owner(index);
+
+ cl_git_pass(git_index_write_tree(&tree_oid, index));
+
+ cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
+
+ cl_git_pass(git_commit_create_v(
+ commit_oid,
+ repo,
+ "HEAD",
+ signature,
+ signature,
+ NULL,
+ "Initial commit",
+ tree,
+ 0));
+
+ git_tree_free(tree);
+}
+
+void setup_stash(git_repository *repo, git_signature *signature)
+{
+ git_oid commit_oid;
+ git_index *index;
+
+ cl_git_pass(git_repository_index(&index, repo));
+
+ cl_git_mkfile("stash/what", "hello\n"); /* ce013625030ba8dba906f756967f9e9ca394464a */
+ cl_git_mkfile("stash/how", "small\n"); /* ac790413e2d7a26c3767e78c57bb28716686eebc */
+ cl_git_mkfile("stash/who", "world\n"); /* cc628ccd10742baea8241c5924df992b5c019f71 */
+ cl_git_mkfile("stash/when", "now\n"); /* b6ed15e81e2593d7bb6265eb4a991d29dc3e628b */
+ cl_git_mkfile("stash/just.ignore", "me\n"); /* 78925fb1236b98b37a35e9723033e627f97aa88b */
+
+ cl_git_mkfile("stash/.gitignore", "*.ignore\n");
+
+ cl_git_pass(git_index_add_bypath(index, "what"));
+ cl_git_pass(git_index_add_bypath(index, "how"));
+ cl_git_pass(git_index_add_bypath(index, "who"));
+ cl_git_pass(git_index_add_bypath(index, ".gitignore"));
+ cl_git_pass(git_index_write(index));
+
+ commit_staged_files(&commit_oid, index, signature);
+
+ cl_git_rewritefile("stash/what", "goodbye\n"); /* dd7e1c6f0fefe118f0b63d9f10908c460aa317a6 */
+ cl_git_rewritefile("stash/how", "not so small and\n"); /* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */
+ cl_git_rewritefile("stash/who", "funky world\n"); /* a0400d4954659306a976567af43125a0b1aa8595 */
+
+ cl_git_pass(git_index_add_bypath(index, "what"));
+ cl_git_pass(git_index_add_bypath(index, "how"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_rewritefile("stash/what", "see you later\n"); /* bc99dc98b3eba0e9157e94769cd4d49cb49de449 */
+
+ git_index_free(index);
+}
diff --git a/tests-clar/stash/stash_helpers.h b/tests-clar/stash/stash_helpers.h
new file mode 100644
index 000000000..bb7fec4f5
--- /dev/null
+++ b/tests-clar/stash/stash_helpers.h
@@ -0,0 +1,8 @@
+void setup_stash(
+ git_repository *repo,
+ git_signature *signature);
+
+void commit_staged_files(
+ git_oid *commit_oid,
+ git_index *index,
+ git_signature *signature); \ No newline at end of file
diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c
index 369b25bda..2d3898ba4 100644
--- a/tests-clar/status/ignore.c
+++ b/tests-clar/status/ignore.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "fileops.h"
#include "git2/attr.h"
+#include "ignore.h"
#include "attr.h"
#include "status_helpers.h"
@@ -21,21 +22,25 @@ void test_status_ignore__0(void)
const char *path;
int expected;
} test_cases[] = {
- /* patterns "sub" and "ign" from .gitignore */
+ /* pattern "ign" from .gitignore */
{ "file", 0 },
{ "ign", 1 },
- { "sub", 1 },
+ { "sub", 0 },
{ "sub/file", 0 },
{ "sub/ign", 1 },
- { "sub/sub", 1 },
+ { "sub/ign/file", 1 },
+ { "sub/ign/sub", 1 },
+ { "sub/ign/sub/file", 1 },
+ { "sub/sub", 0 },
{ "sub/sub/file", 0 },
{ "sub/sub/ign", 1 },
- { "sub/sub/sub", 1 },
+ { "sub/sub/sub", 0 },
/* pattern "dir/" from .gitignore */
{ "dir", 1 },
{ "dir/", 1 },
{ "sub/dir", 1 },
{ "sub/dir/", 1 },
+ { "sub/dir/file", 1 }, /* contained in ignored parent */
{ "sub/sub/dir", 0 }, /* dir is not actually a dir, but a file */
{ NULL, 0 }
}, *one_test;
@@ -131,3 +136,326 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
cl_assert(ignored);
}
+void test_status_ignore__ignore_pattern_contains_space(void)
+{
+ unsigned int flags;
+ const mode_t mode = 0777;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "foo bar.txt\n");
+
+ cl_git_mkfile(
+ "empty_standard_repo/foo bar.txt", "I'm going to be ignored!");
+
+ cl_git_pass(git_status_file(&flags, g_repo, "foo bar.txt"));
+ cl_assert(flags == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_futils_mkdir_r("empty_standard_repo/foo", NULL, mode));
+ cl_git_mkfile("empty_standard_repo/foo/look-ma.txt", "I'm not going to be ignored!");
+
+ cl_git_pass(git_status_file(&flags, g_repo, "foo/look-ma.txt"));
+ cl_assert(flags == GIT_STATUS_WT_NEW);
+}
+
+void test_status_ignore__ignore_pattern_ignorecase(void)
+{
+ unsigned int flags;
+ bool ignore_case;
+ git_index *index;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "a.txt\n");
+
+ cl_git_mkfile("empty_standard_repo/A.txt", "Differs in case");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ ignore_case = index->ignore_case;
+ git_index_free(index);
+
+ cl_git_pass(git_status_file(&flags, g_repo, "A.txt"));
+ cl_assert(flags == ignore_case ? GIT_STATUS_IGNORED : GIT_STATUS_WT_NEW);
+}
+
+void test_status_ignore__subdirectories(void)
+{
+ status_entry_single st;
+ int ignored;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_mkfile(
+ "empty_standard_repo/ignore_me", "I'm going to be ignored!");
+
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
+ cl_assert_equal_i(2, st.count);
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_file(&st.status, g_repo, "ignore_me"));
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "ignore_me"));
+ cl_assert(ignored);
+
+ /* I've changed libgit2 so that the behavior here now differs from
+ * core git but seems to make more sense. In core git, the following
+ * items are skipped completed, even if --ignored is passed to status.
+ * It you mirror these steps and run "git status -uall --ignored" then
+ * you will not see "test/ignore_me/" in the results.
+ *
+ * However, we had a couple reports of this as a bug, plus there is a
+ * similar circumstance where we were differing for core git when you
+ * used a rooted path for an ignore, so I changed this behavior.
+ */
+ cl_git_pass(git_futils_mkdir_r(
+ "empty_standard_repo/test/ignore_me", NULL, 0775));
+ cl_git_mkfile(
+ "empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!");
+ cl_git_mkfile(
+ "empty_standard_repo/test/ignore_me/file2", "Me, too!");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
+ cl_assert_equal_i(3, st.count);
+
+ cl_git_pass(git_status_file(&st.status, g_repo, "test/ignore_me/file"));
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(
+ git_status_should_ignore(&ignored, g_repo, "test/ignore_me/file"));
+ cl_assert(ignored);
+}
+
+void test_status_ignore__subdirectories_recursion(void)
+{
+ /* Let's try again with recursing into ignored dirs turned on */
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ static const char *paths_r[] = {
+ ".gitignore",
+ "ignore_also/file",
+ "ignore_me",
+ "test/ignore_me/and_me/file",
+ "test/ignore_me/file",
+ "test/ignore_me/file2",
+ };
+ static const unsigned int statuses_r[] = {
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED,
+ };
+ static const char *paths_nr[] = {
+ ".gitignore",
+ "ignore_also/",
+ "ignore_me",
+ "test/ignore_me/",
+ };
+ static const unsigned int statuses_nr[] = {
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED,
+ };
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n/ignore_also\n");
+
+ cl_git_mkfile(
+ "empty_standard_repo/ignore_me", "I'm going to be ignored!");
+ cl_git_pass(git_futils_mkdir_r(
+ "empty_standard_repo/test/ignore_me", NULL, 0775));
+ cl_git_mkfile(
+ "empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!");
+ cl_git_mkfile(
+ "empty_standard_repo/test/ignore_me/file2", "Me, too!");
+ cl_git_pass(git_futils_mkdir_r(
+ "empty_standard_repo/test/ignore_me/and_me", NULL, 0775));
+ cl_git_mkfile(
+ "empty_standard_repo/test/ignore_me/and_me/file", "Deeply ignored");
+ cl_git_pass(git_futils_mkdir_r(
+ "empty_standard_repo/ignore_also", NULL, 0775));
+ cl_git_mkfile(
+ "empty_standard_repo/ignore_also/file", "I'm going to be ignored!");
+
+ memset(&counts, 0x0, sizeof(status_entry_counts));
+ counts.expected_entry_count = 6;
+ counts.expected_paths = paths_r;
+ counts.expected_statuses = statuses_r;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
+
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__normal, &counts));
+
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
+
+
+ memset(&counts, 0x0, sizeof(status_entry_counts));
+ counts.expected_entry_count = 4;
+ counts.expected_paths = paths_nr;
+ counts.expected_statuses = statuses_nr;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS;
+
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__normal, &counts));
+
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
+}
+
+void test_status_ignore__adding_internal_ignores(void)
+{
+ int ignored;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_ignore_add_rule(g_repo, "*.nomatch\n"));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_ignore_add_rule(g_repo, "*.txt\n"));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_ignore_add_rule(g_repo, "*.bar\n"));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(ignored);
+
+ cl_git_pass(git_ignore_clear_internal_rules(g_repo));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_ignore_add_rule(
+ g_repo, "multiple\n*.rules\n# comment line\n*.bar\n"));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(ignored);
+}
+
+void test_status_ignore__add_internal_as_first_thing(void)
+{
+ int ignored;
+ const char *add_me = "\n#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n\n";
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_pass(git_ignore_add_rule(g_repo, add_me));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.tmp"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
+ cl_assert(!ignored);
+}
+
+void test_status_ignore__internal_ignores_inside_deep_paths(void)
+{
+ int ignored;
+ const char *add_me = "Debug\nthis/is/deep\npatterned*/dir\n";
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_pass(git_ignore_add_rule(g_repo, add_me));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "Debug"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/Debug"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "really/Debug/this/file"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "Debug/what/I/say"));
+ cl_assert(ignored);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/NoDebug"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "NoDebug/this"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "please/NoDebug/this"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deep"));
+ cl_assert(ignored);
+ /* pattern containing slash gets FNM_PATHNAME so all slashes must match */
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/this/is/deep"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deep/too"));
+ cl_assert(ignored);
+ /* pattern containing slash gets FNM_PATHNAME so all slashes must match */
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "but/this/is/deep/and/ignored"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/not/deep"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "is/this/not/as/deep"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deepish"));
+ cl_assert(!ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "xthis/is/deep"));
+ cl_assert(!ignored);
+}
+
+void test_status_ignore__automatically_ignore_bad_files(void)
+{
+ int ignored;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_ignore_add_rule(g_repo, "*.c\n"));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
+ cl_assert(ignored);
+
+ cl_git_pass(git_ignore_clear_internal_rules(g_repo));
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
+ cl_assert(ignored);
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
+ cl_assert(!ignored);
+}
diff --git a/tests-clar/status/single.c b/tests-clar/status/single.c
index e900a31d6..292c9120a 100644
--- a/tests-clar/status/single.c
+++ b/tests-clar/status/single.c
@@ -25,5 +25,21 @@ void test_status_single__hash_single_file(void)
cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0);
}
+/* test retrieving OID from an empty file apart from the ODB */
+void test_status_single__hash_single_empty_file(void)
+{
+ static const char file_name[] = "new_empty_file";
+ static const char file_contents[] = "";
+ static const char file_hash[] = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
+
+ git_oid expected_id, actual_id;
+ /* initialization */
+ git_oid_fromstr(&expected_id, file_hash);
+ cl_git_mkfile(file_name, file_contents);
+ cl_set_cleanup(&cleanup__remove_file, (void *)file_name);
+
+ cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB));
+ cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0);
+}
diff --git a/tests-clar/status/status_data.h b/tests-clar/status/status_data.h
index f109717e8..a41bde7c2 100644
--- a/tests-clar/status/status_data.h
+++ b/tests-clar/status/status_data.h
@@ -19,6 +19,8 @@ static const char *entry_paths0[] = {
"subdir/deleted_file",
"subdir/modified_file",
"subdir/new_file",
+
+ "\xe8\xbf\x99",
};
static const unsigned int entry_statuses0[] = {
@@ -38,9 +40,11 @@ static const unsigned int entry_statuses0[] = {
GIT_STATUS_WT_DELETED,
GIT_STATUS_WT_MODIFIED,
GIT_STATUS_WT_NEW,
+
+ GIT_STATUS_WT_NEW,
};
-static const size_t entry_count0 = 15;
+static const int entry_count0 = 16;
/* entries for a copy of tests/resources/status with all content
* deleted from the working directory
@@ -82,10 +86,60 @@ static const unsigned int entry_statuses2[] = {
GIT_STATUS_WT_DELETED,
};
-static const size_t entry_count2 = 15;
+static const int entry_count2 = 15;
/* entries for a copy of tests/resources/status with some mods */
+static const char *entry_paths3_icase[] = {
+ ".HEADER",
+ "42-is-not-prime.sigh",
+ "current_file",
+ "current_file/",
+ "file_deleted",
+ "ignored_file",
+ "modified_file",
+ "new_file",
+ "README.md",
+ "staged_changes",
+ "staged_changes_file_deleted",
+ "staged_changes_modified_file",
+ "staged_delete_file_deleted",
+ "staged_delete_modified_file",
+ "staged_new_file",
+ "staged_new_file_deleted_file",
+ "staged_new_file_modified_file",
+ "subdir",
+ "subdir/current_file",
+ "subdir/deleted_file",
+ "subdir/modified_file",
+ "\xe8\xbf\x99",
+};
+
+static const unsigned int entry_statuses3_icase[] = {
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_DELETED,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_DELETED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_INDEX_MODIFIED,
+ GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED,
+ GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_MODIFIED,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_WT_NEW | GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_DELETED,
+ GIT_STATUS_WT_DELETED,
+ GIT_STATUS_WT_DELETED,
+ GIT_STATUS_WT_NEW,
+};
+
static const char *entry_paths3[] = {
".HEADER",
"42-is-not-prime.sigh",
@@ -108,6 +162,7 @@ static const char *entry_paths3[] = {
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
+ "\xe8\xbf\x99",
};
static const unsigned int entry_statuses3[] = {
@@ -132,9 +187,10 @@ static const unsigned int entry_statuses3[] = {
GIT_STATUS_WT_DELETED,
GIT_STATUS_WT_DELETED,
GIT_STATUS_WT_DELETED,
+ GIT_STATUS_WT_NEW,
};
-static const size_t entry_count3 = 21;
+static const int entry_count3 = 22;
/* entries for a copy of tests/resources/status with some mods
@@ -163,7 +219,8 @@ static const char *entry_paths4[] = {
"subdir/deleted_file",
"subdir/modified_file",
"zzz_new_dir/new_file",
- "zzz_new_file"
+ "zzz_new_file",
+ "\xe8\xbf\x99",
};
static const unsigned int entry_statuses4[] = {
@@ -189,6 +246,7 @@ static const unsigned int entry_statuses4[] = {
GIT_STATUS_WT_DELETED,
GIT_STATUS_WT_NEW,
GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_NEW,
};
-static const size_t entry_count4 = 22;
+static const int entry_count4 = 23;
diff --git a/tests-clar/status/status_helpers.c b/tests-clar/status/status_helpers.c
index 3dbf43a5b..24546d45c 100644
--- a/tests-clar/status/status_helpers.c
+++ b/tests-clar/status/status_helpers.c
@@ -47,3 +47,51 @@ int cb_status__single(const char *p, unsigned int s, void *payload)
return 0;
}
+
+int cb_status__print(
+ const char *path, unsigned int status_flags, void *payload)
+{
+ char istatus = ' ', wstatus = ' ';
+ int icount = 0, wcount = 0;
+
+ if (status_flags & GIT_STATUS_INDEX_NEW) {
+ istatus = 'A'; icount++;
+ }
+ if (status_flags & GIT_STATUS_INDEX_MODIFIED) {
+ istatus = 'M'; icount++;
+ }
+ if (status_flags & GIT_STATUS_INDEX_DELETED) {
+ istatus = 'D'; icount++;
+ }
+ if (status_flags & GIT_STATUS_INDEX_RENAMED) {
+ istatus = 'R'; icount++;
+ }
+ if (status_flags & GIT_STATUS_INDEX_TYPECHANGE) {
+ istatus = 'T'; icount++;
+ }
+
+ if (status_flags & GIT_STATUS_WT_NEW) {
+ wstatus = 'A'; wcount++;
+ }
+ if (status_flags & GIT_STATUS_WT_MODIFIED) {
+ wstatus = 'M'; wcount++;
+ }
+ if (status_flags & GIT_STATUS_WT_DELETED) {
+ wstatus = 'D'; wcount++;
+ }
+ if (status_flags & GIT_STATUS_WT_TYPECHANGE) {
+ wstatus = 'T'; wcount++;
+ }
+ if (status_flags & GIT_STATUS_IGNORED) {
+ wstatus = 'I'; wcount++;
+ }
+
+ fprintf(stderr, "%c%c %s (%d/%d%s)\n",
+ istatus, wstatus, path, icount, wcount,
+ (icount > 1 || wcount > 1) ? " INVALID COMBO" : "");
+
+ if (payload)
+ *((int *)payload) += 1;
+
+ return 0;
+}
diff --git a/tests-clar/status/status_helpers.h b/tests-clar/status/status_helpers.h
index cffca66a5..1aa0263ee 100644
--- a/tests-clar/status/status_helpers.h
+++ b/tests-clar/status/status_helpers.h
@@ -2,12 +2,12 @@
#define INCLUDE_cl_status_helpers_h__
typedef struct {
- size_t wrong_status_flags_count;
- size_t wrong_sorted_path;
- size_t entry_count;
+ int wrong_status_flags_count;
+ int wrong_sorted_path;
+ int entry_count;
const unsigned int* expected_statuses;
const char** expected_paths;
- size_t expected_entry_count;
+ int expected_entry_count;
} status_entry_counts;
/* cb_status__normal takes payload of "status_entry_counts *" */
@@ -30,4 +30,8 @@ typedef struct {
extern int cb_status__single(const char *p, unsigned int s, void *payload);
+/* cb_status__print takes optional payload of "int *" */
+
+extern int cb_status__print(const char *p, unsigned int s, void *payload);
+
#endif
diff --git a/tests-clar/status/submodules.c b/tests-clar/status/submodules.c
index 9423e8490..8365a7f5a 100644
--- a/tests-clar/status/submodules.c
+++ b/tests-clar/status/submodules.c
@@ -3,24 +3,17 @@
#include "path.h"
#include "posix.h"
#include "status_helpers.h"
+#include "../submodule/submodule_helpers.h"
static git_repository *g_repo = NULL;
void test_status_submodules__initialize(void)
{
- git_buf modpath = GIT_BUF_INIT;
-
g_repo = cl_git_sandbox_init("submodules");
cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_buf_sets(&modpath, git_repository_workdir(g_repo)));
- cl_assert(git_path_dirname_r(&modpath, modpath.ptr) >= 0);
- cl_git_pass(git_buf_joinpath(&modpath, modpath.ptr, "testrepo.git\n"));
-
- p_rename("submodules/gitmodules", "submodules/.gitmodules");
- cl_git_append2file("submodules/.gitmodules", modpath.ptr);
- git_buf_free(&modpath);
+ rewrite_gitmodules(git_repository_workdir(g_repo));
p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git");
}
@@ -28,6 +21,7 @@ void test_status_submodules__initialize(void)
void test_status_submodules__cleanup(void)
{
cl_git_sandbox_cleanup();
+ cl_fixture_cleanup("testrepo.git");
}
void test_status_submodules__api(void)
@@ -40,8 +34,8 @@ void test_status_submodules__api(void)
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
cl_assert(sm != NULL);
- cl_assert_equal_s("testrepo", sm->name);
- cl_assert_equal_s("testrepo", sm->path);
+ cl_assert_equal_s("testrepo", git_submodule_name(sm));
+ cl_assert_equal_s("testrepo", git_submodule_path(sm));
}
void test_status_submodules__0(void)
@@ -56,7 +50,7 @@ void test_status_submodules__0(void)
git_status_foreach(g_repo, cb_status__count, &counts)
);
- cl_assert(counts == 6);
+ cl_assert_equal_i(6, counts);
}
static const char *expected_files[] = {
@@ -77,36 +71,152 @@ static unsigned int expected_status[] = {
GIT_STATUS_WT_NEW
};
-static int
-cb_status__match(const char *p, unsigned int s, void *payload)
+static int cb_status__match(const char *p, unsigned int s, void *payload)
{
- volatile int *index = (int *)payload;
+ status_entry_counts *counts = payload;
+ int idx = counts->entry_count++;
- cl_assert_equal_s(expected_files[*index], p);
- cl_assert(expected_status[*index] == s);
- (*index)++;
+ cl_assert_equal_s(counts->expected_paths[idx], p);
+ cl_assert(counts->expected_statuses[idx] == s);
return 0;
}
void test_status_submodules__1(void)
{
- int index = 0;
+ status_entry_counts counts;
cl_assert(git_path_isdir("submodules/.git"));
cl_assert(git_path_isdir("submodules/testrepo/.git"));
cl_assert(git_path_isfile("submodules/.gitmodules"));
+ memset(&counts, 0, sizeof(counts));
+ counts.expected_paths = expected_files;
+ counts.expected_statuses = expected_status;
+
cl_git_pass(
- git_status_foreach(g_repo, cb_status__match, &index)
+ git_status_foreach(g_repo, cb_status__match, &counts)
);
- cl_assert(index == 6);
+ cl_assert_equal_i(6, counts.entry_count);
}
void test_status_submodules__single_file(void)
{
- unsigned int status;
+ unsigned int status = 0;
cl_git_pass( git_status_file(&status, g_repo, "testrepo") );
- cl_assert(status == 0);
+ cl_assert(!status);
}
+
+void test_status_submodules__moved_head(void)
+{
+ git_submodule *sm;
+ git_repository *smrepo;
+ git_oid oid;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ static const char *expected_files_with_sub[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "ignored",
+ "modified",
+ "testrepo",
+ "untracked"
+ };
+ static unsigned int expected_status_with_sub[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW
+ };
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+ cl_git_pass(git_submodule_open(&smrepo, sm));
+
+ /* move submodule HEAD to c47800c7266a2be04c571c04d5a6614691ea99bd */
+ cl_git_pass(
+ git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ cl_git_pass(git_repository_set_head_detached(smrepo, &oid));
+
+ /* first do a normal status, which should now include the submodule */
+
+ memset(&counts, 0, sizeof(counts));
+ counts.expected_paths = expected_files_with_sub;
+ counts.expected_statuses = expected_status_with_sub;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS;
+
+ cl_git_pass(
+ git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(7, counts.entry_count);
+
+ /* try again with EXCLUDE_SUBMODULES which should skip it */
+
+ memset(&counts, 0, sizeof(counts));
+ counts.expected_paths = expected_files;
+ counts.expected_statuses = expected_status;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
+
+ cl_git_pass(
+ git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ git_repository_free(smrepo);
+}
+
+void test_status_submodules__dirty_workdir_only(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ static const char *expected_files_with_sub[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "ignored",
+ "modified",
+ "testrepo",
+ "untracked"
+ };
+ static unsigned int expected_status_with_sub[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW
+ };
+
+ cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
+ cl_git_mkfile("submodules/testrepo/all_new.txt", "never seen before");
+
+ /* first do a normal status, which should now include the submodule */
+
+ memset(&counts, 0, sizeof(counts));
+ counts.expected_paths = expected_files_with_sub;
+ counts.expected_statuses = expected_status_with_sub;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS;
+
+ cl_git_pass(
+ git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(7, counts.entry_count);
+
+ /* try again with EXCLUDE_SUBMODULES which should skip it */
+
+ memset(&counts, 0, sizeof(counts));
+ counts.expected_paths = expected_files;
+ counts.expected_statuses = expected_status;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
+
+ cl_git_pass(
+ git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+}
+
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 6cc6259b8..a9b8a12ed 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -7,16 +7,6 @@
#include "path.h"
/**
- * Initializer
- *
- * Not all of the tests in this file use the same fixtures, so we allow each
- * test to load their fixture at the top of the test function.
- */
-void test_status_worktree__initialize(void)
-{
-}
-
-/**
* Cleanup
*
* This will be called once after each test finishes, even
@@ -71,7 +61,7 @@ static int remove_file_cb(void *data, git_buf *file)
return 0;
if (git_path_isdir(filename))
- cl_git_pass(git_futils_rmdir_r(filename, GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_RMDIR_REMOVE_FILES));
else
cl_git_pass(p_unlink(git_buf_cstr(file)));
@@ -110,7 +100,13 @@ void test_status_worktree__swap_subdir_and_file(void)
{
status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
- git_status_options opts;
+ git_index *index;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ bool ignore_case;
+
+ cl_git_pass(git_repository_index(&index, repo));
+ ignore_case = index->ignore_case;
+ git_index_free(index);
/* first alter the contents of the worktree */
cl_git_pass(p_rename("status/current_file", "status/swap"));
@@ -124,10 +120,9 @@ void test_status_worktree__swap_subdir_and_file(void)
/* now get status */
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = entry_count3;
- counts.expected_paths = entry_paths3;
- counts.expected_statuses = entry_statuses3;
+ counts.expected_paths = ignore_case ? entry_paths3_icase : entry_paths3;
+ counts.expected_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3;
- memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_INCLUDE_IGNORED;
@@ -144,7 +139,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
{
status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
- git_status_options opts;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
/* first alter the contents of the worktree */
cl_git_pass(p_rename("status/current_file", "status/swap"));
@@ -161,7 +156,6 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
counts.expected_paths = entry_paths4;
counts.expected_statuses = entry_statuses4;
- memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
/* TODO: set pathspec to "current_file" eventually */
@@ -280,6 +274,7 @@ void test_status_worktree__issue_592(void)
repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "l.txt"));
cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists("issue_592/l.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "l.txt"));
@@ -294,6 +289,7 @@ void test_status_worktree__issue_592_2(void)
repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
@@ -308,7 +304,8 @@ void test_status_worktree__issue_592_3(void)
repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
@@ -338,7 +335,7 @@ void test_status_worktree__issue_592_5(void)
repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "t"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), GIT_DIRREMOVAL_FILES_AND_DIRS));
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
cl_git_pass(p_mkdir(git_buf_cstr(&path), 0777));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, NULL));
@@ -405,114 +402,274 @@ void test_status_worktree__issue_592_ignored_dirs_with_tracked_content(void)
*/
}
-void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
+void test_status_worktree__conflict_with_diff3(void)
{
- git_repository *repo;
- int error;
- unsigned int status = 0;
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_index *index;
+ unsigned int status;
+ git_index_entry ancestor_entry, our_entry, their_entry;
- cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+ memset(&our_entry, 0x0, sizeof(git_index_entry));
+ memset(&their_entry, 0x0, sizeof(git_index_entry));
- error = git_status_file(&status, repo, "dummy");
+ ancestor_entry.path = "modified_file";
+ git_oid_fromstr(&ancestor_entry.oid,
+ "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
- cl_git_fail(error);
- cl_assert(error != GIT_ENOTFOUND);
+ our_entry.path = "modified_file";
+ git_oid_fromstr(&our_entry.oid,
+ "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
+
+ their_entry.path = "modified_file";
+ git_oid_fromstr(&their_entry.oid,
+ "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
+
+ cl_git_pass(git_status_file(&status, repo, "modified_file"));
+ cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status);
- git_repository_free(repo);
+ cl_git_pass(git_repository_index(&index, repo));
+
+ cl_git_pass(git_index_remove(index, "modified_file", 0));
+ cl_git_pass(git_index_conflict_add(index, &ancestor_entry,
+ &our_entry, &their_entry));
+
+ cl_git_pass(git_status_file(&status, repo, "modified_file"));
+
+ cl_assert_equal_i(GIT_STATUS_INDEX_DELETED | GIT_STATUS_WT_NEW, status);
+
+ git_index_free(index);
}
-void test_status_worktree__first_commit_in_progress(void)
+static const char *filemode_paths[] = {
+ "exec_off",
+ "exec_off2on_staged",
+ "exec_off2on_workdir",
+ "exec_off_untracked",
+ "exec_on",
+ "exec_on2off_staged",
+ "exec_on2off_workdir",
+ "exec_on_untracked",
+};
+
+static unsigned int filemode_statuses[] = {
+ GIT_STATUS_CURRENT,
+ GIT_STATUS_INDEX_MODIFIED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_CURRENT,
+ GIT_STATUS_INDEX_MODIFIED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW
+};
+
+static const int filemode_count = 8;
+
+void test_status_worktree__filemode_changes(void)
{
- git_repository *repo;
- git_index *index;
- status_entry_single result;
+ git_repository *repo = cl_git_sandbox_init("filemodes");
+ status_entry_counts counts;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
- cl_git_pass(git_repository_init(&repo, "getting_started", 0));
- cl_git_mkfile("getting_started/testfile.txt", "content\n");
+ /* overwrite stored filemode with platform appropriate value */
+ if (cl_is_chmod_supported())
+ cl_repo_set_bool(repo, "core.filemode", true);
+ else {
+ int i;
- memset(&result, 0, sizeof(result));
- cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
- cl_assert_equal_i(1, result.count);
- cl_assert(result.status == GIT_STATUS_WT_NEW);
+ cl_repo_set_bool(repo, "core.filemode", false);
- cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_index_add(index, "testfile.txt", 0));
- cl_git_pass(git_index_write(index));
+ /* won't trust filesystem mode diffs, so these will appear unchanged */
+ for (i = 0; i < filemode_count; ++i)
+ if (filemode_statuses[i] == GIT_STATUS_WT_MODIFIED)
+ filemode_statuses[i] = GIT_STATUS_CURRENT;
+ }
- memset(&result, 0, sizeof(result));
- cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
- cl_assert_equal_i(1, result.count);
- cl_assert(result.status == GIT_STATUS_INDEX_NEW);
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_INCLUDE_IGNORED |
+ GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
- git_index_free(index);
- git_repository_free(repo);
+ memset(&counts, 0, sizeof(counts));
+ counts.expected_entry_count = filemode_count;
+ counts.expected_paths = filemode_paths;
+ counts.expected_statuses = filemode_statuses;
+
+ cl_git_pass(
+ git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)
+ );
+
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+static int cb_status__interrupt(const char *p, unsigned int s, void *payload)
+{
+ volatile int *count = (int *)payload;
+
+ GIT_UNUSED(p);
+ GIT_UNUSED(s);
+ (*count)++;
-void test_status_worktree__status_file_without_index_or_workdir(void)
+ return (*count == 8);
+}
+
+void test_status_worktree__interruptable_foreach(void)
{
- git_repository *repo;
- unsigned int status = 0;
+ int count = 0;
+ git_repository *repo = cl_git_sandbox_init("status");
+
+ cl_assert_equal_i(
+ GIT_EUSER, git_status_foreach(repo, cb_status__interrupt, &count)
+ );
+
+ cl_assert_equal_i(8, count);
+}
+
+void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ unsigned int status;
+
+ cl_repo_set_bool(repo, "core.autocrlf", true);
+
+ cl_git_rewritefile("status/current_file", "current_file\r\n");
+
+ cl_git_pass(git_status_file(&status, repo, "current_file"));
+
+ cl_assert_equal_i(GIT_STATUS_CURRENT, status);
+}
+
+void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf_issue_1397(void)
+{
+ git_repository *repo = cl_git_sandbox_init("issue_1397");
+ unsigned int status;
+
+ cl_repo_set_bool(repo, "core.autocrlf", true);
+
+ cl_git_pass(git_status_file(&status, repo, "crlf_file.txt"));
+
+ cl_assert_equal_i(GIT_STATUS_CURRENT, status);
+}
+
+void test_status_worktree__conflicted_item(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
git_index *index;
+ unsigned int status;
+ git_index_entry ancestor_entry, our_entry, their_entry;
+
+ memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+ memset(&our_entry, 0x0, sizeof(git_index_entry));
+ memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+ ancestor_entry.path = "modified_file";
+ git_oid_fromstr(&ancestor_entry.oid,
+ "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
- cl_git_pass(p_mkdir("wd", 0777));
+ our_entry.path = "modified_file";
+ git_oid_fromstr(&our_entry.oid,
+ "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
- cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_repository_set_workdir(repo, "wd"));
+ their_entry.path = "modified_file";
+ git_oid_fromstr(&their_entry.oid,
+ "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
- cl_git_pass(git_index_open(&index, "empty-index"));
- cl_assert_equal_i(0, git_index_entrycount(index));
- git_repository_set_index(repo, index);
+ cl_git_pass(git_status_file(&status, repo, "modified_file"));
+ cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status);
- cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_conflict_add(index, &ancestor_entry,
+ &our_entry, &their_entry));
- cl_assert_equal_i(GIT_STATUS_INDEX_DELETED, status);
+ cl_git_pass(git_status_file(&status, repo, "modified_file"));
+ cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status);
- git_repository_free(repo);
git_index_free(index);
- cl_git_pass(p_rmdir("wd"));
}
-static void fill_index_wth_head_entries(git_repository *repo, git_index *index)
+static void stage_and_commit(git_repository *repo, const char *path)
{
- git_oid oid;
- git_commit *commit;
+ git_oid tree_oid, commit_oid;
git_tree *tree;
+ git_signature *signature;
+ git_index *index;
- cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD"));
- cl_git_pass(git_commit_lookup(&commit, repo, &oid));
- cl_git_pass(git_commit_tree(&tree, commit));
-
- cl_git_pass(git_index_read_tree(index, tree));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add_bypath(index, path));
cl_git_pass(git_index_write(index));
+ cl_git_pass(git_index_write_tree(&tree_oid, index));
+ git_index_free(index);
+
+ cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
+
+ cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60));
+
+ cl_git_pass(git_commit_create_v(
+ &commit_oid,
+ repo,
+ "HEAD",
+ signature,
+ signature,
+ NULL,
+ "Initial commit\n\0",
+ tree,
+ 0));
+
git_tree_free(tree);
- git_commit_free(commit);
+ git_signature_free(signature);
}
-void test_status_worktree__status_file_with_clean_index_and_empty_workdir(void)
+static void assert_ignore_case(
+ bool should_ignore_case,
+ int expected_lower_cased_file_status,
+ int expected_camel_cased_file_status)
{
- git_repository *repo;
- unsigned int status = 0;
- git_index *index;
+ unsigned int status;
+ git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
+ git_repository *repo, *repo2;
- cl_git_pass(p_mkdir("wd", 0777));
+ repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
- cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_repository_set_workdir(repo, "wd"));
+ cl_repo_set_bool(repo, "core.ignorecase", should_ignore_case);
- cl_git_pass(git_index_open(&index, "my-index"));
- fill_index_wth_head_entries(repo, index);
+ cl_git_pass(git_buf_joinpath(&lower_case_path,
+ git_repository_workdir(repo), "plop"));
- git_repository_set_index(repo, index);
+ cl_git_mkfile(git_buf_cstr(&lower_case_path), "");
- cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));
+ stage_and_commit(repo, "plop");
- cl_assert_equal_i(GIT_STATUS_WT_DELETED, status);
+ cl_git_pass(git_repository_open(&repo2, "./empty_standard_repo"));
- git_repository_free(repo);
- git_index_free(index);
- cl_git_pass(p_rmdir("wd"));
- cl_git_pass(p_unlink("my-index"));
+ cl_git_pass(git_status_file(&status, repo2, "plop"));
+ cl_assert_equal_i(GIT_STATUS_CURRENT, status);
+
+ cl_git_pass(git_buf_joinpath(&camel_case_path,
+ git_repository_workdir(repo), "Plop"));
+
+ cl_git_pass(p_rename(git_buf_cstr(&lower_case_path), git_buf_cstr(&camel_case_path)));
+
+ cl_git_pass(git_status_file(&status, repo2, "plop"));
+ cl_assert_equal_i(expected_lower_cased_file_status, status);
+
+ cl_git_pass(git_status_file(&status, repo2, "Plop"));
+ cl_assert_equal_i(expected_camel_cased_file_status, status);
+
+ git_repository_free(repo2);
+ git_buf_free(&lower_case_path);
+ git_buf_free(&camel_case_path);
+}
+
+void test_status_worktree__file_status_honors_core_ignorecase_true(void)
+{
+ assert_ignore_case(true, GIT_STATUS_CURRENT, GIT_STATUS_CURRENT);
+}
+
+void test_status_worktree__file_status_honors_core_ignorecase_false(void)
+{
+ assert_ignore_case(false, GIT_STATUS_WT_DELETED, GIT_STATUS_WT_NEW);
}
diff --git a/tests-clar/status/worktree_init.c b/tests-clar/status/worktree_init.c
new file mode 100644
index 000000000..b67107aec
--- /dev/null
+++ b/tests-clar/status/worktree_init.c
@@ -0,0 +1,339 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "ignore.h"
+#include "status_helpers.h"
+#include "posix.h"
+#include "util.h"
+#include "path.h"
+
+static void cleanup_new_repo(void *path)
+{
+ cl_fixture_cleanup((char *)path);
+}
+
+void test_status_worktree_init__cannot_retrieve_the_status_of_a_bare_repository(void)
+{
+ git_repository *repo;
+ unsigned int status = 0;
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ cl_assert_equal_i(GIT_EBAREREPO, git_status_file(&status, repo, "dummy"));
+ git_repository_free(repo);
+}
+
+void test_status_worktree_init__first_commit_in_progress(void)
+{
+ git_repository *repo;
+ git_index *index;
+ status_entry_single result;
+
+ cl_set_cleanup(&cleanup_new_repo, "getting_started");
+
+ cl_git_pass(git_repository_init(&repo, "getting_started", 0));
+ cl_git_mkfile("getting_started/testfile.txt", "content\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add_bypath(index, "testfile.txt"));
+ cl_git_pass(git_index_write(index));
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_INDEX_NEW);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+
+
+void test_status_worktree_init__status_file_without_index_or_workdir(void)
+{
+ git_repository *repo;
+ unsigned int status = 0;
+ git_index *index;
+
+ cl_git_pass(p_mkdir("wd", 0777));
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_set_workdir(repo, "wd", false));
+
+ cl_git_pass(git_index_open(&index, "empty-index"));
+ cl_assert_equal_i(0, (int)git_index_entrycount(index));
+ git_repository_set_index(repo, index);
+
+ cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));
+
+ cl_assert_equal_i(GIT_STATUS_INDEX_DELETED, status);
+
+ git_repository_free(repo);
+ git_index_free(index);
+ cl_git_pass(p_rmdir("wd"));
+}
+
+static void fill_index_wth_head_entries(git_repository *repo, git_index *index)
+{
+ git_oid oid;
+ git_commit *commit;
+ git_tree *tree;
+
+ cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
+ cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+ cl_git_pass(git_commit_tree(&tree, commit));
+
+ cl_git_pass(git_index_read_tree(index, tree));
+ cl_git_pass(git_index_write(index));
+
+ git_tree_free(tree);
+ git_commit_free(commit);
+}
+
+void test_status_worktree_init__status_file_with_clean_index_and_empty_workdir(void)
+{
+ git_repository *repo;
+ unsigned int status = 0;
+ git_index *index;
+
+ cl_git_pass(p_mkdir("wd", 0777));
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_set_workdir(repo, "wd", false));
+
+ cl_git_pass(git_index_open(&index, "my-index"));
+ fill_index_wth_head_entries(repo, index);
+
+ git_repository_set_index(repo, index);
+
+ cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));
+
+ cl_assert_equal_i(GIT_STATUS_WT_DELETED, status);
+
+ git_repository_free(repo);
+ git_index_free(index);
+ cl_git_pass(p_rmdir("wd"));
+ cl_git_pass(p_unlink("my-index"));
+}
+
+void test_status_worktree_init__bracket_in_filename(void)
+{
+ git_repository *repo;
+ git_index *index;
+ status_entry_single result;
+ unsigned int status_flags;
+ int error;
+
+ #define FILE_WITH_BRACKET "LICENSE[1].md"
+ #define FILE_WITHOUT_BRACKET "LICENSE1.md"
+
+ cl_set_cleanup(&cleanup_new_repo, "with_bracket");
+
+ cl_git_pass(git_repository_init(&repo, "with_bracket", 0));
+ cl_git_mkfile("with_bracket/" FILE_WITH_BRACKET, "I have a bracket in my name\n");
+
+ /* file is new to working directory */
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ /* ignore the file */
+
+ cl_git_rewritefile("with_bracket/.gitignore", "*.md\n.gitignore\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET));
+ cl_assert(status_flags == GIT_STATUS_IGNORED);
+
+ /* don't ignore the file */
+
+ cl_git_rewritefile("with_bracket/.gitignore", ".gitignore\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ /* add the file to the index */
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add_bypath(index, FILE_WITH_BRACKET));
+ cl_git_pass(git_index_write(index));
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_INDEX_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET));
+ cl_assert(status_flags == GIT_STATUS_INDEX_NEW);
+
+ /* Create file without bracket */
+
+ cl_git_mkfile("with_bracket/" FILE_WITHOUT_BRACKET, "I have no bracket in my name!\n");
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITHOUT_BRACKET));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, "LICENSE\\[1\\].md"));
+ cl_assert(status_flags == GIT_STATUS_INDEX_NEW);
+
+ error = git_status_file(&status_flags, repo, FILE_WITH_BRACKET);
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_EAMBIGUOUS, error);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_status_worktree_init__space_in_filename(void)
+{
+ git_repository *repo;
+ git_index *index;
+ status_entry_single result;
+ unsigned int status_flags;
+
+#define FILE_WITH_SPACE "LICENSE - copy.md"
+
+ cl_set_cleanup(&cleanup_new_repo, "with_space");
+ cl_git_pass(git_repository_init(&repo, "with_space", 0));
+ cl_git_mkfile("with_space/" FILE_WITH_SPACE, "I have a space in my name\n");
+
+ /* file is new to working directory */
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ /* ignore the file */
+
+ cl_git_rewritefile("with_space/.gitignore", "*.md\n.gitignore\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_IGNORED);
+
+ /* don't ignore the file */
+
+ cl_git_rewritefile("with_space/.gitignore", ".gitignore\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ /* add the file to the index */
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add_bypath(index, FILE_WITH_SPACE));
+ cl_git_pass(git_index_write(index));
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_INDEX_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_INDEX_NEW);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+static int cb_status__expected_path(const char *p, unsigned int s, void *payload)
+{
+ const char *expected_path = (const char *)payload;
+
+ GIT_UNUSED(s);
+
+ if (payload == NULL)
+ cl_fail("Unexpected path");
+
+ cl_assert_equal_s(expected_path, p);
+
+ return 0;
+}
+
+void test_status_worktree_init__disable_pathspec_match(void)
+{
+ git_repository *repo;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ char *file_with_bracket = "LICENSE[1].md",
+ *imaginary_file_with_bracket = "LICENSE[1-2].md";
+
+ cl_set_cleanup(&cleanup_new_repo, "pathspec");
+ cl_git_pass(git_repository_init(&repo, "pathspec", 0));
+ cl_git_mkfile("pathspec/LICENSE[1].md", "screaming bracket\n");
+ cl_git_mkfile("pathspec/LICENSE1.md", "no bracket\n");
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
+ opts.pathspec.count = 1;
+ opts.pathspec.strings = &file_with_bracket;
+
+ cl_git_pass(
+ git_status_foreach_ext(repo, &opts, cb_status__expected_path,
+ file_with_bracket)
+ );
+
+ /* Test passing a pathspec matching files in the workdir. */
+ /* Must not match because pathspecs are disabled. */
+ opts.pathspec.strings = &imaginary_file_with_bracket;
+ cl_git_pass(
+ git_status_foreach_ext(repo, &opts, cb_status__expected_path, NULL)
+ );
+
+ git_repository_free(repo);
+}
+
+void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
+{
+ git_repository *repo;
+ git_index *index;
+ unsigned int status;
+
+ cl_set_cleanup(&cleanup_new_repo, "getting_started");
+ cl_git_pass(git_repository_init(&repo, "getting_started", 0));
+
+ // Ensure that repo has core.autocrlf=true
+ cl_repo_set_bool(repo, "core.autocrlf", true);
+
+ cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add_bypath(index, "testfile.txt"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_status_file(&status, repo, "testfile.txt"));
+ cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c
new file mode 100644
index 000000000..acf8f6462
--- /dev/null
+++ b/tests-clar/submodule/lookup.c
@@ -0,0 +1,114 @@
+#include "clar_libgit2.h"
+#include "submodule_helpers.h"
+#include "posix.h"
+
+static git_repository *g_repo = NULL;
+
+void test_submodule_lookup__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("submod2");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+
+ /* must create submod2_target before rewrite so prettify will work */
+ rewrite_gitmodules(git_repository_workdir(g_repo));
+ p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+}
+
+void test_submodule_lookup__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ cl_fixture_cleanup("submod2_target");
+}
+
+void test_submodule_lookup__simple_lookup(void)
+{
+ git_submodule *sm;
+
+ /* lookup existing */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_assert(sm);
+
+ /* lookup pending change in .gitmodules that is not in HEAD */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_assert(sm);
+
+ /* lookup pending change in .gitmodules that is neither in HEAD nor index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
+ cl_assert(sm);
+
+ /* lookup git repo subdir that is not added as submodule */
+ cl_assert(git_submodule_lookup(&sm, g_repo, "not-submodule") == GIT_EEXISTS);
+
+ /* lookup existing directory that is not a submodule */
+ cl_assert(git_submodule_lookup(&sm, g_repo, "just_a_dir") == GIT_ENOTFOUND);
+
+ /* lookup existing file that is not a submodule */
+ cl_assert(git_submodule_lookup(&sm, g_repo, "just_a_file") == GIT_ENOTFOUND);
+
+ /* lookup non-existent item */
+ cl_assert(git_submodule_lookup(&sm, g_repo, "no_such_file") == GIT_ENOTFOUND);
+}
+
+void test_submodule_lookup__accessors(void)
+{
+ git_submodule *sm;
+ const char *oid = "480095882d281ed676fe5b863569520e54a7d5c0";
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_assert(git_submodule_owner(sm) == g_repo);
+ cl_assert_equal_s("sm_unchanged", git_submodule_name(sm));
+ cl_assert(git__suffixcmp(git_submodule_path(sm), "sm_unchanged") == 0);
+ cl_assert(git__suffixcmp(git_submodule_url(sm), "/submod2_target") == 0);
+
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0);
+
+ cl_assert(git_submodule_ignore(sm) == GIT_SUBMODULE_IGNORE_NONE);
+ cl_assert(git_submodule_update(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_assert_equal_s("sm_changed_head", git_submodule_name(sm));
+
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm),
+ "3d9386c507f6b093471a3e324085657a3c2b4247") == 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_assert_equal_s("sm_added_and_uncommited", git_submodule_name(sm));
+
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
+ cl_assert(git_submodule_head_id(sm) == NULL);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
+ cl_assert_equal_s("sm_missing_commits", git_submodule_name(sm));
+
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm),
+ "5e4963595a9774b90524d35a807169049de8ccad") == 0);
+}
+
+typedef struct {
+ int count;
+} sm_lookup_data;
+
+static int sm_lookup_cb(git_submodule *sm, const char *name, void *payload)
+{
+ sm_lookup_data *data = payload;
+ data->count += 1;
+ cl_assert_equal_s(git_submodule_name(sm), name);
+ return 0;
+}
+
+void test_submodule_lookup__foreach(void)
+{
+ sm_lookup_data data;
+ memset(&data, 0, sizeof(data));
+ cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
+ cl_assert_equal_i(8, data.count);
+}
diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c
new file mode 100644
index 000000000..94eb3738a
--- /dev/null
+++ b/tests-clar/submodule/modify.c
@@ -0,0 +1,266 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "path.h"
+#include "submodule_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+#define SM_LIBGIT2_URL "https://github.com/libgit2/libgit2.git"
+#define SM_LIBGIT2 "sm_libgit2"
+#define SM_LIBGIT2B "sm_libgit2b"
+
+void test_submodule_modify__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("submod2");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+
+ /* must create submod2_target before rewrite so prettify will work */
+ rewrite_gitmodules(git_repository_workdir(g_repo));
+ p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+}
+
+void test_submodule_modify__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ cl_fixture_cleanup("submod2_target");
+}
+
+void test_submodule_modify__add(void)
+{
+ git_submodule *sm;
+ git_config *cfg;
+ const char *s;
+
+ /* re-add existing submodule */
+ cl_assert(
+ git_submodule_add_setup(NULL, g_repo, "whatever", "sm_unchanged", 1) ==
+ GIT_EEXISTS );
+
+ /* add a submodule using a gitlink */
+
+ cl_git_pass(
+ git_submodule_add_setup(&sm, g_repo, SM_LIBGIT2_URL, SM_LIBGIT2, 1)
+ );
+
+ cl_assert(git_path_isfile("submod2/" SM_LIBGIT2 "/.git"));
+
+ cl_assert(git_path_isdir("submod2/.git/modules"));
+ cl_assert(git_path_isdir("submod2/.git/modules/" SM_LIBGIT2));
+ cl_assert(git_path_isfile("submod2/.git/modules/" SM_LIBGIT2 "/HEAD"));
+
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(
+ git_config_get_string(&s, cfg, "submodule." SM_LIBGIT2 ".url"));
+ cl_assert_equal_s(s, SM_LIBGIT2_URL);
+ git_config_free(cfg);
+
+ /* add a submodule not using a gitlink */
+
+ cl_git_pass(
+ git_submodule_add_setup(&sm, g_repo, SM_LIBGIT2_URL, SM_LIBGIT2B, 0)
+ );
+
+ cl_assert(git_path_isdir("submod2/" SM_LIBGIT2B "/.git"));
+ cl_assert(git_path_isfile("submod2/" SM_LIBGIT2B "/.git/HEAD"));
+ cl_assert(!git_path_exists("submod2/.git/modules/" SM_LIBGIT2B));
+
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(
+ git_config_get_string(&s, cfg, "submodule." SM_LIBGIT2B ".url"));
+ cl_assert_equal_s(s, SM_LIBGIT2_URL);
+ git_config_free(cfg);
+}
+
+static int delete_one_config(const git_config_entry *entry, void *payload)
+{
+ git_config *cfg = payload;
+ return git_config_delete_entry(cfg, entry->name);
+}
+
+static int init_one_submodule(
+ git_submodule *sm, const char *name, void *payload)
+{
+ GIT_UNUSED(name);
+ GIT_UNUSED(payload);
+ return git_submodule_init(sm, false);
+}
+
+void test_submodule_modify__init(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ /* erase submodule data from .git/config */
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(
+ git_config_foreach_match(cfg, "submodule\\..*", delete_one_config, cfg));
+ git_config_free(cfg);
+
+ /* confirm no submodule data in config */
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url"));
+ cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url"));
+ cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url"));
+ git_config_free(cfg);
+
+ /* call init and see that settings are copied */
+ cl_git_pass(git_submodule_foreach(g_repo, init_one_submodule, NULL));
+
+ git_submodule_reload_all(g_repo);
+
+ /* confirm submodule data in config */
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url"));
+ cl_assert(git__suffixcmp(str, "/submod2_target") == 0);
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url"));
+ cl_assert(git__suffixcmp(str, "/submod2_target") == 0);
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url"));
+ cl_assert(git__suffixcmp(str, "/submod2_target") == 0);
+ git_config_free(cfg);
+}
+
+static int sync_one_submodule(
+ git_submodule *sm, const char *name, void *payload)
+{
+ GIT_UNUSED(name);
+ GIT_UNUSED(payload);
+ return git_submodule_sync(sm);
+}
+
+void test_submodule_modify__sync(void)
+{
+ git_submodule *sm1, *sm2, *sm3;
+ git_config *cfg;
+ const char *str;
+
+#define SM1 "sm_unchanged"
+#define SM2 "sm_changed_head"
+#define SM3 "sm_added_and_uncommited"
+
+ /* look up some submodules */
+ cl_git_pass(git_submodule_lookup(&sm1, g_repo, SM1));
+ cl_git_pass(git_submodule_lookup(&sm2, g_repo, SM2));
+ cl_git_pass(git_submodule_lookup(&sm3, g_repo, SM3));
+
+ /* At this point, the .git/config URLs for the submodules have
+ * not be rewritten with the absolute paths (although the
+ * .gitmodules have. Let's confirm that they DO NOT match
+ * yet, then we can do a sync to make them match...
+ */
+
+ /* check submodule info does not match before sync */
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM1".url"));
+ cl_assert(strcmp(git_submodule_url(sm1), str) != 0);
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM2".url"));
+ cl_assert(strcmp(git_submodule_url(sm2), str) != 0);
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM3".url"));
+ cl_assert(strcmp(git_submodule_url(sm3), str) != 0);
+ git_config_free(cfg);
+
+ /* sync all the submodules */
+ cl_git_pass(git_submodule_foreach(g_repo, sync_one_submodule, NULL));
+
+ /* check that submodule config is updated */
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM1".url"));
+ cl_assert_equal_s(git_submodule_url(sm1), str);
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM2".url"));
+ cl_assert_equal_s(git_submodule_url(sm2), str);
+ cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM3".url"));
+ cl_assert_equal_s(git_submodule_url(sm3), str);
+ git_config_free(cfg);
+}
+
+void test_submodule_modify__edit_and_save(void)
+{
+ git_submodule *sm1, *sm2;
+ char *old_url;
+ git_submodule_ignore_t old_ignore;
+ git_submodule_update_t old_update;
+ git_repository *r2;
+ int old_fetchrecurse;
+
+ cl_git_pass(git_submodule_lookup(&sm1, g_repo, "sm_changed_head"));
+
+ old_url = git__strdup(git_submodule_url(sm1));
+
+ /* modify properties of submodule */
+ cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
+ old_ignore = git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
+ old_update = git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
+ old_fetchrecurse = git_submodule_set_fetch_recurse_submodules(sm1, 1);
+
+ cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));
+
+ /* revert without saving (and confirm setters return old value) */
+ cl_git_pass(git_submodule_set_url(sm1, old_url));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_IGNORE_UNTRACKED,
+ (int)git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_DEFAULT));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_UPDATE_REBASE,
+ (int)git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_DEFAULT));
+ cl_assert_equal_i(
+ 1, git_submodule_set_fetch_recurse_submodules(sm1, old_fetchrecurse));
+
+ /* check that revert was successful */
+ cl_assert_equal_s(old_url, git_submodule_url(sm1));
+ cl_assert_equal_i((int)old_ignore, (int)git_submodule_ignore(sm1));
+ cl_assert_equal_i((int)old_update, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(
+ old_fetchrecurse, git_submodule_fetch_recurse_submodules(sm1));
+
+ /* modify properties of submodule (again) */
+ cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
+ git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
+ git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
+ git_submodule_set_fetch_recurse_submodules(sm1, 1);
+
+ /* call save */
+ cl_git_pass(git_submodule_save(sm1));
+
+ /* attempt to "revert" values */
+ git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_DEFAULT);
+ git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_DEFAULT);
+
+ /* but ignore and update should NOT revert because the DEFAULT
+ * should now be the newly saved value...
+ */
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));
+
+ /* call reload and check that the new values are loaded */
+ cl_git_pass(git_submodule_reload(sm1));
+
+ cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));
+
+ /* open a second copy of the repo and compare submodule */
+ cl_git_pass(git_repository_open(&r2, "submod2"));
+ cl_git_pass(git_submodule_lookup(&sm2, r2, "sm_changed_head"));
+
+ cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm2));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm2));
+ cl_assert_equal_i(
+ (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm2));
+ cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm2));
+
+ git_repository_free(r2);
+ git__free(old_url);
+}
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
new file mode 100644
index 000000000..282e82758
--- /dev/null
+++ b/tests-clar/submodule/status.c
@@ -0,0 +1,385 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "path.h"
+#include "submodule_helpers.h"
+#include "fileops.h"
+#include "iterator.h"
+
+static git_repository *g_repo = NULL;
+
+void test_submodule_status__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("submod2");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+
+ /* must create submod2_target before rewrite so prettify will work */
+ rewrite_gitmodules(git_repository_workdir(g_repo));
+ p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+ p_rename("submod2/not/.gitted", "submod2/not/.git");
+}
+
+void test_submodule_status__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ cl_fixture_cleanup("submod2_target");
+}
+
+void test_submodule_status__unchanged(void)
+{
+ unsigned int status, expected;
+ git_submodule *sm;
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ expected = GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_IN_WD;
+
+ cl_assert(status == expected);
+}
+
+/* 4 values of GIT_SUBMODULE_IGNORE to check */
+
+void test_submodule_status__ignore_none(void)
+{
+ unsigned int status;
+ git_submodule *sm;
+ git_buf path = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+ cl_assert_equal_i(GIT_EEXISTS,
+ git_submodule_lookup(&sm, g_repo, "not-submodule"));
+ cl_assert_equal_i(GIT_EEXISTS,
+ git_submodule_lookup(&sm, g_repo, "not"));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNTRACKED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0);
+
+ /* removed sm_unchanged for deleted workdir */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
+
+ /* now mkdir sm_unchanged to test uninitialized */
+ cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_reload(sm));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
+
+ /* update sm_changed_head in index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_add_to_index(sm, true));
+ /* reload is not needed because add_to_index updates the submodule data */
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0);
+
+ /* remove sm_changed_head from index */
+ {
+ git_index *index;
+ size_t pos;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_assert(!git_index_find(&pos, index, "sm_changed_head"));
+ cl_git_pass(git_index_remove(index, "sm_changed_head", 0));
+ cl_git_pass(git_index_write(index));
+
+ git_index_free(index);
+ }
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_reload(sm));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_DELETED) != 0);
+
+ git_buf_free(&path);
+}
+
+static int set_sm_ignore(git_submodule *sm, const char *name, void *payload)
+{
+ git_submodule_ignore_t ignore = *(git_submodule_ignore_t *)payload;
+ GIT_UNUSED(name);
+ git_submodule_set_ignore(sm, ignore);
+ return 0;
+}
+
+void test_submodule_status__ignore_untracked(void)
+{
+ unsigned int status;
+ git_submodule *sm;
+ git_buf path = GIT_BUF_INIT;
+ git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_UNTRACKED;
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+
+ cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
+
+ cl_git_fail(git_submodule_lookup(&sm, g_repo, "not-submodule"));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0);
+
+ /* removed sm_unchanged for deleted workdir */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
+
+ /* now mkdir sm_unchanged to test uninitialized */
+ cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_reload(sm));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
+
+ /* update sm_changed_head in index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_add_to_index(sm, true));
+ /* reload is not needed because add_to_index updates the submodule data */
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0);
+
+ git_buf_free(&path);
+}
+
+void test_submodule_status__ignore_dirty(void)
+{
+ unsigned int status;
+ git_submodule *sm;
+ git_buf path = GIT_BUF_INIT;
+ git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_DIRTY;
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+
+ cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+ cl_assert_equal_i(GIT_EEXISTS,
+ git_submodule_lookup(&sm, g_repo, "not-submodule"));
+ cl_assert_equal_i(GIT_EEXISTS,
+ git_submodule_lookup(&sm, g_repo, "not"));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0);
+
+ /* removed sm_unchanged for deleted workdir */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
+
+ /* now mkdir sm_unchanged to test uninitialized */
+ cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_reload(sm));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
+
+ /* update sm_changed_head in index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_add_to_index(sm, true));
+ /* reload is not needed because add_to_index updates the submodule data */
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0);
+
+ git_buf_free(&path);
+}
+
+void test_submodule_status__ignore_all(void)
+{
+ unsigned int status;
+ git_submodule *sm;
+ git_buf path = GIT_BUF_INIT;
+ git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_ALL;
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+
+ cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+ cl_assert_equal_i(GIT_EEXISTS,
+ git_submodule_lookup(&sm, g_repo, "not-submodule"));
+ cl_assert_equal_i(GIT_EEXISTS,
+ git_submodule_lookup(&sm, g_repo, "not"));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ /* removed sm_unchanged for deleted workdir */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ /* now mkdir sm_unchanged to test uninitialized */
+ cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_reload(sm));
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ /* update sm_changed_head in index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
+ cl_git_pass(git_submodule_add_to_index(sm, true));
+ /* reload is not needed because add_to_index updates the submodule data */
+ cl_git_pass(git_submodule_status(&status, sm));
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+
+ git_buf_free(&path);
+}
+
+typedef struct {
+ size_t counter;
+ const char **paths;
+} submodule_expectations;
+
+static int confirm_submodule_status(
+ const char *path, unsigned int status_flags, void *payload)
+{
+ submodule_expectations *exp = payload;
+
+ while (git__suffixcmp(exp->paths[exp->counter], "/") == 0)
+ exp->counter++;
+
+ cl_assert_equal_s(exp->paths[exp->counter++], path);
+
+ GIT_UNUSED(status_flags);
+
+ return 0;
+}
+
+void test_submodule_status__iterator(void)
+{
+ git_iterator *iter;
+ const git_index_entry *entry;
+ size_t i;
+ static const char *expected[] = {
+ ".gitmodules",
+ "just_a_dir/",
+ "just_a_dir/contents",
+ "just_a_file",
+ "not",
+ "not-submodule",
+ "README.txt",
+ "sm_added_and_uncommited",
+ "sm_changed_file",
+ "sm_changed_head",
+ "sm_changed_index",
+ "sm_changed_untracked_file",
+ "sm_missing_commits",
+ "sm_unchanged",
+ NULL
+ };
+ submodule_expectations exp = { 0, expected };
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+
+ cl_git_pass(git_iterator_for_workdir(&iter, g_repo,
+ GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ cl_git_pass(git_iterator_current(&entry, iter));
+
+ for (i = 0; entry; ++i) {
+ cl_assert_equal_s(expected[i], entry->path);
+ cl_git_pass(git_iterator_advance(&entry, iter));
+ }
+
+ git_iterator_free(iter);
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ cl_git_pass(git_status_foreach_ext(g_repo, &opts, confirm_submodule_status, &exp));
+}
diff --git a/tests-clar/submodule/submodule_helpers.c b/tests-clar/submodule/submodule_helpers.c
new file mode 100644
index 000000000..0c3e79f71
--- /dev/null
+++ b/tests-clar/submodule/submodule_helpers.c
@@ -0,0 +1,84 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "path.h"
+#include "util.h"
+#include "posix.h"
+#include "submodule_helpers.h"
+
+/* rewrite gitmodules -> .gitmodules
+ * rewrite the empty or relative urls inside each module
+ * rename the .gitted directory inside any submodule to .git
+ */
+void rewrite_gitmodules(const char *workdir)
+{
+ git_buf in_f = GIT_BUF_INIT, out_f = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ FILE *in, *out;
+ char line[256];
+
+ cl_git_pass(git_buf_joinpath(&in_f, workdir, "gitmodules"));
+ cl_git_pass(git_buf_joinpath(&out_f, workdir, ".gitmodules"));
+
+ cl_assert((in = fopen(in_f.ptr, "r")) != NULL);
+ cl_assert((out = fopen(out_f.ptr, "w")) != NULL);
+
+ while (fgets(line, sizeof(line), in) != NULL) {
+ char *scan = line;
+
+ while (*scan == ' ' || *scan == '\t') scan++;
+
+ /* rename .gitted -> .git in submodule directories */
+ if (git__prefixcmp(scan, "path =") == 0) {
+ scan += strlen("path =");
+ while (*scan == ' ') scan++;
+
+ git_buf_joinpath(&path, workdir, scan);
+ git_buf_rtrim(&path);
+ git_buf_joinpath(&path, path.ptr, ".gitted");
+
+ if (!git_buf_oom(&path) && p_access(path.ptr, F_OK) == 0) {
+ git_buf_joinpath(&out_f, workdir, scan);
+ git_buf_rtrim(&out_f);
+ git_buf_joinpath(&out_f, out_f.ptr, ".git");
+
+ if (!git_buf_oom(&out_f))
+ p_rename(path.ptr, out_f.ptr);
+ }
+ }
+
+ /* copy non-"url =" lines verbatim */
+ if (git__prefixcmp(scan, "url =") != 0) {
+ fputs(line, out);
+ continue;
+ }
+
+ /* convert relative URLs in "url =" lines */
+ scan += strlen("url =");
+ while (*scan == ' ') scan++;
+
+ if (*scan == '.') {
+ git_buf_joinpath(&path, workdir, scan);
+ git_buf_rtrim(&path);
+ } else if (!*scan || *scan == '\n') {
+ git_buf_joinpath(&path, workdir, "../testrepo.git");
+ } else {
+ fputs(line, out);
+ continue;
+ }
+
+ git_path_prettify(&path, path.ptr, NULL);
+ git_buf_putc(&path, '\n');
+ cl_assert(!git_buf_oom(&path));
+
+ fwrite(line, scan - line, sizeof(char), out);
+ fputs(path.ptr, out);
+ }
+
+ fclose(in);
+ fclose(out);
+
+ cl_must_pass(p_unlink(in_f.ptr));
+
+ git_buf_free(&in_f);
+ git_buf_free(&out_f);
+ git_buf_free(&path);
+}
diff --git a/tests-clar/submodule/submodule_helpers.h b/tests-clar/submodule/submodule_helpers.h
new file mode 100644
index 000000000..6b76a832e
--- /dev/null
+++ b/tests-clar/submodule/submodule_helpers.h
@@ -0,0 +1,2 @@
+extern void rewrite_gitmodules(const char *workdir);
+
diff --git a/tests-clar/threads/basic.c b/tests-clar/threads/basic.c
index 2b1c36808..a15c53140 100644
--- a/tests-clar/threads/basic.c
+++ b/tests-clar/threads/basic.c
@@ -5,16 +5,19 @@
static git_repository *g_repo;
-void test_threads_basic__initialize(void) {
- g_repo = cl_git_sandbox_init("testrepo");
+void test_threads_basic__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
}
-void test_threads_basic__cleanup(void) {
- cl_git_sandbox_cleanup();
+void test_threads_basic__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
}
-void test_threads_basic__cache(void) {
- // run several threads polling the cache at the same time
- cl_assert(1 == 1);
+void test_threads_basic__cache(void)
+{
+ // run several threads polling the cache at the same time
+ cl_assert(1 == 1);
}
diff --git a/tests-clar/trace/trace.c b/tests-clar/trace/trace.c
new file mode 100644
index 000000000..cc99cd187
--- /dev/null
+++ b/tests-clar/trace/trace.c
@@ -0,0 +1,88 @@
+#include "clar_libgit2.h"
+#include "trace.h"
+
+static int written = 0;
+
+static void trace_callback(git_trace_level_t level, const char *message)
+{
+ GIT_UNUSED(level);
+
+ cl_assert(strcmp(message, "Hello world!") == 0);
+
+ written = 1;
+}
+
+void test_trace_trace__initialize(void)
+{
+ git_trace_set(GIT_TRACE_INFO, trace_callback);
+ written = 0;
+}
+
+void test_trace_trace__cleanup(void)
+{
+ git_trace_set(GIT_TRACE_NONE, NULL);
+}
+
+void test_trace_trace__sets(void)
+{
+#ifdef GIT_TRACE
+ cl_assert(git_trace_level() == GIT_TRACE_INFO);
+#endif
+}
+
+void test_trace_trace__can_reset(void)
+{
+#ifdef GIT_TRACE
+ cl_assert(git_trace_level() == GIT_TRACE_INFO);
+ cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback));
+
+ cl_assert(written == 0);
+ git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
+ cl_assert(written == 0);
+
+ git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
+ cl_assert(written == 1);
+#endif
+}
+
+void test_trace_trace__can_unset(void)
+{
+#ifdef GIT_TRACE
+ cl_assert(git_trace_level() == GIT_TRACE_INFO);
+ cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL));
+
+ cl_assert(git_trace_level() == GIT_TRACE_NONE);
+
+ cl_assert(written == 0);
+ git_trace(GIT_TRACE_FATAL, "Hello %s!", "world");
+ cl_assert(written == 0);
+#endif
+}
+
+void test_trace_trace__skips_higher_level(void)
+{
+#ifdef GIT_TRACE
+ cl_assert(written == 0);
+ git_trace(GIT_TRACE_DEBUG, "Hello %s!", "world");
+ cl_assert(written == 0);
+#endif
+}
+
+void test_trace_trace__writes(void)
+{
+#ifdef GIT_TRACE
+ cl_assert(written == 0);
+ git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
+ cl_assert(written == 1);
+#endif
+}
+
+void test_trace_trace__writes_lower_level(void)
+{
+#ifdef GIT_TRACE
+ cl_assert(written == 0);
+ git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
+ cl_assert(written == 1);
+#endif
+}
+
diff --git a/tests-clar/valgrind-supp-mac.txt b/tests-clar/valgrind-supp-mac.txt
new file mode 100644
index 000000000..03e60dcd7
--- /dev/null
+++ b/tests-clar/valgrind-supp-mac.txt
@@ -0,0 +1,82 @@
+{
+ libgit2-giterr-set-buffer
+ Memcheck:Leak
+ ...
+ fun:git__realloc
+ fun:git_buf_try_grow
+ fun:git_buf_grow
+ fun:git_buf_vprintf
+ fun:giterr_set
+}
+{
+ mac-setenv-leak-1
+ Memcheck:Leak
+ fun:malloc_zone_malloc
+ fun:__setenv
+ fun:setenv
+}
+{
+ mac-setenv-leak-2
+ Memcheck:Leak
+ fun:malloc_zone_malloc
+ fun:malloc_set_zone_name
+ ...
+ fun:init__zone0
+ fun:setenv
+}
+{
+ mac-dyld-initializer-leak
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:dyld_register_image_state_change_handler
+ fun:_dyld_initializer
+}
+{
+ mac-tz-leak-1
+ Memcheck:Leak
+ ...
+ fun:token_table_add
+ fun:notify_register_check
+ fun:notify_register_tz
+}
+{
+ mac-tz-leak-2
+ Memcheck:Leak
+ fun:malloc
+ fun:tzload
+}
+{
+ mac-tz-leak-3
+ Memcheck:Leak
+ fun:malloc
+ fun:tzsetwall_basic
+}
+{
+ mac-tz-leak-4
+ Memcheck:Leak
+ fun:malloc
+ fun:gmtsub
+}
+{
+ mac-system-init-leak-1
+ Memcheck:Leak
+ ...
+ fun:_libxpc_initializer
+ fun:libSystem_initializer
+}
+{
+ mac-system-init-leak-2
+ Memcheck:Leak
+ ...
+ fun:__keymgr_initializer
+ fun:libSystem_initializer
+}
+{
+ mac-puts-leak
+ Memcheck:Leak
+ fun:malloc
+ fun:__smakebuf
+ ...
+ fun:puts
+}