From d578b71d61ee8131e8abf7f538b93d8c6cc6fe6d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 27 Mar 2019 17:33:00 +0800 Subject: [PATCH] move code.gitea.io/git to code.gitea.io/gitea/modules/git (#6364) * move code.gitea.io/git to code.gitea.io/gitea/modules/git * fix imports * fix fmt * fix misspell * remove wrong tests data * fix unit tests * fix tests * fix tests * fix tests * fix tests * fix tests * enable Debug to trace the failure tests * fix tests * fix tests * fix tests * fix tests * fix tests * comment commit count tests since git clone depth is 50 * fix tests * update from code.gitea.io/git * revert change to makefile --- Gopkg.lock | 19 +- cmd/admin.go | 2 +- cmd/hook.go | 2 +- cmd/serv.go | 2 +- integrations/api_releases_test.go | 2 +- .../git_helper_for_declarative_test.go | 2 +- integrations/git_test.go | 2 +- integrations/ssh_key_test.go | 2 +- models/action.go | 2 +- models/action_test.go | 2 +- models/git_diff.go | 2 +- models/gpg_key.go | 2 +- models/graph.go | 2 +- models/graph_test.go | 2 +- models/issue_comment.go | 2 +- models/migrations/v28.go | 2 +- models/migrations/v39.go | 2 +- models/migrations/v82.go | 2 +- models/pull.go | 2 +- models/release.go | 4 +- models/release_test.go | 2 +- models/repo.go | 2 +- models/repo_branch.go | 2 +- models/repo_indexer.go | 2 +- models/repo_mirror.go | 2 +- models/repo_tag.go | 2 +- models/status.go | 2 +- models/update.go | 2 +- models/update_test.go | 2 +- models/user.go | 2 +- models/webhook_dingtalk.go | 3 +- models/webhook_discord.go | 2 +- models/webhook_slack.go | 2 +- models/wiki.go | 7 +- modules/base/tool.go | 3 +- modules/context/api.go | 3 +- modules/context/repo.go | 2 +- modules/git/README.md | 3 + {vendor/code.gitea.io => modules}/git/blob.go | 0 modules/git/blob_test.go | 80 ++ .../code.gitea.io => modules}/git/cache.go | 0 .../code.gitea.io => modules}/git/command.go | 4 +- modules/git/command_test.go | 41 + .../code.gitea.io => modules}/git/commit.go | 0 .../git/commit_archive.go | 0 .../git/commit_info.go | 0 modules/git/commit_info_test.go | 117 +++ modules/git/commit_test.go | 38 + .../code.gitea.io => modules}/git/error.go | 0 {vendor/code.gitea.io => modules}/git/git.go | 0 {vendor/code.gitea.io => modules}/git/hook.go | 13 +- .../code.gitea.io => modules}/git/parse.go | 0 modules/git/parse_test.go | 58 ++ {vendor/code.gitea.io => modules}/git/ref.go | 0 {vendor/code.gitea.io => modules}/git/repo.go | 0 .../git/repo_blame.go | 0 .../git/repo_blob.go | 0 modules/git/repo_blob_test.go | 66 ++ .../git/repo_branch.go | 0 modules/git/repo_branch_test.go | 39 + .../git/repo_commit.go | 4 +- modules/git/repo_commit_test.go | 59 ++ .../git/repo_hook.go | 2 +- .../git/repo_object.go | 0 .../git/repo_pull.go | 0 modules/git/repo_pull_test.go | 30 + .../code.gitea.io => modules}/git/repo_ref.go | 0 modules/git/repo_ref_test.go | 49 + .../code.gitea.io => modules}/git/repo_tag.go | 0 modules/git/repo_tag_test.go | 44 + modules/git/repo_test.go | 26 + .../git/repo_tree.go | 2 +- {vendor/code.gitea.io => modules}/git/sha1.go | 0 .../git/signature.go | 0 .../git/submodule.go | 0 modules/git/submodule_test.go | 29 + {vendor/code.gitea.io => modules}/git/tag.go | 0 modules/git/tests/repos/repo1_bare/HEAD | 1 + modules/git/tests/repos/repo1_bare/config | 4 + .../git/tests/repos/repo1_bare/description | 1 + .../repo1_bare/hooks/applypatch-msg.sample | 15 + .../repos/repo1_bare/hooks/commit-msg.sample | 24 + .../repos/repo1_bare/hooks/post-update.sample | 8 + .../repo1_bare/hooks/pre-applypatch.sample | 14 + .../repos/repo1_bare/hooks/pre-commit.sample | 49 + .../repos/repo1_bare/hooks/pre-push.sample | 53 ++ .../repos/repo1_bare/hooks/pre-rebase.sample | 169 ++++ .../repos/repo1_bare/hooks/pre-receive.sample | 24 + .../hooks/prepare-commit-msg.sample | 36 + .../repos/repo1_bare/hooks/update.sample | 128 +++ .../git/tests/repos/repo1_bare/info/exclude | 6 + .../0b/9f291245f6c596fd30bee925fe94fe0cbadd60 | Bin 0 -> 54 bytes .../11/93ff46343f4f6a0522e2b28b871e905178c1f0 | Bin 0 -> 23 bytes .../15/3f451b9ee7fa1da317ab17a127e9fd9d384310 | Bin 0 -> 31 bytes .../18/4d49c75a0b202b1d2ea2fcb5861c329321fcd6 | Bin 0 -> 56 bytes .../21/6bf54c2f2e2916b830ebe09e8c58a6ed52d86b | Bin 0 -> 28 bytes .../28/39944139e0de9737a044f78b0e4b40d989a9e3 | 1 + .../2e/65efe2a145dda7ee51d1741299f848e5bf752e | Bin 0 -> 16 bytes .../30/4c56b3bef33d0afeb8515ee803c839daf30ab8 | Bin 0 -> 85 bytes .../34/d1da713bf7de1c535e1d7d3ca985afd84bc7e5 | Bin 0 -> 23 bytes .../37/991dec2c8e592043f47155ce4808d4580f9123 | 1 + .../38/441bf2c4d4c27efff94728c9eb33266f44a702 | Bin 0 -> 134 bytes .../3a/d28a9149a2864384548f3d17ed7f38014c9e8a | Bin 0 -> 638 bytes .../50/13716a9da8e66ea21059a84f1b4311424d2b7f | Bin 0 -> 31 bytes .../59/dfb0bb505a601006e31fed53d2e24e44fca9ca | Bin 0 -> 144 bytes .../5c/80b0245c1c6f8343fa418ec374b13b5d4ee658 | 3 + .../62/d735f9efa9cf5b7df6bac9917b80e4779f4315 | Bin 0 -> 111 bytes .../64/3a35374408002fcf2f0e8d42d262a1e0e2f80e | Bin 0 -> 32 bytes .../6c/493ff740f9380390d5c9ddef4af18697ac9375 | Bin 0 -> 21 bytes .../6f/bd69e9823458e6c4a2fc5c0f6bc022b2f2acd1 | 1 + .../7e/3b688f3369ca28ebafbda9f8ef39713dd12fc8 | Bin 0 -> 85 bytes .../80/06ff9adbf0cb94da7dad9e537e53817f9fa5c0 | Bin 0 -> 176 bytes .../82/26f571dcc2d2f33a7179d929b10b9c39faa631 | Bin 0 -> 71 bytes .../83/b9c4da46ed59098a009f8640c77eac97b71dfe | Bin 0 -> 115 bytes .../8d/92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2 | Bin 0 -> 153 bytes .../95/bb4d39648ee7e325106df01a621c530863a653 | Bin 0 -> 121 bytes .../98/1ff127cc331753bba28e1377c35934f1ca9b56 | Bin 0 -> 56 bytes .../9c/9aef8dd84e02bc7ec12641deb4c930a7c30185 | 2 + .../b1/4df6442ea5a1b382985a6549b85d435376c351 | Bin 0 -> 18 bytes .../b1/fc9917b618c924cf4aa421dae74e8bf9b556d3 | Bin 0 -> 176 bytes .../b7/5f44edbd9252c32bf9faa0c1257ffb3b126c24 | Bin 0 -> 80 bytes .../c8/c90111bdc18b3afd2b2906007059e95ac8fdc3 | Bin 0 -> 111 bytes .../d0/845fe2f85710b50d673dafe98236bf9f2023da | Bin 0 -> 50 bytes .../e2/129701f1a4d54dc44f03c93bca0a2aec7c5449 | Bin 0 -> 21 bytes .../f1/a6cb52b2d16773290cefe49ad0684b50a4f930 | Bin 0 -> 111 bytes .../tests/repos/repo1_bare/refs/heads/branch1 | 1 + .../tests/repos/repo1_bare/refs/heads/branch2 | 1 + .../tests/repos/repo1_bare/refs/heads/master | 1 + .../git/tests/repos/repo1_bare/refs/tags/test | 1 + {vendor/code.gitea.io => modules}/git/tree.go | 4 +- .../git/tree_blob.go | 4 +- .../git/tree_entry.go | 2 +- modules/git/tree_entry_test.go | 98 ++ .../code.gitea.io => modules}/git/utils.go | 0 modules/notification/base/notifier.go | 2 +- modules/notification/base/null.go | 2 +- modules/notification/notification.go | 2 +- modules/notification/ui/ui.go | 2 +- modules/setting/git.go | 3 +- modules/setting/setting.go | 2 +- modules/test/context_tests.go | 5 +- modules/uploader/delete.go | 2 +- modules/uploader/update.go | 2 +- modules/uploader/upload.go | 5 +- routers/api/v1/convert/convert.go | 9 +- routers/api/v1/repo/commits.go | 5 +- routers/api/v1/repo/file.go | 3 +- routers/api/v1/repo/git_ref.go | 3 +- routers/api/v1/repo/hook.go | 2 +- routers/api/v1/repo/pull.go | 3 +- routers/api/v1/repo/tree.go | 2 +- routers/init.go | 2 +- routers/private/push_update.go | 2 +- routers/repo/branch.go | 2 +- routers/repo/commit.go | 2 +- routers/repo/download.go | 3 +- routers/repo/editor.go | 2 +- routers/repo/issue.go | 8 +- routers/repo/middlewares.go | 2 +- routers/repo/pull.go | 2 +- routers/repo/repo.go | 7 +- routers/repo/setting.go | 3 +- routers/repo/setting_protected_branch.go | 2 +- routers/repo/view.go | 2 +- routers/repo/webhook.go | 2 +- routers/repo/wiki.go | 3 +- routers/repo/wiki_test.go | 2 +- vendor/code.gitea.io/git/LICENSE | 20 - vendor/code.gitea.io/git/doc.go | 5 - .../stretchr/testify/require/doc.go | 28 + .../testify/require/forward_requirements.go | 16 + .../stretchr/testify/require/require.go | 867 ++++++++++++++++++ .../testify/require/require_forward.go | 687 ++++++++++++++ .../stretchr/testify/require/requirements.go | 9 + 174 files changed, 3044 insertions(+), 145 deletions(-) create mode 100644 modules/git/README.md rename {vendor/code.gitea.io => modules}/git/blob.go (100%) create mode 100644 modules/git/blob_test.go rename {vendor/code.gitea.io => modules}/git/cache.go (100%) rename {vendor/code.gitea.io => modules}/git/command.go (96%) create mode 100644 modules/git/command_test.go rename {vendor/code.gitea.io => modules}/git/commit.go (100%) rename {vendor/code.gitea.io => modules}/git/commit_archive.go (100%) rename {vendor/code.gitea.io => modules}/git/commit_info.go (100%) create mode 100644 modules/git/commit_info_test.go create mode 100644 modules/git/commit_test.go rename {vendor/code.gitea.io => modules}/git/error.go (100%) rename {vendor/code.gitea.io => modules}/git/git.go (100%) rename {vendor/code.gitea.io => modules}/git/hook.go (92%) rename {vendor/code.gitea.io => modules}/git/parse.go (100%) create mode 100644 modules/git/parse_test.go rename {vendor/code.gitea.io => modules}/git/ref.go (100%) rename {vendor/code.gitea.io => modules}/git/repo.go (100%) rename {vendor/code.gitea.io => modules}/git/repo_blame.go (100%) rename {vendor/code.gitea.io => modules}/git/repo_blob.go (100%) create mode 100644 modules/git/repo_blob_test.go rename {vendor/code.gitea.io => modules}/git/repo_branch.go (100%) create mode 100644 modules/git/repo_branch_test.go rename {vendor/code.gitea.io => modules}/git/repo_commit.go (98%) create mode 100644 modules/git/repo_commit_test.go rename {vendor/code.gitea.io => modules}/git/repo_hook.go (87%) rename {vendor/code.gitea.io => modules}/git/repo_object.go (100%) rename {vendor/code.gitea.io => modules}/git/repo_pull.go (100%) create mode 100644 modules/git/repo_pull_test.go rename {vendor/code.gitea.io => modules}/git/repo_ref.go (100%) create mode 100644 modules/git/repo_ref_test.go rename {vendor/code.gitea.io => modules}/git/repo_tag.go (100%) create mode 100644 modules/git/repo_tag_test.go create mode 100644 modules/git/repo_test.go rename {vendor/code.gitea.io => modules}/git/repo_tree.go (97%) rename {vendor/code.gitea.io => modules}/git/sha1.go (100%) rename {vendor/code.gitea.io => modules}/git/signature.go (100%) rename {vendor/code.gitea.io => modules}/git/submodule.go (100%) create mode 100644 modules/git/submodule_test.go rename {vendor/code.gitea.io => modules}/git/tag.go (100%) create mode 100644 modules/git/tests/repos/repo1_bare/HEAD create mode 100644 modules/git/tests/repos/repo1_bare/config create mode 100644 modules/git/tests/repos/repo1_bare/description create mode 100755 modules/git/tests/repos/repo1_bare/hooks/applypatch-msg.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/commit-msg.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/post-update.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/pre-applypatch.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/pre-commit.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/pre-push.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/pre-rebase.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/pre-receive.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/prepare-commit-msg.sample create mode 100755 modules/git/tests/repos/repo1_bare/hooks/update.sample create mode 100644 modules/git/tests/repos/repo1_bare/info/exclude create mode 100644 modules/git/tests/repos/repo1_bare/objects/0b/9f291245f6c596fd30bee925fe94fe0cbadd60 create mode 100644 modules/git/tests/repos/repo1_bare/objects/11/93ff46343f4f6a0522e2b28b871e905178c1f0 create mode 100644 modules/git/tests/repos/repo1_bare/objects/15/3f451b9ee7fa1da317ab17a127e9fd9d384310 create mode 100644 modules/git/tests/repos/repo1_bare/objects/18/4d49c75a0b202b1d2ea2fcb5861c329321fcd6 create mode 100644 modules/git/tests/repos/repo1_bare/objects/21/6bf54c2f2e2916b830ebe09e8c58a6ed52d86b create mode 100644 modules/git/tests/repos/repo1_bare/objects/28/39944139e0de9737a044f78b0e4b40d989a9e3 create mode 100644 modules/git/tests/repos/repo1_bare/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e create mode 100644 modules/git/tests/repos/repo1_bare/objects/30/4c56b3bef33d0afeb8515ee803c839daf30ab8 create mode 100644 modules/git/tests/repos/repo1_bare/objects/34/d1da713bf7de1c535e1d7d3ca985afd84bc7e5 create mode 100644 modules/git/tests/repos/repo1_bare/objects/37/991dec2c8e592043f47155ce4808d4580f9123 create mode 100644 modules/git/tests/repos/repo1_bare/objects/38/441bf2c4d4c27efff94728c9eb33266f44a702 create mode 100644 modules/git/tests/repos/repo1_bare/objects/3a/d28a9149a2864384548f3d17ed7f38014c9e8a create mode 100644 modules/git/tests/repos/repo1_bare/objects/50/13716a9da8e66ea21059a84f1b4311424d2b7f create mode 100644 modules/git/tests/repos/repo1_bare/objects/59/dfb0bb505a601006e31fed53d2e24e44fca9ca create mode 100644 modules/git/tests/repos/repo1_bare/objects/5c/80b0245c1c6f8343fa418ec374b13b5d4ee658 create mode 100644 modules/git/tests/repos/repo1_bare/objects/62/d735f9efa9cf5b7df6bac9917b80e4779f4315 create mode 100644 modules/git/tests/repos/repo1_bare/objects/64/3a35374408002fcf2f0e8d42d262a1e0e2f80e create mode 100644 modules/git/tests/repos/repo1_bare/objects/6c/493ff740f9380390d5c9ddef4af18697ac9375 create mode 100644 modules/git/tests/repos/repo1_bare/objects/6f/bd69e9823458e6c4a2fc5c0f6bc022b2f2acd1 create mode 100644 modules/git/tests/repos/repo1_bare/objects/7e/3b688f3369ca28ebafbda9f8ef39713dd12fc8 create mode 100644 modules/git/tests/repos/repo1_bare/objects/80/06ff9adbf0cb94da7dad9e537e53817f9fa5c0 create mode 100644 modules/git/tests/repos/repo1_bare/objects/82/26f571dcc2d2f33a7179d929b10b9c39faa631 create mode 100644 modules/git/tests/repos/repo1_bare/objects/83/b9c4da46ed59098a009f8640c77eac97b71dfe create mode 100644 modules/git/tests/repos/repo1_bare/objects/8d/92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2 create mode 100644 modules/git/tests/repos/repo1_bare/objects/95/bb4d39648ee7e325106df01a621c530863a653 create mode 100644 modules/git/tests/repos/repo1_bare/objects/98/1ff127cc331753bba28e1377c35934f1ca9b56 create mode 100644 modules/git/tests/repos/repo1_bare/objects/9c/9aef8dd84e02bc7ec12641deb4c930a7c30185 create mode 100644 modules/git/tests/repos/repo1_bare/objects/b1/4df6442ea5a1b382985a6549b85d435376c351 create mode 100644 modules/git/tests/repos/repo1_bare/objects/b1/fc9917b618c924cf4aa421dae74e8bf9b556d3 create mode 100644 modules/git/tests/repos/repo1_bare/objects/b7/5f44edbd9252c32bf9faa0c1257ffb3b126c24 create mode 100644 modules/git/tests/repos/repo1_bare/objects/c8/c90111bdc18b3afd2b2906007059e95ac8fdc3 create mode 100644 modules/git/tests/repos/repo1_bare/objects/d0/845fe2f85710b50d673dafe98236bf9f2023da create mode 100644 modules/git/tests/repos/repo1_bare/objects/e2/129701f1a4d54dc44f03c93bca0a2aec7c5449 create mode 100644 modules/git/tests/repos/repo1_bare/objects/f1/a6cb52b2d16773290cefe49ad0684b50a4f930 create mode 100644 modules/git/tests/repos/repo1_bare/refs/heads/branch1 create mode 100644 modules/git/tests/repos/repo1_bare/refs/heads/branch2 create mode 100644 modules/git/tests/repos/repo1_bare/refs/heads/master create mode 100644 modules/git/tests/repos/repo1_bare/refs/tags/test rename {vendor/code.gitea.io => modules}/git/tree.go (96%) rename {vendor/code.gitea.io => modules}/git/tree_blob.go (90%) rename {vendor/code.gitea.io => modules}/git/tree_entry.go (99%) create mode 100644 modules/git/tree_entry_test.go rename {vendor/code.gitea.io => modules}/git/utils.go (100%) delete mode 100644 vendor/code.gitea.io/git/LICENSE delete mode 100644 vendor/code.gitea.io/git/doc.go create mode 100644 vendor/github.com/stretchr/testify/require/doc.go create mode 100644 vendor/github.com/stretchr/testify/require/forward_requirements.go create mode 100644 vendor/github.com/stretchr/testify/require/require.go create mode 100644 vendor/github.com/stretchr/testify/require/require_forward.go create mode 100644 vendor/github.com/stretchr/testify/require/requirements.go diff --git a/Gopkg.lock b/Gopkg.lock index cf5223dff..bc29e41c5 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,15 +3,7 @@ [[projects]] branch = "master" - digest = "1:e1fa64238b0a2dbf1edf98c4af8d1b8cb65179e286d7f28006b50fa9f508ee9d" - name = "code.gitea.io/git" - packages = ["."] - pruneopts = "NUT" - revision = "74d7c14dd4a3ed9c5def0dc3c1aeede399ddc5c5" - -[[projects]] - branch = "master" - digest = "1:6fb0a860db126f973204b4b05ed08d338d485a74c19c15f0e5cf0f49352a8ef1" + digest = "1:dbf849e6552740945ac1c6c6acba590fbc594e4efa80cf05568dec8579ae0dab" name = "code.gitea.io/sdk" packages = ["gitea"] pruneopts = "NUT" @@ -887,9 +879,12 @@ revision = "0abe01ef9be25c4aedc174758ec2d917314d6d70" [[projects]] - digest = "1:a852b1ad03ca063d2c57866d9f94dcb1cb2e111415c5902ce0586fc2d207221b" + digest = "1:0d3d375df794ab11a192668f4eacdb116ccd99aa574fe357185a2d463e07f2fb" name = "github.com/stretchr/testify" - packages = ["assert"] + packages = [ + "assert", + "require", + ] pruneopts = "NUT" revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" version = "v1.2.1" @@ -1231,7 +1226,6 @@ analyzer-name = "dep" analyzer-version = 1 input-imports = [ - "code.gitea.io/git", "code.gitea.io/sdk/gitea", "github.com/PuerkitoBio/goquery", "github.com/Unknwon/cae/zip", @@ -1313,6 +1307,7 @@ "github.com/satori/go.uuid", "github.com/sergi/go-diff/diffmatchpatch", "github.com/stretchr/testify/assert", + "github.com/stretchr/testify/require", "github.com/tstranex/u2f", "github.com/urfave/cli", "github.com/yohcop/openid-go", diff --git a/cmd/admin.go b/cmd/admin.go index 0934a7364..5c7d7613a 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -11,10 +11,10 @@ import ( "os" "text/tabwriter" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth/oauth2" "code.gitea.io/gitea/modules/generate" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" diff --git a/cmd/hook.go b/cmd/hook.go index d3a1a56b0..18d26f17c 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -12,8 +12,8 @@ import ( "strconv" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/setting" diff --git a/cmd/serv.go b/cmd/serv.go index ca0354d06..cab72f911 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -14,8 +14,8 @@ import ( "strings" "time" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/pprof" "code.gitea.io/gitea/modules/private" diff --git a/integrations/api_releases_test.go b/integrations/api_releases_test.go index 5c1b6c5d4..5cc4522f0 100644 --- a/integrations/api_releases_test.go +++ b/integrations/api_releases_test.go @@ -9,8 +9,8 @@ import ( "net/http" "testing" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" api "code.gitea.io/sdk/gitea" "github.com/stretchr/testify/assert" diff --git a/integrations/git_helper_for_declarative_test.go b/integrations/git_helper_for_declarative_test.go index 60c7c29f6..010f47a7a 100644 --- a/integrations/git_helper_for_declarative_test.go +++ b/integrations/git_helper_for_declarative_test.go @@ -16,7 +16,7 @@ import ( "testing" "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/ssh" "github.com/Unknwon/com" diff --git a/integrations/git_test.go b/integrations/git_test.go index a3ea61597..28ead9d38 100644 --- a/integrations/git_test.go +++ b/integrations/git_test.go @@ -16,8 +16,8 @@ import ( "testing" "time" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "github.com/stretchr/testify/assert" ) diff --git a/integrations/ssh_key_test.go b/integrations/ssh_key_test.go index 9ad43ae22..f6df5ff8f 100644 --- a/integrations/ssh_key_test.go +++ b/integrations/ssh_key_test.go @@ -14,7 +14,7 @@ import ( "testing" "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" api "code.gitea.io/sdk/gitea" "github.com/stretchr/testify/assert" ) diff --git a/models/action.go b/models/action.go index 2cd3616d6..d4cc4086d 100644 --- a/models/action.go +++ b/models/action.go @@ -14,8 +14,8 @@ import ( "time" "unicode" - "code.gitea.io/git" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" diff --git a/models/action_test.go b/models/action_test.go index 96d6ddb6d..e30b70680 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "github.com/stretchr/testify/assert" diff --git a/models/git_diff.go b/models/git_diff.go index 2e76e56be..ac2a5f90d 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -19,8 +19,8 @@ import ( "strconv" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/highlight" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" diff --git a/models/gpg_key.go b/models/gpg_key.go index c9b57caaa..03b0fd0f6 100644 --- a/models/gpg_key.go +++ b/models/gpg_key.go @@ -15,7 +15,7 @@ import ( "strings" "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" diff --git a/models/graph.go b/models/graph.go index 90b9ff11f..5f68abaf7 100644 --- a/models/graph.go +++ b/models/graph.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" ) diff --git a/models/graph_test.go b/models/graph_test.go index 0f6e33879..5c78e3877 100644 --- a/models/graph_test.go +++ b/models/graph_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" ) func BenchmarkGetCommitGraph(b *testing.B) { diff --git a/models/issue_comment.go b/models/issue_comment.go index c3654460f..d4a3d26a7 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -11,7 +11,7 @@ import ( "fmt" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "github.com/Unknwon/com" diff --git a/models/migrations/v28.go b/models/migrations/v28.go index e9db42004..a30cbf2af 100644 --- a/models/migrations/v28.go +++ b/models/migrations/v28.go @@ -10,7 +10,7 @@ import ( "path/filepath" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" diff --git a/models/migrations/v39.go b/models/migrations/v39.go index 9fb7390c7..1312cb331 100644 --- a/models/migrations/v39.go +++ b/models/migrations/v39.go @@ -7,8 +7,8 @@ package migrations import ( "fmt" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "github.com/go-xorm/xorm" diff --git a/models/migrations/v82.go b/models/migrations/v82.go index be9e71fd8..eb73f1834 100644 --- a/models/migrations/v82.go +++ b/models/migrations/v82.go @@ -7,8 +7,8 @@ package migrations import ( "fmt" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "github.com/go-xorm/xorm" ) diff --git a/models/pull.go b/models/pull.go index 35fbc4178..ef3ec8e14 100644 --- a/models/pull.go +++ b/models/pull.go @@ -16,9 +16,9 @@ import ( "strings" "time" - "code.gitea.io/git" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" diff --git a/models/release.go b/models/release.go index 0c78707d6..f147016b1 100644 --- a/models/release.go +++ b/models/release.go @@ -9,13 +9,13 @@ import ( "sort" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" - api "code.gitea.io/sdk/gitea" + "github.com/go-xorm/builder" ) diff --git a/models/release_test.go b/models/release_test.go index de34109e8..39c661305 100644 --- a/models/release_test.go +++ b/models/release_test.go @@ -7,7 +7,7 @@ package models import ( "testing" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "github.com/stretchr/testify/assert" ) diff --git a/models/repo.go b/models/repo.go index 9a85c77f0..19526fb17 100644 --- a/models/repo.go +++ b/models/repo.go @@ -21,7 +21,7 @@ import ( "strings" "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/options" diff --git a/models/repo_branch.go b/models/repo_branch.go index c4013dfb8..9ea4ce45f 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "github.com/Unknwon/com" diff --git a/models/repo_indexer.go b/models/repo_indexer.go index b4f7bf1bd..bfeeca26e 100644 --- a/models/repo_indexer.go +++ b/models/repo_indexer.go @@ -9,8 +9,8 @@ import ( "strconv" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/indexer" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" diff --git a/models/repo_mirror.go b/models/repo_mirror.go index 9f8c9bee6..c3fc9a43d 100644 --- a/models/repo_mirror.go +++ b/models/repo_mirror.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "code.gitea.io/git" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" diff --git a/models/repo_tag.go b/models/repo_tag.go index 752eaf028..fa3f19bb2 100644 --- a/models/repo_tag.go +++ b/models/repo_tag.go @@ -5,7 +5,7 @@ package models import ( - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" ) // GetTagsByPath returns repo tags by it's path diff --git a/models/status.go b/models/status.go index 91d011f7c..93d82b76f 100644 --- a/models/status.go +++ b/models/status.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" diff --git a/models/update.go b/models/update.go index 9cd4d0d97..cde6b217c 100644 --- a/models/update.go +++ b/models/update.go @@ -11,8 +11,8 @@ import ( "strings" "time" - "code.gitea.io/git" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" ) diff --git a/models/update_test.go b/models/update_test.go index 45451ee43..f2219a4e6 100644 --- a/models/update_test.go +++ b/models/update_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "github.com/stretchr/testify/assert" ) diff --git a/models/user.go b/models/user.go index 8fc15848c..b831a2ebf 100644 --- a/models/user.go +++ b/models/user.go @@ -25,10 +25,10 @@ import ( "time" "unicode/utf8" - "code.gitea.io/git" "code.gitea.io/gitea/modules/avatar" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/generate" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" diff --git a/models/webhook_dingtalk.go b/models/webhook_dingtalk.go index 1021ab35f..708673270 100644 --- a/models/webhook_dingtalk.go +++ b/models/webhook_dingtalk.go @@ -9,8 +9,9 @@ import ( "fmt" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" api "code.gitea.io/sdk/gitea" + dingtalk "github.com/lunny/dingtalk_webhook" ) diff --git a/models/webhook_discord.go b/models/webhook_discord.go index 893e78096..8f1cb1694 100644 --- a/models/webhook_discord.go +++ b/models/webhook_discord.go @@ -11,7 +11,7 @@ import ( "strconv" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/sdk/gitea" ) diff --git a/models/webhook_slack.go b/models/webhook_slack.go index 90d5ccce0..2bb84c2c4 100644 --- a/models/webhook_slack.go +++ b/models/webhook_slack.go @@ -10,7 +10,7 @@ import ( "fmt" "strings" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/sdk/gitea" ) diff --git a/models/wiki.go b/models/wiki.go index 65cf26a44..0f5cdc20b 100644 --- a/models/wiki.go +++ b/models/wiki.go @@ -13,12 +13,11 @@ import ( "path/filepath" "strings" - "github.com/Unknwon/com" - - "code.gitea.io/git" - + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/sync" + + "github.com/Unknwon/com" ) var ( diff --git a/modules/base/tool.go b/modules/base/tool.go index b069e5fae..359cf87d7 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -23,10 +23,11 @@ import ( "unicode" "unicode/utf8" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "github.com/Unknwon/com" "github.com/Unknwon/i18n" "github.com/gogits/chardet" diff --git a/modules/context/api.go b/modules/context/api.go index 7ec4d9036..04a472b38 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -13,11 +13,12 @@ import ( "github.com/go-macaron/csrf" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "github.com/Unknwon/paginater" macaron "gopkg.in/macaron.v1" ) diff --git a/modules/context/repo.go b/modules/context/repo.go index e0ee802f7..20a3d1942 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -12,9 +12,9 @@ import ( "path" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" diff --git a/modules/git/README.md b/modules/git/README.md new file mode 100644 index 000000000..4418c1b89 --- /dev/null +++ b/modules/git/README.md @@ -0,0 +1,3 @@ +# Git Module + +This module is merged from https://github.com/go-gitea/git which is a Go module to access Git through shell commands. Now it's a part of gitea's main repository for easier pull request. diff --git a/vendor/code.gitea.io/git/blob.go b/modules/git/blob.go similarity index 100% rename from vendor/code.gitea.io/git/blob.go rename to modules/git/blob.go diff --git a/modules/git/blob_test.go b/modules/git/blob_test.go new file mode 100644 index 000000000..39516c422 --- /dev/null +++ b/modules/git/blob_test.go @@ -0,0 +1,80 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "io/ioutil" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var repoSelf = &Repository{ + Path: "./", +} + +var testBlob = &Blob{ + repo: repoSelf, + TreeEntry: &TreeEntry{ + ID: MustIDFromString("a8d4b49dd073a4a38a7e58385eeff7cc52568697"), + ptree: &Tree{ + repo: repoSelf, + }, + }, +} + +func TestBlob_Data(t *testing.T) { + output := `Copyright (c) 2016 The Gitea Authors +Copyright (c) 2015 The Gogs Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +` + + r, err := testBlob.Data() + assert.NoError(t, err) + require.NotNil(t, r) + + data, err := ioutil.ReadAll(r) + assert.NoError(t, err) + assert.Equal(t, output, string(data)) +} + +func Benchmark_Blob_Data(b *testing.B) { + for i := 0; i < b.N; i++ { + r, err := testBlob.Data() + if err != nil { + b.Fatal(err) + } + ioutil.ReadAll(r) + } +} + +func Benchmark_Blob_DataPipeline(b *testing.B) { + stdout := new(bytes.Buffer) + for i := 0; i < b.N; i++ { + stdout.Reset() + if err := testBlob.DataPipeline(stdout, nil); err != nil { + b.Fatal(err) + } + } +} diff --git a/vendor/code.gitea.io/git/cache.go b/modules/git/cache.go similarity index 100% rename from vendor/code.gitea.io/git/cache.go rename to modules/git/cache.go diff --git a/vendor/code.gitea.io/git/command.go b/modules/git/command.go similarity index 96% rename from vendor/code.gitea.io/git/command.go rename to modules/git/command.go index fc48d2871..d35463511 100644 --- a/vendor/code.gitea.io/git/command.go +++ b/modules/git/command.go @@ -120,7 +120,7 @@ func (c *Command) RunInDir(dir string) (string, error) { return string(stdout), nil } -// RunTimeout executes the command in defualt working directory with given timeout, +// RunTimeout executes the command in default working directory with given timeout, // and returns stdout in string and error (combined with stderr). func (c *Command) RunTimeout(timeout time.Duration) (string, error) { stdout, err := c.RunInDirTimeout(timeout, "") @@ -130,7 +130,7 @@ func (c *Command) RunTimeout(timeout time.Duration) (string, error) { return string(stdout), nil } -// Run executes the command in defualt working directory +// Run executes the command in default working directory // and returns stdout in string and error (combined with stderr). func (c *Command) Run() (string, error) { return c.RunTimeout(-1) diff --git a/modules/git/command_test.go b/modules/git/command_test.go new file mode 100644 index 000000000..2f35b3c32 --- /dev/null +++ b/modules/git/command_test.go @@ -0,0 +1,41 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// +build race + +package git + +import ( + "context" + "testing" + "time" +) + +func TestRunInDirTimeoutPipelineNoTimeout(t *testing.T) { + + maxLoops := 1000 + + // 'git --version' does not block so it must be finished before the timeout triggered. + cmd := NewCommand("--version") + for i := 0; i < maxLoops; i++ { + if err := cmd.RunInDirTimeoutPipeline(-1, "", nil, nil); err != nil { + t.Fatal(err) + } + } +} + +func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) { + + maxLoops := 1000 + + // 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered. + cmd := NewCommand("hash-object --stdin") + for i := 0; i < maxLoops; i++ { + if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil { + if err != context.DeadlineExceeded { + t.Fatalf("Testing %d/%d: %v", i, maxLoops, err) + } + } + } +} diff --git a/vendor/code.gitea.io/git/commit.go b/modules/git/commit.go similarity index 100% rename from vendor/code.gitea.io/git/commit.go rename to modules/git/commit.go diff --git a/vendor/code.gitea.io/git/commit_archive.go b/modules/git/commit_archive.go similarity index 100% rename from vendor/code.gitea.io/git/commit_archive.go rename to modules/git/commit_archive.go diff --git a/vendor/code.gitea.io/git/commit_info.go b/modules/git/commit_info.go similarity index 100% rename from vendor/code.gitea.io/git/commit_info.go rename to modules/git/commit_info.go diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go new file mode 100644 index 000000000..120a9a737 --- /dev/null +++ b/modules/git/commit_info_test.go @@ -0,0 +1,117 @@ +package git + +import ( + "os" + "path/filepath" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +const testReposDir = "tests/repos/" +const benchmarkReposDir = "benchmark/repos/" + +func cloneRepo(url, dir, name string) (string, error) { + repoDir := filepath.Join(dir, name) + if _, err := os.Stat(repoDir); err == nil { + return repoDir, nil + } + return repoDir, Clone(url, repoDir, CloneRepoOptions{ + Mirror: false, + Bare: false, + Quiet: true, + Timeout: 5 * time.Minute, + }) +} + +func testGetCommitsInfo(t *testing.T, repo1 *Repository) { + // these test case are specific to the repo1 test repo + testCases := []struct { + CommitID string + Path string + ExpectedIDs map[string]string + }{ + {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", "", map[string]string{ + "file1.txt": "95bb4d39648ee7e325106df01a621c530863a653", + "file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", + }}, + {"2839944139e0de9737a044f78b0e4b40d989a9e3", "", map[string]string{ + "file1.txt": "2839944139e0de9737a044f78b0e4b40d989a9e3", + "branch1.txt": "9c9aef8dd84e02bc7ec12641deb4c930a7c30185", + }}, + {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", "branch2", map[string]string{ + "branch2.txt": "5c80b0245c1c6f8343fa418ec374b13b5d4ee658", + }}, + } + for _, testCase := range testCases { + commit, err := repo1.GetCommit(testCase.CommitID) + assert.NoError(t, err) + tree, err := commit.Tree.SubTree(testCase.Path) + assert.NoError(t, err) + entries, err := tree.ListEntries() + assert.NoError(t, err) + commitsInfo, err := entries.GetCommitsInfo(commit, testCase.Path, nil) + assert.NoError(t, err) + assert.Len(t, commitsInfo, len(testCase.ExpectedIDs)) + for _, commitInfo := range commitsInfo { + entry := commitInfo[0].(*TreeEntry) + commit := commitInfo[1].(*Commit) + expectedID, ok := testCase.ExpectedIDs[entry.Name()] + if !assert.True(t, ok) { + continue + } + assert.Equal(t, expectedID, commit.ID.String()) + } + } +} + +func TestEntries_GetCommitsInfo(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + testGetCommitsInfo(t, bareRepo1) + + clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo") + assert.NoError(t, err) + defer os.RemoveAll(clonedPath) + clonedRepo1, err := OpenRepository(clonedPath) + assert.NoError(t, err) + testGetCommitsInfo(t, clonedRepo1) +} + +func BenchmarkEntries_GetCommitsInfo(b *testing.B) { + benchmarks := []struct { + url string + name string + }{ + {url: "https://github.com/go-gitea/gitea.git", name: "gitea"}, + {url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles"}, + {url: "https://github.com/moby/moby.git", name: "moby"}, + {url: "https://github.com/golang/go.git", name: "go"}, + {url: "https://github.com/torvalds/linux.git", name: "linux"}, + } + for _, benchmark := range benchmarks { + var commit *Commit + var entries Entries + if repoPath, err := cloneRepo(benchmark.url, benchmarkReposDir, benchmark.name); err != nil { + b.Fatal(err) + } else if repo, err := OpenRepository(repoPath); err != nil { + b.Fatal(err) + } else if commit, err = repo.GetBranchCommit("master"); err != nil { + b.Fatal(err) + } else if entries, err = commit.Tree.ListEntries(); err != nil { + b.Fatal(err) + } + entries.Sort() + b.ResetTimer() + b.Run(benchmark.name, func(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := entries.GetCommitsInfo(commit, "", nil) + if err != nil { + b.Fatal(err) + } + } + }) + } +} diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go new file mode 100644 index 000000000..bbe12b5ae --- /dev/null +++ b/modules/git/commit_test.go @@ -0,0 +1,38 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCommitsCount(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + commitsCount, err := CommitsCount(bareRepo1Path, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0") + assert.NoError(t, err) + assert.Equal(t, int64(3), commitsCount) +} + +func TestGetFullCommitID(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + id, err := GetFullCommitID(bareRepo1Path, "8006ff9a") + assert.NoError(t, err) + assert.Equal(t, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", id) +} + +func TestGetFullCommitIDError(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + id, err := GetFullCommitID(bareRepo1Path, "unknown") + assert.Empty(t, id) + if assert.Error(t, err) { + assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]") + } +} diff --git a/vendor/code.gitea.io/git/error.go b/modules/git/error.go similarity index 100% rename from vendor/code.gitea.io/git/error.go rename to modules/git/error.go diff --git a/vendor/code.gitea.io/git/git.go b/modules/git/git.go similarity index 100% rename from vendor/code.gitea.io/git/git.go rename to modules/git/git.go diff --git a/vendor/code.gitea.io/git/hook.go b/modules/git/hook.go similarity index 92% rename from vendor/code.gitea.io/git/hook.go rename to modules/git/hook.go index afed623e6..18c00b583 100644 --- a/vendor/code.gitea.io/git/hook.go +++ b/modules/git/hook.go @@ -82,11 +82,20 @@ func (h *Hook) Name() string { func (h *Hook) Update() error { if len(strings.TrimSpace(h.Content)) == 0 { if isExist(h.path) { - return os.Remove(h.path) + err := os.Remove(h.path) + if err != nil { + return err + } } + h.IsActive = false return nil } - return ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm) + err := ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm) + if err != nil { + return err + } + h.IsActive = true + return nil } // ListHooks returns a list of Git hooks of given repository. diff --git a/vendor/code.gitea.io/git/parse.go b/modules/git/parse.go similarity index 100% rename from vendor/code.gitea.io/git/parse.go rename to modules/git/parse.go diff --git a/modules/git/parse_test.go b/modules/git/parse_test.go new file mode 100644 index 000000000..66936cbdf --- /dev/null +++ b/modules/git/parse_test.go @@ -0,0 +1,58 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestParseTreeEntries(t *testing.T) { + testCases := []struct { + Input string + Expected []*TreeEntry + }{ + { + Input: "", + Expected: []*TreeEntry{}, + }, + { + Input: "100644 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c\texample/file2.txt\n", + Expected: []*TreeEntry{ + { + mode: EntryModeBlob, + Type: ObjectBlob, + ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"), + name: "example/file2.txt", + }, + }, + }, + { + Input: "120000 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c\t\"example/\\n.txt\"\n" + + "040000 tree 1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8\texample\n", + Expected: []*TreeEntry{ + { + ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"), + Type: ObjectBlob, + mode: EntryModeSymlink, + name: "example/\n.txt", + }, + { + ID: MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8"), + Type: ObjectTree, + mode: EntryModeTree, + name: "example", + }, + }, + }, + } + + for _, testCase := range testCases { + entries, err := ParseTreeEntries([]byte(testCase.Input)) + assert.NoError(t, err) + assert.EqualValues(t, testCase.Expected, entries) + } +} diff --git a/vendor/code.gitea.io/git/ref.go b/modules/git/ref.go similarity index 100% rename from vendor/code.gitea.io/git/ref.go rename to modules/git/ref.go diff --git a/vendor/code.gitea.io/git/repo.go b/modules/git/repo.go similarity index 100% rename from vendor/code.gitea.io/git/repo.go rename to modules/git/repo.go diff --git a/vendor/code.gitea.io/git/repo_blame.go b/modules/git/repo_blame.go similarity index 100% rename from vendor/code.gitea.io/git/repo_blame.go rename to modules/git/repo_blame.go diff --git a/vendor/code.gitea.io/git/repo_blob.go b/modules/git/repo_blob.go similarity index 100% rename from vendor/code.gitea.io/git/repo_blob.go rename to modules/git/repo_blob.go diff --git a/modules/git/repo_blob_test.go b/modules/git/repo_blob_test.go new file mode 100644 index 000000000..074365f16 --- /dev/null +++ b/modules/git/repo_blob_test.go @@ -0,0 +1,66 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "io/ioutil" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRepository_GetBlob_Found(t *testing.T) { + repoPath := filepath.Join(testReposDir, "repo1_bare") + r, err := OpenRepository(repoPath) + assert.NoError(t, err) + + testCases := []struct { + OID string + Data []byte + }{ + {"e2129701f1a4d54dc44f03c93bca0a2aec7c5449", []byte("file1\n")}, + {"6c493ff740f9380390d5c9ddef4af18697ac9375", []byte("file2\n")}, + } + + for _, testCase := range testCases { + blob, err := r.GetBlob(testCase.OID) + assert.NoError(t, err) + + dataReader, err := blob.Data() + assert.NoError(t, err) + + data, err := ioutil.ReadAll(dataReader) + assert.NoError(t, err) + assert.Equal(t, testCase.Data, data) + } +} + +func TestRepository_GetBlob_NotExist(t *testing.T) { + repoPath := filepath.Join(testReposDir, "repo1_bare") + r, err := OpenRepository(repoPath) + assert.NoError(t, err) + + testCase := "0000000000000000000000000000000000000000" + testError := ErrNotExist{testCase, ""} + + blob, err := r.GetBlob(testCase) + assert.Nil(t, blob) + assert.EqualError(t, err, testError.Error()) +} + +func TestRepository_GetBlob_NoId(t *testing.T) { + repoPath := filepath.Join(testReposDir, "repo1_bare") + r, err := OpenRepository(repoPath) + assert.NoError(t, err) + + testCase := "" + testError := fmt.Errorf("Length must be 40: %s", testCase) + + blob, err := r.GetBlob(testCase) + assert.Nil(t, blob) + assert.EqualError(t, err, testError.Error()) +} diff --git a/vendor/code.gitea.io/git/repo_branch.go b/modules/git/repo_branch.go similarity index 100% rename from vendor/code.gitea.io/git/repo_branch.go rename to modules/git/repo_branch.go diff --git a/modules/git/repo_branch_test.go b/modules/git/repo_branch_test.go new file mode 100644 index 000000000..08736d702 --- /dev/null +++ b/modules/git/repo_branch_test.go @@ -0,0 +1,39 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRepository_GetBranches(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + + branches, err := bareRepo1.GetBranches() + + assert.NoError(t, err) + assert.Len(t, branches, 3) + assert.ElementsMatch(t, []string{"branch1", "branch2", "master"}, branches) +} + +func BenchmarkRepository_GetBranches(b *testing.B) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + if err != nil { + b.Fatal(err) + } + + for i := 0; i < b.N; i++ { + _, err := bareRepo1.GetBranches() + if err != nil { + b.Fatal(err) + } + } +} diff --git a/vendor/code.gitea.io/git/repo_commit.go b/modules/git/repo_commit.go similarity index 98% rename from vendor/code.gitea.io/git/repo_commit.go rename to modules/git/repo_commit.go index 2d9f5bdbf..146619373 100644 --- a/vendor/code.gitea.io/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -146,7 +146,7 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) { return nil, err } - // name-rev commitID ouput will be "COMMIT_ID master" or "COMMIT_ID master~12" + // name-rev commitID output will be "COMMIT_ID master" or "COMMIT_ID master~12" commit.Branch = strings.Split(strings.Split(string(data), " ")[1], "~")[0] repo.commitCache.Set(id.String(), commit) @@ -262,7 +262,7 @@ func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) { return commitsCount(repo.Path, revision, file) } -// CommitsByFileAndRange return the commits accroding revison file and the page +// CommitsByFileAndRange return the commits according revison file and the page func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) { stdout, err := NewCommand("log", revision, "--follow", "--skip="+strconv.Itoa((page-1)*50), "--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat, "--", file).RunInDirBytes(repo.Path) diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go new file mode 100644 index 000000000..6761a45b7 --- /dev/null +++ b/modules/git/repo_commit_test.go @@ -0,0 +1,59 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRepository_GetCommitBranches(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + + // these test case are specific to the repo1_bare test repo + testCases := []struct { + CommitID string + ExpectedBranches []string + }{ + {"2839944139e0de9737a044f78b0e4b40d989a9e3", []string{"branch1"}}, + {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", []string{"branch2"}}, + {"37991dec2c8e592043f47155ce4808d4580f9123", []string{"master"}}, + {"95bb4d39648ee7e325106df01a621c530863a653", []string{"branch1", "branch2"}}, + {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", []string{"branch2", "master"}}, + {"master", []string{"master"}}, + } + for _, testCase := range testCases { + commit, err := bareRepo1.GetCommit(testCase.CommitID) + assert.NoError(t, err) + branches, err := bareRepo1.getBranches(commit, 2) + assert.NoError(t, err) + assert.Equal(t, testCase.ExpectedBranches, branches) + } +} + +func TestGetTagCommitWithSignature(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a") + + assert.NoError(t, err) + assert.NotNil(t, commit) + assert.NotNil(t, commit.Signature) + // test that signature is not in message + assert.Equal(t, "tag", commit.CommitMessage) +} + +func TestGetCommitWithBadCommitID(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + commit, err := bareRepo1.GetCommit("bad_branch") + assert.Nil(t, commit) + assert.Error(t, err) + assert.EqualError(t, err, "object does not exist [id: bad_branch, rel_path: ]") +} diff --git a/vendor/code.gitea.io/git/repo_hook.go b/modules/git/repo_hook.go similarity index 87% rename from vendor/code.gitea.io/git/repo_hook.go rename to modules/git/repo_hook.go index 49f4d09fb..a652e938f 100644 --- a/vendor/code.gitea.io/git/repo_hook.go +++ b/modules/git/repo_hook.go @@ -4,7 +4,7 @@ package git -// GetHook get one hook accroding the name on a repository +// GetHook get one hook according the name on a repository func (repo *Repository) GetHook(name string) (*Hook, error) { return GetHook(repo.Path, name) } diff --git a/vendor/code.gitea.io/git/repo_object.go b/modules/git/repo_object.go similarity index 100% rename from vendor/code.gitea.io/git/repo_object.go rename to modules/git/repo_object.go diff --git a/vendor/code.gitea.io/git/repo_pull.go b/modules/git/repo_pull.go similarity index 100% rename from vendor/code.gitea.io/git/repo_pull.go rename to modules/git/repo_pull.go diff --git a/modules/git/repo_pull_test.go b/modules/git/repo_pull_test.go new file mode 100644 index 000000000..e19478877 --- /dev/null +++ b/modules/git/repo_pull_test.go @@ -0,0 +1,30 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetFormatPatch(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch") + assert.NoError(t, err) + defer os.RemoveAll(clonedPath) + repo, err := OpenRepository(clonedPath) + assert.NoError(t, err) + rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95") + assert.NoError(t, err) + patchb, err := ioutil.ReadAll(rd) + assert.NoError(t, err) + patch := string(patchb) + assert.Regexp(t, "^From 8d92fc95", patch) + assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt") +} diff --git a/vendor/code.gitea.io/git/repo_ref.go b/modules/git/repo_ref.go similarity index 100% rename from vendor/code.gitea.io/git/repo_ref.go rename to modules/git/repo_ref.go diff --git a/modules/git/repo_ref_test.go b/modules/git/repo_ref_test.go new file mode 100644 index 000000000..2a3ea26a7 --- /dev/null +++ b/modules/git/repo_ref_test.go @@ -0,0 +1,49 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRepository_GetRefs(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + + refs, err := bareRepo1.GetRefs() + + assert.NoError(t, err) + assert.Len(t, refs, 4) + + expectedRefs := []string{ + BranchPrefix + "branch1", + BranchPrefix + "branch2", + BranchPrefix + "master", + TagPrefix + "test", + } + + for _, ref := range refs { + assert.Contains(t, expectedRefs, ref.Name) + } +} + +func TestRepository_GetRefsFiltered(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + + refs, err := bareRepo1.GetRefsFiltered(TagPrefix) + + assert.NoError(t, err) + if assert.Len(t, refs, 1) { + assert.Equal(t, TagPrefix+"test", refs[0].Name) + assert.Equal(t, "tag", refs[0].Type) + assert.Equal(t, "3ad28a9149a2864384548f3d17ed7f38014c9e8a", refs[0].Object.String()) + } +} diff --git a/vendor/code.gitea.io/git/repo_tag.go b/modules/git/repo_tag.go similarity index 100% rename from vendor/code.gitea.io/git/repo_tag.go rename to modules/git/repo_tag.go diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go new file mode 100644 index 000000000..ccb2d57ac --- /dev/null +++ b/modules/git/repo_tag_test.go @@ -0,0 +1,44 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRepository_GetTags(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + bareRepo1, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + + tags, err := bareRepo1.GetTagInfos() + assert.NoError(t, err) + assert.Len(t, tags, 1) + assert.EqualValues(t, "test", tags[0].Name) + assert.EqualValues(t, "37991dec2c8e592043f47155ce4808d4580f9123", tags[0].ID.String()) + assert.EqualValues(t, "commit", tags[0].Type) +} + +func TestRepository_GetTag(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestRepository_GetTag") + assert.NoError(t, err) + defer os.RemoveAll(clonedPath) + + bareRepo1, err := OpenRepository(clonedPath) + assert.NoError(t, err) + + tag, err := bareRepo1.GetTag("test") + assert.NoError(t, err) + assert.NotNil(t, tag) + assert.EqualValues(t, "test", tag.Name) + assert.EqualValues(t, "37991dec2c8e592043f47155ce4808d4580f9123", tag.ID.String()) + assert.EqualValues(t, "commit", tag.Type) +} diff --git a/modules/git/repo_test.go b/modules/git/repo_test.go new file mode 100644 index 000000000..c5ce6f444 --- /dev/null +++ b/modules/git/repo_test.go @@ -0,0 +1,26 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestGetLatestCommitTime(t *testing.T) { + lct, err := GetLatestCommitTime(".") + assert.NoError(t, err) + // Time is in the past + now := time.Now() + assert.True(t, lct.Unix() < now.Unix(), "%d not smaller than %d", lct, now) + // Time is after Mon Oct 23 03:52:09 2017 +0300 + // which is the time of commit + // d47b98c44c9a6472e44ab80efe65235e11c6da2a + refTime, err := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Mon Oct 23 03:52:09 2017 +0300") + assert.NoError(t, err) + assert.True(t, lct.Unix() > refTime.Unix(), "%d not greater than %d", lct, refTime) +} diff --git a/vendor/code.gitea.io/git/repo_tree.go b/modules/git/repo_tree.go similarity index 97% rename from vendor/code.gitea.io/git/repo_tree.go rename to modules/git/repo_tree.go index 146b919d7..3fa491d52 100644 --- a/vendor/code.gitea.io/git/repo_tree.go +++ b/modules/git/repo_tree.go @@ -21,7 +21,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) { if len(idStr) != 40 { res, err := NewCommand("rev-parse", idStr).RunInDir(repo.Path) if err != nil { - return nil, err; + return nil, err } if len(res) > 0 { idStr = res[:len(res)-1] diff --git a/vendor/code.gitea.io/git/sha1.go b/modules/git/sha1.go similarity index 100% rename from vendor/code.gitea.io/git/sha1.go rename to modules/git/sha1.go diff --git a/vendor/code.gitea.io/git/signature.go b/modules/git/signature.go similarity index 100% rename from vendor/code.gitea.io/git/signature.go rename to modules/git/signature.go diff --git a/vendor/code.gitea.io/git/submodule.go b/modules/git/submodule.go similarity index 100% rename from vendor/code.gitea.io/git/submodule.go rename to modules/git/submodule.go diff --git a/modules/git/submodule_test.go b/modules/git/submodule_test.go new file mode 100644 index 000000000..6a3bb7ec7 --- /dev/null +++ b/modules/git/submodule_test.go @@ -0,0 +1,29 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetRefURL(t *testing.T) { + var kases = []struct { + refURL string + prefixURL string + parentPath string + expect string + }{ + {"git://github.com/user1/repo1", "/", "/", "http://github.com/user1/repo1"}, + {"https://localhost/user1/repo1.git", "/", "/", "https://localhost/user1/repo1"}, + {"git@github.com/user1/repo1.git", "/", "/", "git@github.com/user1/repo1"}, + {"ssh://git@git.zefie.net:2222/zefie/lge_g6_kernel_scripts.git", "/", "/", "http://git.zefie.net/zefie/lge_g6_kernel_scripts"}, + } + + for _, kase := range kases { + assert.EqualValues(t, kase.expect, getRefURL(kase.refURL, kase.prefixURL, kase.parentPath)) + } +} diff --git a/vendor/code.gitea.io/git/tag.go b/modules/git/tag.go similarity index 100% rename from vendor/code.gitea.io/git/tag.go rename to modules/git/tag.go diff --git a/modules/git/tests/repos/repo1_bare/HEAD b/modules/git/tests/repos/repo1_bare/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/modules/git/tests/repos/repo1_bare/config b/modules/git/tests/repos/repo1_bare/config new file mode 100644 index 000000000..07d359d07 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/config @@ -0,0 +1,4 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true diff --git a/modules/git/tests/repos/repo1_bare/description b/modules/git/tests/repos/repo1_bare/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo1_bare/hooks/applypatch-msg.sample b/modules/git/tests/repos/repo1_bare/hooks/applypatch-msg.sample new file mode 100755 index 000000000..a5d7b84a6 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/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 +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/modules/git/tests/repos/repo1_bare/hooks/commit-msg.sample b/modules/git/tests/repos/repo1_bare/hooks/commit-msg.sample new file mode 100755 index 000000000..b58d1184a --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/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/modules/git/tests/repos/repo1_bare/hooks/post-update.sample b/modules/git/tests/repos/repo1_bare/hooks/post-update.sample new file mode 100755 index 000000000..ec17ec193 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/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/modules/git/tests/repos/repo1_bare/hooks/pre-applypatch.sample b/modules/git/tests/repos/repo1_bare/hooks/pre-applypatch.sample new file mode 100755 index 000000000..4142082bc --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/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 +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/modules/git/tests/repos/repo1_bare/hooks/pre-commit.sample b/modules/git/tests/repos/repo1_bare/hooks/pre-commit.sample new file mode 100755 index 000000000..68d62d544 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/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 --bool 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 + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + 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/modules/git/tests/repos/repo1_bare/hooks/pre-push.sample b/modules/git/tests/repos/repo1_bare/hooks/pre-push.sample new file mode 100755 index 000000000..6187dbf43 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/modules/git/tests/repos/repo1_bare/hooks/pre-rebase.sample b/modules/git/tests/repos/repo1_bare/hooks/pre-rebase.sample new file mode 100755 index 000000000..33730ca64 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/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 + +<<\DOC_END + +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". + +DOC_END diff --git a/modules/git/tests/repos/repo1_bare/hooks/pre-receive.sample b/modules/git/tests/repos/repo1_bare/hooks/pre-receive.sample new file mode 100755 index 000000000..a1fd29ec1 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/modules/git/tests/repos/repo1_bare/hooks/prepare-commit-msg.sample b/modules/git/tests/repos/repo1_bare/hooks/prepare-commit-msg.sample new file mode 100755 index 000000000..f093a02ec --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/prepare-commit-msg.sample @@ -0,0 +1,36 @@ +#!/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/modules/git/tests/repos/repo1_bare/hooks/update.sample b/modules/git/tests/repos/repo1_bare/hooks/update.sample new file mode 100755 index 000000000..80ba94135 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block 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 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&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/modules/git/tests/repos/repo1_bare/info/exclude b/modules/git/tests/repos/repo1_bare/info/exclude new file mode 100644 index 000000000..a5196d1be --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/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/modules/git/tests/repos/repo1_bare/objects/0b/9f291245f6c596fd30bee925fe94fe0cbadd60 b/modules/git/tests/repos/repo1_bare/objects/0b/9f291245f6c596fd30bee925fe94fe0cbadd60 new file mode 100644 index 0000000000000000000000000000000000000000..11de5add68c6a08f91c355ca7859336b24f4ec6e GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bxNXyJgHPkDqC}DUcG@bF|lB>Q){FzT$pW@Pb MQxoC|084ZbNf}@jg#Z8m literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/11/93ff46343f4f6a0522e2b28b871e905178c1f0 b/modules/git/tests/repos/repo1_bare/objects/11/93ff46343f4f6a0522e2b28b871e905178c1f0 new file mode 100644 index 0000000000000000000000000000000000000000..3541cd14f0bf5f3a172f868c7ec730dcc255ebd2 GIT binary patch literal 23 fcmbAT(SQY{RanuOb literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/15/3f451b9ee7fa1da317ab17a127e9fd9d384310 b/modules/git/tests/repos/repo1_bare/objects/15/3f451b9ee7fa1da317ab17a127e9fd9d384310 new file mode 100644 index 0000000000000000000000000000000000000000..8db3c790b50176e62dc6f5da6c14b52c41e1a9d5 GIT binary patch literal 31 ncmbu-1;e+mF^cM@q>u@@%* literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/21/6bf54c2f2e2916b830ebe09e8c58a6ed52d86b b/modules/git/tests/repos/repo1_bare/objects/21/6bf54c2f2e2916b830ebe09e8c58a6ed52d86b new file mode 100644 index 0000000000000000000000000000000000000000..8c0b1b32851fd002342d6b71a176e1e5c185aaa0 GIT binary patch literal 28 kcmbB8m9=e>0KT?P4ÂèRt@Á¤O¼šö´n‹Úû[›½Þ,À\`oÏŽœ3òõ£þ]ÍTz…Kß»ùe;ƒ \ No newline at end of file diff --git a/modules/git/tests/repos/repo1_bare/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e b/modules/git/tests/repos/repo1_bare/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e new file mode 100644 index 0000000000000000000000000000000000000000..3e46ba4a32b0d9c687dbc65f4a2241a91250a71d GIT binary patch literal 16 XcmbIg((OCEph}s literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/30/4c56b3bef33d0afeb8515ee803c839daf30ab8 b/modules/git/tests/repos/repo1_bare/objects/30/4c56b3bef33d0afeb8515ee803c839daf30ab8 new file mode 100644 index 0000000000000000000000000000000000000000..3a5c6c1962c161d13e0c02b3323b9822a13ddb70 GIT binary patch literal 85 zcmV-b0IL6Z0V^p=O;s>AV=y!@Ff%bxNGeLqOU^LVE2$`95S;wq&BWe6i&g2-rtWsR r34s*{KR}hGW#*(p6g?7}&iHZ3Ro^52%qOi+acRA&3GoB~vD_Zg${Qvf literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/34/d1da713bf7de1c535e1d7d3ca985afd84bc7e5 b/modules/git/tests/repos/repo1_bare/objects/34/d1da713bf7de1c535e1d7d3ca985afd84bc7e5 new file mode 100644 index 0000000000000000000000000000000000000000..29f2d4fd004afa03b43e3148207e258e7aa9fc41 GIT binary patch literal 23 fcmbAT3SQY^Qam@(V literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/37/991dec2c8e592043f47155ce4808d4580f9123 b/modules/git/tests/repos/repo1_bare/objects/37/991dec2c8e592043f47155ce4808d4580f9123 new file mode 100644 index 000000000..3658e9514 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/objects/37/991dec2c8e592043f47155ce4808d4580f9123 @@ -0,0 +1 @@ +xŽKN1 YçÞ#ç3 !Øp.ØÎL‹™J›·§á,kñêû}5 PlªB÷5sKÔH|>ŸdíKÌKl kì% û¬S7ƒÜ›ä¢e¡Ó¢™c¥Î‰±çÆH‡§Señ®~ÙuLxŸëocì Óeµ—ý:D¾7µÓ˜—gð‰¢_Bñ=":þËüÝüSà^ETàø™·uûp?ƒ6M^ \ No newline at end of file diff --git a/modules/git/tests/repos/repo1_bare/objects/38/441bf2c4d4c27efff94728c9eb33266f44a702 b/modules/git/tests/repos/repo1_bare/objects/38/441bf2c4d4c27efff94728c9eb33266f44a702 new file mode 100644 index 0000000000000000000000000000000000000000..c3d484aee09e064e9d85cb4a65b40530f8312d7d GIT binary patch literal 134 zcmV;10D1p-0iBIY4#FT509|v6cLAFR1%$*HUAXcTd>$>al%#nk9^dK_T+S?JQg5v? zNaqf`5dlVDl$T1IVw3T<N2F>E+CB@PX~`NW{T&duoT1c(bk6XAWmCimq>wSJK;|N#Xl&jFgr|Mi zRWmlf95b3eLxDzIF2`z``=Na01IpU!j(<=8vAX+YzltuY+HWt%PaLq+>lq6~0sl(! zB#C`Ev9BK|srvqiJGz5k_WBWe{#pIx7*@IZy9A*m7ckQ*RjnatXCbWH9s)-E<3&^AKtjJ8fMd#*yv3WP^ zr-#ko1D{DQD!KHArNk*#s6l@9^)ceY3UbDy*Xjsx4Z#PfnLXXw4)kpn6;v*vxtZ+x z2D_lH)!11s3*Vl2EVMT&3u;d2l;9vgd(z=jMR<4Ku5HEe%a$XWuk&Z=jya!^foJCK`j}+=wi(j%iTp2PFahJMgi2=F4{ey)s9iTJtg1JsUMZ6lJx|N#sQEpJogVP z8uV!CNQ1%b=Fz|{Yj)5Uz`*+Usg8@&a^Mx2bjB$;L|39tjr~|Nl{BTIn=NM*ZfiJ~ zLy#pcW^mVxxU3AA)Vs-eXT{#RjKwQrU8YD0^wp;UQC=@RpR`+Uyf@u zJh8qI3NJ=97+)Hf4c)i%?tUFWLnyHZQGlG*+VZfTI0@Wxi_+_wk2*3uI8%mntNnpkB1t^ Y7yX3&&=be`GduOD{BLx>0RSri=s==DZvX%Q literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/50/13716a9da8e66ea21059a84f1b4311424d2b7f b/modules/git/tests/repos/repo1_bare/objects/50/13716a9da8e66ea21059a84f1b4311424d2b7f new file mode 100644 index 0000000000000000000000000000000000000000..b96905930a2880ea7fd86f55d4d27b17fd7c6aad GIT binary patch literal 31 ncmb7wq!6d00M=i#3F_n@*maD7>ft*UeqUCemK(P= \ No newline at end of file diff --git a/modules/git/tests/repos/repo1_bare/objects/62/d735f9efa9cf5b7df6bac9917b80e4779f4315 b/modules/git/tests/repos/repo1_bare/objects/62/d735f9efa9cf5b7df6bac9917b80e4779f4315 new file mode 100644 index 0000000000000000000000000000000000000000..15b958a2a2d94ab1af697229889fdf138cb610bc GIT binary patch literal 111 zcmV-#0FeK90V^p=O;s>7Fkvt>FfcPQQAo?oNj20fsVHH1Bs87zfMd4I$1fT#okw#V{s RgD*YubNRFK6aXErEt=Y8HN5}; literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/64/3a35374408002fcf2f0e8d42d262a1e0e2f80e b/modules/git/tests/repos/repo1_bare/objects/64/3a35374408002fcf2f0e8d42d262a1e0e2f80e new file mode 100644 index 0000000000000000000000000000000000000000..eb0ad4757554744e23c7cb0093fd1d8b1e0c8259 GIT binary patch literal 32 qcmV+*0N?+30ZYosPf{?nV9?Xk2crDalH$yi)cB&*f_wmF83<7yNf8wQ literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/6c/493ff740f9380390d5c9ddef4af18697ac9375 b/modules/git/tests/repos/repo1_bare/objects/6c/493ff740f9380390d5c9ddef4af18697ac9375 new file mode 100644 index 0000000000000000000000000000000000000000..7d217a785011e7d7830ac92773a95cd277cf7eb7 GIT binary patch literal 21 ccmbAV=y!@Ff%bxNGeLqOU^LVE2$`95S;wq&BWe6i&g2-rtWsR r34s*{KR}hGW#*(p6p7lqO3!=#OLnpNYVn2YFaOT9a25anp@SY2>cA$Z literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/80/06ff9adbf0cb94da7dad9e537e53817f9fa5c0 b/modules/git/tests/repos/repo1_bare/objects/80/06ff9adbf0cb94da7dad9e537e53817f9fa5c0 new file mode 100644 index 0000000000000000000000000000000000000000..808fe6efb6326b4b22be5e3d05a2a43cea60751d GIT binary patch literal 176 zcmV;h08jsT0iBLZP6Z(l09|v6-kZEM3=DK)jBY%E7l3YfkN9RVJ-C?L`#FNkT2!TY zY+Ik;{Q5ApR^Y^h*4iR$Q(1BoR~+Gr7%@<#kU2Hs#e8P1`-CLq8dHebOXMb$3NJA< zEU^@uD5I=Q&6)f)Z$sf-`vGr5k69I-<_}%2eZCyGA#(0@UWQ(u!3O8id2c;DT0}Jb exB2V*Ghkjts=#q>_r8CCbgevxp5`0fyHJV$qg2xX literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/82/26f571dcc2d2f33a7179d929b10b9c39faa631 b/modules/git/tests/repos/repo1_bare/objects/82/26f571dcc2d2f33a7179d929b10b9c39faa631 new file mode 100644 index 0000000000000000000000000000000000000000..6a194fb3a6ad64928934bc79ee8b4eaf83cd8ef5 GIT binary patch literal 71 zcmV-N0J#5n0V^p=O;s>6U@$QN0)?c+B8D0AAJxwoiwEys)F)hiIMU?fso7x=**u`^ dg_ih7Kf(pJ@}}Faf7xWVf4+k9EdV^d8ly9;A+Z1e literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/83/b9c4da46ed59098a009f8640c77eac97b71dfe b/modules/git/tests/repos/repo1_bare/objects/83/b9c4da46ed59098a009f8640c77eac97b71dfe new file mode 100644 index 0000000000000000000000000000000000000000..8602ab5402e8225031a72722dad30f40c0b4169d GIT binary patch literal 115 zcmV-(0F3{50V^p=O;s>7uwXDT00M=iqQt!93?l{!U(e%F+zQ&VdW-&SZIdyYtoY}e zp@D&!iHSm5W=^W1UP(m>!y}>Tj31X=^*!RxeA4<9m)4t_5KkmUMqoubp7!4zep)b3 VxO(#Ld#{ge)7MNc1ppF=EM31(HB|rr literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/8d/92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2 b/modules/git/tests/repos/repo1_bare/objects/8d/92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2 new file mode 100644 index 0000000000000000000000000000000000000000..431a481078f69155e9abc8ce799f60428dfa26be GIT binary patch literal 153 zcmV;K0A~Mq0fo*@3c@fDKw;N8#auwi%w*CAL~!8|JV1UXSZHmD5qf;Z3%GvY;^lQ& zrVbeB(3>ixL8^0FQVArKnNkfkMw^jjs5Nmy@|m33V$)}bASt=R!Mjm)P$og^OSKq1 zVHUQd=jeq^eD}xN;I_wQn-%UaZE(H-3i2Sd)A|^^L literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/95/bb4d39648ee7e325106df01a621c530863a653 b/modules/git/tests/repos/repo1_bare/objects/95/bb4d39648ee7e325106df01a621c530863a653 new file mode 100644 index 0000000000000000000000000000000000000000..6bb6a2564889bd14b18441f9360404988b2a2c3c GIT binary patch literal 121 zcmV-<0EYi~0fo&?3IZ_4WH2-`00M=a%)IRQlKl9L)SR4r2F2{JKKgo^Vml08KbY4O OvFvTojcfpjrxK#K`WkKk literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/9c/9aef8dd84e02bc7ec12641deb4c930a7c30185 b/modules/git/tests/repos/repo1_bare/objects/9c/9aef8dd84e02bc7ec12641deb4c930a7c30185 new file mode 100644 index 000000000..8a263d0d6 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/objects/9c/9aef8dd84e02bc7ec12641deb4c930a7c30185 @@ -0,0 +1,2 @@ +x…ÎM +1 @a×=E. ¤“¦Ó‚.<‚HÛ”œj…9¾â\¿oñò:Ï6ºCoª@è2ûDI+QA©š[V H9P,R %³IÓ¥Cä”\¡è]P•¶èKE+~°™ ƒ'ñLFÞ}ZÜv™·§Âý¥ ΰliddáˆÑäßPÿÖ¿Ô\KÔdÉ“=õ½›ܲ:c \ No newline at end of file diff --git a/modules/git/tests/repos/repo1_bare/objects/b1/4df6442ea5a1b382985a6549b85d435376c351 b/modules/git/tests/repos/repo1_bare/objects/b1/4df6442ea5a1b382985a6549b85d435376c351 new file mode 100644 index 0000000000000000000000000000000000000000..02fe24f0aefaac13965c33a5d42c757a4edf35e7 GIT binary patch literal 18 Zcmbi|f#2QdHu literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/b1/fc9917b618c924cf4aa421dae74e8bf9b556d3 b/modules/git/tests/repos/repo1_bare/objects/b1/fc9917b618c924cf4aa421dae74e8bf9b556d3 new file mode 100644 index 0000000000000000000000000000000000000000..aacc5efc9d0002e837786e4a064d5d2b4dcfc507 GIT binary patch literal 176 zcmV;h08jsT0V^p=O;s>7H)k+000M=i#3F_n@*maD7>ft*UeqUCemK(PDq+w|eg9~o>)qw= z0xy;b&HUldy*vgx3yZ&X9+5Y(o%D13qEdXQrga7o`^D eGo)CVn!9i?=%3f;>vg)6wD7^BAAA5S%SVJo_FR7e literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/b7/5f44edbd9252c32bf9faa0c1257ffb3b126c24 b/modules/git/tests/repos/repo1_bare/objects/b7/5f44edbd9252c32bf9faa0c1257ffb3b126c24 new file mode 100644 index 0000000000000000000000000000000000000000..6c2e007e9f9ac0248d65f46de31db1830200d168 GIT binary patch literal 80 zcmV-W0I&ae0V^p=O;s>AVK6i>Ff%bxNXyJgHPkDqC}DUcG@bF|lB>Q){FzT$pW@Pb mQxoEeq{s-YD96+OyTeZl<_T9%-hJ=&v2FUA$)y0AW*}Zu{U#Cs literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/c8/c90111bdc18b3afd2b2906007059e95ac8fdc3 b/modules/git/tests/repos/repo1_bare/objects/c8/c90111bdc18b3afd2b2906007059e95ac8fdc3 new file mode 100644 index 0000000000000000000000000000000000000000..57c5d7ce848d1a79638cead21f1ea2305e0e9e79 GIT binary patch literal 111 zcmV-#0FeK90V^p=O;s>7Fkvt>FfcPQQAo?oNj20fsVHH1Bs87zhir1rJ&&Y?@6tqLn| RYHsA7WBF^DApk9aE!q4@HmCpq literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/d0/845fe2f85710b50d673dafe98236bf9f2023da b/modules/git/tests/repos/repo1_bare/objects/d0/845fe2f85710b50d673dafe98236bf9f2023da new file mode 100644 index 0000000000000000000000000000000000000000..d29ca5af88e8d8aefebd13c326ef18c9e61d0c91 GIT binary patch literal 50 zcmV-20L}k+0V^p=O;s>9W-v4`Ff%bx$Vkn}$!FN;`^`mf>B7xTGon&Gcf>jemmLlS I02#y&Q17M_xBvhE literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/e2/129701f1a4d54dc44f03c93bca0a2aec7c5449 b/modules/git/tests/repos/repo1_bare/objects/e2/129701f1a4d54dc44f03c93bca0a2aec7c5449 new file mode 100644 index 0000000000000000000000000000000000000000..08245d0012c0582dde8fd5e2f65f8cae03b14e65 GIT binary patch literal 21 ccmb7Fkvt>FfcPQQAo?oNj20fsVHH1Bs87zhC@y|^0Z4xI{&U-CU Ry!G6#`{&lM%K#`mE=Tr)Hy8i_ literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/refs/heads/branch1 b/modules/git/tests/repos/repo1_bare/refs/heads/branch1 new file mode 100644 index 000000000..eb33bd093 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/refs/heads/branch1 @@ -0,0 +1 @@ +2839944139e0de9737a044f78b0e4b40d989a9e3 diff --git a/modules/git/tests/repos/repo1_bare/refs/heads/branch2 b/modules/git/tests/repos/repo1_bare/refs/heads/branch2 new file mode 100644 index 000000000..0475e61f8 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/refs/heads/branch2 @@ -0,0 +1 @@ +5c80b0245c1c6f8343fa418ec374b13b5d4ee658 diff --git a/modules/git/tests/repos/repo1_bare/refs/heads/master b/modules/git/tests/repos/repo1_bare/refs/heads/master new file mode 100644 index 000000000..4804d9d8f --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/refs/heads/master @@ -0,0 +1 @@ +37991dec2c8e592043f47155ce4808d4580f9123 diff --git a/modules/git/tests/repos/repo1_bare/refs/tags/test b/modules/git/tests/repos/repo1_bare/refs/tags/test new file mode 100644 index 000000000..ee311722e --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/refs/tags/test @@ -0,0 +1 @@ +3ad28a9149a2864384548f3d17ed7f38014c9e8a diff --git a/vendor/code.gitea.io/git/tree.go b/modules/git/tree.go similarity index 96% rename from vendor/code.gitea.io/git/tree.go rename to modules/git/tree.go index b65fe1940..5ec22a3a6 100644 --- a/vendor/code.gitea.io/git/tree.go +++ b/modules/git/tree.go @@ -19,8 +19,8 @@ type Tree struct { entries Entries entriesParsed bool - entriesRecursive Entries - entriesRecursiveParsed bool + entriesRecursive Entries + entriesRecursiveParsed bool } // NewTree create a new tree according the repository and commit id diff --git a/vendor/code.gitea.io/git/tree_blob.go b/modules/git/tree_blob.go similarity index 90% rename from vendor/code.gitea.io/git/tree_blob.go rename to modules/git/tree_blob.go index b3d205d8e..a37f6b227 100644 --- a/vendor/code.gitea.io/git/tree_blob.go +++ b/modules/git/tree_blob.go @@ -9,7 +9,7 @@ import ( "strings" ) -// GetTreeEntryByPath get the tree entries accroding the sub dir +// GetTreeEntryByPath get the tree entries according the sub dir func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) { if len(relpath) == 0 { return &TreeEntry{ @@ -44,7 +44,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) { return nil, ErrNotExist{"", relpath} } -// GetBlobByPath get the blob object accroding the path +// GetBlobByPath get the blob object according the path func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) { entry, err := t.GetTreeEntryByPath(relpath) if err != nil { diff --git a/vendor/code.gitea.io/git/tree_entry.go b/modules/git/tree_entry.go similarity index 99% rename from vendor/code.gitea.io/git/tree_entry.go rename to modules/git/tree_entry.go index ead0d4f5d..5b74e9a69 100644 --- a/vendor/code.gitea.io/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -39,7 +39,7 @@ type TreeEntry struct { ptree *Tree - commited bool + committed bool size int64 sized bool diff --git a/modules/git/tree_entry_test.go b/modules/git/tree_entry_test.go new file mode 100644 index 000000000..52920bc00 --- /dev/null +++ b/modules/git/tree_entry_test.go @@ -0,0 +1,98 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func getTestEntries() Entries { + return Entries{ + &TreeEntry{name: "v1.0", mode: EntryModeTree}, + &TreeEntry{name: "v2.0", mode: EntryModeTree}, + &TreeEntry{name: "v2.1", mode: EntryModeTree}, + &TreeEntry{name: "v2.12", mode: EntryModeTree}, + &TreeEntry{name: "v2.2", mode: EntryModeTree}, + &TreeEntry{name: "v12.0", mode: EntryModeTree}, + &TreeEntry{name: "abc", mode: EntryModeBlob}, + &TreeEntry{name: "bcd", mode: EntryModeBlob}, + } +} + +func TestEntriesSort(t *testing.T) { + entries := getTestEntries() + entries.Sort() + assert.Equal(t, "v1.0", entries[0].Name()) + assert.Equal(t, "v12.0", entries[1].Name()) + assert.Equal(t, "v2.0", entries[2].Name()) + assert.Equal(t, "v2.1", entries[3].Name()) + assert.Equal(t, "v2.12", entries[4].Name()) + assert.Equal(t, "v2.2", entries[5].Name()) + assert.Equal(t, "abc", entries[6].Name()) + assert.Equal(t, "bcd", entries[7].Name()) +} + +func TestEntriesCustomSort(t *testing.T) { + entries := getTestEntries() + entries.CustomSort(func(s1, s2 string) bool { + return s1 > s2 + }) + assert.Equal(t, "v2.2", entries[0].Name()) + assert.Equal(t, "v2.12", entries[1].Name()) + assert.Equal(t, "v2.1", entries[2].Name()) + assert.Equal(t, "v2.0", entries[3].Name()) + assert.Equal(t, "v12.0", entries[4].Name()) + assert.Equal(t, "v1.0", entries[5].Name()) + assert.Equal(t, "bcd", entries[6].Name()) + assert.Equal(t, "abc", entries[7].Name()) +} + +func TestFollowLink(t *testing.T) { + r, err := OpenRepository("tests/repos/repo1_bare") + assert.NoError(t, err) + + commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123") + assert.NoError(t, err) + + // get the symlink + lnk, err := commit.Tree.GetTreeEntryByPath("foo/bar/link_to_hello") + assert.NoError(t, err) + assert.True(t, lnk.IsLink()) + + // should be able to dereference to target + target, err := lnk.FollowLink() + assert.NoError(t, err) + assert.Equal(t, target.Name(), "hello") + assert.False(t, target.IsLink()) + assert.Equal(t, target.ID.String(), "b14df6442ea5a1b382985a6549b85d435376c351") + + // should error when called on normal file + target, err = commit.Tree.GetTreeEntryByPath("file1.txt") + assert.NoError(t, err) + _, err = target.FollowLink() + assert.Equal(t, err.Error(), "file1.txt: not a symlink") + + // should error for broken links + target, err = commit.Tree.GetTreeEntryByPath("foo/broken_link") + assert.NoError(t, err) + assert.True(t, target.IsLink()) + _, err = target.FollowLink() + assert.Equal(t, err.Error(), "broken_link: broken link") + + // should error for external links + target, err = commit.Tree.GetTreeEntryByPath("foo/outside_repo") + assert.NoError(t, err) + assert.True(t, target.IsLink()) + _, err = target.FollowLink() + assert.Equal(t, err.Error(), "outside_repo: points outside of repo") + + // testing fix for short link bug + target, err = commit.Tree.GetTreeEntryByPath("foo/link_short") + assert.NoError(t, err) + _, err = target.FollowLink() + assert.Equal(t, err.Error(), "link_short: broken link") +} diff --git a/vendor/code.gitea.io/git/utils.go b/modules/git/utils.go similarity index 100% rename from vendor/code.gitea.io/git/utils.go rename to modules/git/utils.go diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index bac90f5bb..e44f3cc63 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -5,8 +5,8 @@ package base import ( - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" ) // Notifier defines an interface to notify receiver diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 608bd0dca..12be1999f 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -5,8 +5,8 @@ package base import ( - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" ) // NullNotifier implements a blank notifier diff --git a/modules/notification/notification.go b/modules/notification/notification.go index e38c36f7d..e0de88346 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -5,8 +5,8 @@ package notification import ( - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/indexer" "code.gitea.io/gitea/modules/notification/mail" diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go index 135e92abf..987004358 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -5,8 +5,8 @@ package ui import ( - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" ) diff --git a/modules/setting/git.go b/modules/setting/git.go index 59951fcb9..5d9701a43 100644 --- a/modules/setting/git.go +++ b/modules/setting/git.go @@ -7,8 +7,9 @@ package setting import ( "time" - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + version "github.com/mcuadros/go-version" ) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index ac44f54f0..95fca20b1 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -20,8 +20,8 @@ import ( "strings" "time" - "code.gitea.io/git" "code.gitea.io/gitea/modules/generate" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" _ "code.gitea.io/gitea/modules/minwinsvc" // import minwinsvc for windows services "code.gitea.io/gitea/modules/user" diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index af986001a..d5a800d36 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -6,14 +6,13 @@ package test import ( "net/http" + "net/http/httptest" "net/url" "testing" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" - - "net/http/httptest" + "code.gitea.io/gitea/modules/git" "github.com/go-macaron/session" "github.com/stretchr/testify/assert" diff --git a/modules/uploader/delete.go b/modules/uploader/delete.go index fbe451c5d..2353f18c4 100644 --- a/modules/uploader/delete.go +++ b/modules/uploader/delete.go @@ -7,8 +7,8 @@ package uploader import ( "fmt" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" ) // DeleteRepoFileOptions holds the repository delete file options diff --git a/modules/uploader/update.go b/modules/uploader/update.go index 08caf11ee..bc543c7ff 100644 --- a/modules/uploader/update.go +++ b/modules/uploader/update.go @@ -8,8 +8,8 @@ import ( "fmt" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/setting" ) diff --git a/modules/uploader/upload.go b/modules/uploader/upload.go index bee3f1b9b..81d7c3ba2 100644 --- a/modules/uploader/upload.go +++ b/modules/uploader/upload.go @@ -10,11 +10,10 @@ import ( "path" "strings" + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/setting" - - "code.gitea.io/git" - "code.gitea.io/gitea/models" ) // UploadRepoFileOptions contains the uploaded repository file options diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go index 6569d21ab..7de4d5acc 100644 --- a/routers/api/v1/convert/convert.go +++ b/routers/api/v1/convert/convert.go @@ -7,14 +7,13 @@ package convert import ( "fmt" - "github.com/Unknwon/com" - - api "code.gitea.io/sdk/gitea" - - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" + api "code.gitea.io/sdk/gitea" + + "github.com/Unknwon/com" ) // ToEmail convert models.EmailAddress to api.Email diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index 3596e8801..75eff488d 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -8,12 +8,11 @@ package repo import ( "time" - "code.gitea.io/git" - api "code.gitea.io/sdk/gitea" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" + api "code.gitea.io/sdk/gitea" ) // GetSingleCommit get a commit via diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 929ed00d6..3ce80d24f 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -8,9 +8,8 @@ package repo import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/routers/repo" - - "code.gitea.io/git" ) // GetRawFile get a file by path on a repository diff --git a/routers/api/v1/repo/git_ref.go b/routers/api/v1/repo/git_ref.go index ffdfc57b1..6a6ed9ff3 100644 --- a/routers/api/v1/repo/git_ref.go +++ b/routers/api/v1/repo/git_ref.go @@ -6,8 +6,7 @@ package repo import ( "code.gitea.io/gitea/modules/context" - - "code.gitea.io/git" + "code.gitea.io/gitea/modules/git" api "code.gitea.io/sdk/gitea" ) diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index f01049721..ef9d5ac1d 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -5,9 +5,9 @@ package repo import ( - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/routers/api/v1/convert" "code.gitea.io/gitea/routers/api/v1/utils" api "code.gitea.io/sdk/gitea" diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 156ca83a1..7abe6241b 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -9,14 +9,13 @@ import ( "net/http" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/util" - api "code.gitea.io/sdk/gitea" ) diff --git a/routers/api/v1/repo/tree.go b/routers/api/v1/repo/tree.go index 8a5d0c4b0..012eba673 100644 --- a/routers/api/v1/repo/tree.go +++ b/routers/api/v1/repo/tree.go @@ -8,8 +8,8 @@ import ( "fmt" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/sdk/gitea" ) diff --git a/routers/init.go b/routers/init.go index 2fc3bb966..3b8d8ac90 100644 --- a/routers/init.go +++ b/routers/init.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/migrations" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/cron" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/highlight" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" "code.gitea.io/gitea/modules/log" diff --git a/routers/private/push_update.go b/routers/private/push_update.go index 988d27334..5c42f066e 100644 --- a/routers/private/push_update.go +++ b/routers/private/push_update.go @@ -8,8 +8,8 @@ import ( "encoding/json" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" macaron "gopkg.in/macaron.v1" diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 44fd4bcd1..19925c1ed 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -8,11 +8,11 @@ package repo import ( "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" ) diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 820a54646..9e40ced7f 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -8,10 +8,10 @@ import ( "path" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" diff --git a/routers/repo/download.go b/routers/repo/download.go index 57a1e65ac..41c4a1810 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -11,10 +11,9 @@ import ( "path" "strings" - "code.gitea.io/git" - "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" ) diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 01963d8dc..54046258b 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -11,11 +11,11 @@ import ( "path" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 33d3ec6a7..2db2cfc71 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -15,20 +15,20 @@ import ( "strconv" "strings" - "github.com/Unknwon/com" - "github.com/Unknwon/paginater" - - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + + "github.com/Unknwon/com" + "github.com/Unknwon/paginater" ) const ( diff --git a/routers/repo/middlewares.go b/routers/repo/middlewares.go index 4dee272ed..6ff09cb84 100644 --- a/routers/repo/middlewares.go +++ b/routers/repo/middlewares.go @@ -3,9 +3,9 @@ package repo import ( "fmt" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" ) // SetEditorconfigIfExists set editor config as render variable diff --git a/routers/repo/pull.go b/routers/repo/pull.go index c61ae905f..08c833c16 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -13,11 +13,11 @@ import ( "path" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 42dfd5626..5add788fc 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -10,17 +10,16 @@ import ( "path" "strings" - "github.com/Unknwon/com" - - "code.gitea.io/git" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + + "github.com/Unknwon/com" ) const ( diff --git a/routers/repo/setting.go b/routers/repo/setting.go index d68edb4e5..2520b57bc 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -10,12 +10,11 @@ import ( "strings" "time" - "code.gitea.io/git" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" diff --git a/routers/repo/setting_protected_branch.go b/routers/repo/setting_protected_branch.go index def27753d..05ad0ec0e 100644 --- a/routers/repo/setting_protected_branch.go +++ b/routers/repo/setting_protected_branch.go @@ -8,11 +8,11 @@ import ( "fmt" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) diff --git a/routers/repo/view.go b/routers/repo/view.go index 786cfcbc5..dcd546ff6 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -14,10 +14,10 @@ import ( "path" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/highlight" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index cea514535..8510cb7ba 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -12,11 +12,11 @@ import ( "path" "strings" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/sdk/gitea" diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 8426406c3..790214e8e 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -11,12 +11,11 @@ import ( "path/filepath" "strings" - "code.gitea.io/git" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/util" diff --git a/routers/repo/wiki_test.go b/routers/repo/wiki_test.go index 99812cab4..7302f9e48 100644 --- a/routers/repo/wiki_test.go +++ b/routers/repo/wiki_test.go @@ -9,9 +9,9 @@ import ( "net/http" "testing" - "code.gitea.io/git" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" diff --git a/vendor/code.gitea.io/git/LICENSE b/vendor/code.gitea.io/git/LICENSE deleted file mode 100644 index 10aeba46b..000000000 --- a/vendor/code.gitea.io/git/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 The Gitea Authors -Copyright (c) 2014 The Gogs Authors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/code.gitea.io/git/doc.go b/vendor/code.gitea.io/git/doc.go deleted file mode 100644 index 1941d2855..000000000 --- a/vendor/code.gitea.io/git/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2016 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git // import "code.gitea.io/git" diff --git a/vendor/github.com/stretchr/testify/require/doc.go b/vendor/github.com/stretchr/testify/require/doc.go new file mode 100644 index 000000000..169de3922 --- /dev/null +++ b/vendor/github.com/stretchr/testify/require/doc.go @@ -0,0 +1,28 @@ +// Package require implements the same assertions as the `assert` package but +// stops test execution when a test fails. +// +// Example Usage +// +// The following is a complete example using require in a standard test function: +// import ( +// "testing" +// "github.com/stretchr/testify/require" +// ) +// +// func TestSomething(t *testing.T) { +// +// var a string = "Hello" +// var b string = "Hello" +// +// require.Equal(t, a, b, "The two words should be the same.") +// +// } +// +// Assertions +// +// The `require` package have same global functions as in the `assert` package, +// but instead of returning a boolean result they call `t.FailNow()`. +// +// Every assertion function also takes an optional string message as the final argument, +// allowing custom error messages to be appended to the message the assertion method outputs. +package require diff --git a/vendor/github.com/stretchr/testify/require/forward_requirements.go b/vendor/github.com/stretchr/testify/require/forward_requirements.go new file mode 100644 index 000000000..ac71d4058 --- /dev/null +++ b/vendor/github.com/stretchr/testify/require/forward_requirements.go @@ -0,0 +1,16 @@ +package require + +// Assertions provides assertion methods around the +// TestingT interface. +type Assertions struct { + t TestingT +} + +// New makes a new Assertions object for the specified TestingT. +func New(t TestingT) *Assertions { + return &Assertions{ + t: t, + } +} + +//go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl -include-format-funcs diff --git a/vendor/github.com/stretchr/testify/require/require.go b/vendor/github.com/stretchr/testify/require/require.go new file mode 100644 index 000000000..ac3c30878 --- /dev/null +++ b/vendor/github.com/stretchr/testify/require/require.go @@ -0,0 +1,867 @@ +/* +* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen +* THIS FILE MUST NOT BE EDITED BY HAND + */ + +package require + +import ( + assert "github.com/stretchr/testify/assert" + http "net/http" + url "net/url" + time "time" +) + +// Condition uses a Comparison to assert a complex condition. +func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { + if !assert.Condition(t, comp, msgAndArgs...) { + t.FailNow() + } +} + +// Conditionf uses a Comparison to assert a complex condition. +func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) { + if !assert.Conditionf(t, comp, msg, args...) { + t.FailNow() + } +} + +// Contains asserts that the specified string, list(array, slice...) or map contains the +// specified substring or element. +// +// assert.Contains(t, "Hello World", "World") +// assert.Contains(t, ["Hello", "World"], "World") +// assert.Contains(t, {"Hello": "World"}, "Hello") +func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { + if !assert.Contains(t, s, contains, msgAndArgs...) { + t.FailNow() + } +} + +// Containsf asserts that the specified string, list(array, slice...) or map contains the +// specified substring or element. +// +// assert.Containsf(t, "Hello World", "World", "error message %s", "formatted") +// assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") +// assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") +func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { + if !assert.Containsf(t, s, contains, msg, args...) { + t.FailNow() + } +} + +// DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. +func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { + if !assert.DirExists(t, path, msgAndArgs...) { + t.FailNow() + } +} + +// DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. +func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { + if !assert.DirExistsf(t, path, msg, args...) { + t.FailNow() + } +} + +// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should match. +// +// assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) +func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { + if !assert.ElementsMatch(t, listA, listB, msgAndArgs...) { + t.FailNow() + } +} + +// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should match. +// +// assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") +func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { + if !assert.ElementsMatchf(t, listA, listB, msg, args...) { + t.FailNow() + } +} + +// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// assert.Empty(t, obj) +func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { + if !assert.Empty(t, object, msgAndArgs...) { + t.FailNow() + } +} + +// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// assert.Emptyf(t, obj, "error message %s", "formatted") +func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { + if !assert.Emptyf(t, object, msg, args...) { + t.FailNow() + } +} + +// Equal asserts that two objects are equal. +// +// assert.Equal(t, 123, 123) +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). Function equality +// cannot be determined and will always fail. +func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + if !assert.Equal(t, expected, actual, msgAndArgs...) { + t.FailNow() + } +} + +// EqualError asserts that a function returned an error (i.e. not `nil`) +// and that it is equal to the provided error. +// +// actualObj, err := SomeFunction() +// assert.EqualError(t, err, expectedErrorString) +func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { + if !assert.EqualError(t, theError, errString, msgAndArgs...) { + t.FailNow() + } +} + +// EqualErrorf asserts that a function returned an error (i.e. not `nil`) +// and that it is equal to the provided error. +// +// actualObj, err := SomeFunction() +// assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") +func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { + if !assert.EqualErrorf(t, theError, errString, msg, args...) { + t.FailNow() + } +} + +// EqualValues asserts that two objects are equal or convertable to the same types +// and equal. +// +// assert.EqualValues(t, uint32(123), int32(123)) +func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + if !assert.EqualValues(t, expected, actual, msgAndArgs...) { + t.FailNow() + } +} + +// EqualValuesf asserts that two objects are equal or convertable to the same types +// and equal. +// +// assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123)) +func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { + if !assert.EqualValuesf(t, expected, actual, msg, args...) { + t.FailNow() + } +} + +// Equalf asserts that two objects are equal. +// +// assert.Equalf(t, 123, 123, "error message %s", "formatted") +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). Function equality +// cannot be determined and will always fail. +func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { + if !assert.Equalf(t, expected, actual, msg, args...) { + t.FailNow() + } +} + +// Error asserts that a function returned an error (i.e. not `nil`). +// +// actualObj, err := SomeFunction() +// if assert.Error(t, err) { +// assert.Equal(t, expectedError, err) +// } +func Error(t TestingT, err error, msgAndArgs ...interface{}) { + if !assert.Error(t, err, msgAndArgs...) { + t.FailNow() + } +} + +// Errorf asserts that a function returned an error (i.e. not `nil`). +// +// actualObj, err := SomeFunction() +// if assert.Errorf(t, err, "error message %s", "formatted") { +// assert.Equal(t, expectedErrorf, err) +// } +func Errorf(t TestingT, err error, msg string, args ...interface{}) { + if !assert.Errorf(t, err, msg, args...) { + t.FailNow() + } +} + +// Exactly asserts that two objects are equal in value and type. +// +// assert.Exactly(t, int32(123), int64(123)) +func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + if !assert.Exactly(t, expected, actual, msgAndArgs...) { + t.FailNow() + } +} + +// Exactlyf asserts that two objects are equal in value and type. +// +// assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123)) +func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { + if !assert.Exactlyf(t, expected, actual, msg, args...) { + t.FailNow() + } +} + +// Fail reports a failure through +func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { + if !assert.Fail(t, failureMessage, msgAndArgs...) { + t.FailNow() + } +} + +// FailNow fails test +func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { + if !assert.FailNow(t, failureMessage, msgAndArgs...) { + t.FailNow() + } +} + +// FailNowf fails test +func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) { + if !assert.FailNowf(t, failureMessage, msg, args...) { + t.FailNow() + } +} + +// Failf reports a failure through +func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { + if !assert.Failf(t, failureMessage, msg, args...) { + t.FailNow() + } +} + +// False asserts that the specified value is false. +// +// assert.False(t, myBool) +func False(t TestingT, value bool, msgAndArgs ...interface{}) { + if !assert.False(t, value, msgAndArgs...) { + t.FailNow() + } +} + +// Falsef asserts that the specified value is false. +// +// assert.Falsef(t, myBool, "error message %s", "formatted") +func Falsef(t TestingT, value bool, msg string, args ...interface{}) { + if !assert.Falsef(t, value, msg, args...) { + t.FailNow() + } +} + +// FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. +func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { + if !assert.FileExists(t, path, msgAndArgs...) { + t.FailNow() + } +} + +// FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. +func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { + if !assert.FileExistsf(t, path, msg, args...) { + t.FailNow() + } +} + +// HTTPBodyContains asserts that a specified handler returns a +// body that contains a string. +// +// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { + if !assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) { + t.FailNow() + } +} + +// HTTPBodyContainsf asserts that a specified handler returns a +// body that contains a string. +// +// assert.HTTPBodyContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { + if !assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) { + t.FailNow() + } +} + +// HTTPBodyNotContains asserts that a specified handler returns a +// body that does not contain a string. +// +// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { + if !assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) { + t.FailNow() + } +} + +// HTTPBodyNotContainsf asserts that a specified handler returns a +// body that does not contain a string. +// +// assert.HTTPBodyNotContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { + if !assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) { + t.FailNow() + } +} + +// HTTPError asserts that a specified handler returns an error status code. +// +// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { + if !assert.HTTPError(t, handler, method, url, values, msgAndArgs...) { + t.FailNow() + } +} + +// HTTPErrorf asserts that a specified handler returns an error status code. +// +// assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). +func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { + if !assert.HTTPErrorf(t, handler, method, url, values, msg, args...) { + t.FailNow() + } +} + +// HTTPRedirect asserts that a specified handler returns a redirect status code. +// +// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { + if !assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) { + t.FailNow() + } +} + +// HTTPRedirectf asserts that a specified handler returns a redirect status code. +// +// assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). +func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { + if !assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) { + t.FailNow() + } +} + +// HTTPSuccess asserts that a specified handler returns a success status code. +// +// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { + if !assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) { + t.FailNow() + } +} + +// HTTPSuccessf asserts that a specified handler returns a success status code. +// +// assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { + if !assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) { + t.FailNow() + } +} + +// Implements asserts that an object is implemented by the specified interface. +// +// assert.Implements(t, (*MyInterface)(nil), new(MyObject)) +func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { + if !assert.Implements(t, interfaceObject, object, msgAndArgs...) { + t.FailNow() + } +} + +// Implementsf asserts that an object is implemented by the specified interface. +// +// assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject)) +func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { + if !assert.Implementsf(t, interfaceObject, object, msg, args...) { + t.FailNow() + } +} + +// InDelta asserts that the two numerals are within delta of each other. +// +// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01) +func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { + if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) { + t.FailNow() + } +} + +// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. +func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { + if !assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) { + t.FailNow() + } +} + +// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. +func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { + if !assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) { + t.FailNow() + } +} + +// InDeltaSlice is the same as InDelta, except it compares two slices. +func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { + if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) { + t.FailNow() + } +} + +// InDeltaSlicef is the same as InDelta, except it compares two slices. +func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { + if !assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) { + t.FailNow() + } +} + +// InDeltaf asserts that the two numerals are within delta of each other. +// +// assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01) +func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { + if !assert.InDeltaf(t, expected, actual, delta, msg, args...) { + t.FailNow() + } +} + +// InEpsilon asserts that expected and actual have a relative error less than epsilon +func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { + if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) { + t.FailNow() + } +} + +// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. +func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { + if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) { + t.FailNow() + } +} + +// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. +func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { + if !assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) { + t.FailNow() + } +} + +// InEpsilonf asserts that expected and actual have a relative error less than epsilon +func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { + if !assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) { + t.FailNow() + } +} + +// IsType asserts that the specified objects are of the same type. +func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { + if !assert.IsType(t, expectedType, object, msgAndArgs...) { + t.FailNow() + } +} + +// IsTypef asserts that the specified objects are of the same type. +func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) { + if !assert.IsTypef(t, expectedType, object, msg, args...) { + t.FailNow() + } +} + +// JSONEq asserts that two JSON strings are equivalent. +// +// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) +func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { + if !assert.JSONEq(t, expected, actual, msgAndArgs...) { + t.FailNow() + } +} + +// JSONEqf asserts that two JSON strings are equivalent. +// +// assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") +func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { + if !assert.JSONEqf(t, expected, actual, msg, args...) { + t.FailNow() + } +} + +// Len asserts that the specified object has specific length. +// Len also fails if the object has a type that len() not accept. +// +// assert.Len(t, mySlice, 3) +func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { + if !assert.Len(t, object, length, msgAndArgs...) { + t.FailNow() + } +} + +// Lenf asserts that the specified object has specific length. +// Lenf also fails if the object has a type that len() not accept. +// +// assert.Lenf(t, mySlice, 3, "error message %s", "formatted") +func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) { + if !assert.Lenf(t, object, length, msg, args...) { + t.FailNow() + } +} + +// Nil asserts that the specified object is nil. +// +// assert.Nil(t, err) +func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { + if !assert.Nil(t, object, msgAndArgs...) { + t.FailNow() + } +} + +// Nilf asserts that the specified object is nil. +// +// assert.Nilf(t, err, "error message %s", "formatted") +func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { + if !assert.Nilf(t, object, msg, args...) { + t.FailNow() + } +} + +// NoError asserts that a function returned no error (i.e. `nil`). +// +// actualObj, err := SomeFunction() +// if assert.NoError(t, err) { +// assert.Equal(t, expectedObj, actualObj) +// } +func NoError(t TestingT, err error, msgAndArgs ...interface{}) { + if !assert.NoError(t, err, msgAndArgs...) { + t.FailNow() + } +} + +// NoErrorf asserts that a function returned no error (i.e. `nil`). +// +// actualObj, err := SomeFunction() +// if assert.NoErrorf(t, err, "error message %s", "formatted") { +// assert.Equal(t, expectedObj, actualObj) +// } +func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { + if !assert.NoErrorf(t, err, msg, args...) { + t.FailNow() + } +} + +// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the +// specified substring or element. +// +// assert.NotContains(t, "Hello World", "Earth") +// assert.NotContains(t, ["Hello", "World"], "Earth") +// assert.NotContains(t, {"Hello": "World"}, "Earth") +func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { + if !assert.NotContains(t, s, contains, msgAndArgs...) { + t.FailNow() + } +} + +// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the +// specified substring or element. +// +// assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") +// assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") +// assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") +func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { + if !assert.NotContainsf(t, s, contains, msg, args...) { + t.FailNow() + } +} + +// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// if assert.NotEmpty(t, obj) { +// assert.Equal(t, "two", obj[1]) +// } +func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { + if !assert.NotEmpty(t, object, msgAndArgs...) { + t.FailNow() + } +} + +// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// if assert.NotEmptyf(t, obj, "error message %s", "formatted") { +// assert.Equal(t, "two", obj[1]) +// } +func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { + if !assert.NotEmptyf(t, object, msg, args...) { + t.FailNow() + } +} + +// NotEqual asserts that the specified values are NOT equal. +// +// assert.NotEqual(t, obj1, obj2) +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). +func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + if !assert.NotEqual(t, expected, actual, msgAndArgs...) { + t.FailNow() + } +} + +// NotEqualf asserts that the specified values are NOT equal. +// +// assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted") +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). +func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { + if !assert.NotEqualf(t, expected, actual, msg, args...) { + t.FailNow() + } +} + +// NotNil asserts that the specified object is not nil. +// +// assert.NotNil(t, err) +func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { + if !assert.NotNil(t, object, msgAndArgs...) { + t.FailNow() + } +} + +// NotNilf asserts that the specified object is not nil. +// +// assert.NotNilf(t, err, "error message %s", "formatted") +func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { + if !assert.NotNilf(t, object, msg, args...) { + t.FailNow() + } +} + +// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. +// +// assert.NotPanics(t, func(){ RemainCalm() }) +func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { + if !assert.NotPanics(t, f, msgAndArgs...) { + t.FailNow() + } +} + +// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. +// +// assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") +func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { + if !assert.NotPanicsf(t, f, msg, args...) { + t.FailNow() + } +} + +// NotRegexp asserts that a specified regexp does not match a string. +// +// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") +// assert.NotRegexp(t, "^start", "it's not starting") +func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { + if !assert.NotRegexp(t, rx, str, msgAndArgs...) { + t.FailNow() + } +} + +// NotRegexpf asserts that a specified regexp does not match a string. +// +// assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting") +// assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") +func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { + if !assert.NotRegexpf(t, rx, str, msg, args...) { + t.FailNow() + } +} + +// NotSubset asserts that the specified list(array, slice...) contains not all +// elements given in the specified subset(array, slice...). +// +// assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") +func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { + if !assert.NotSubset(t, list, subset, msgAndArgs...) { + t.FailNow() + } +} + +// NotSubsetf asserts that the specified list(array, slice...) contains not all +// elements given in the specified subset(array, slice...). +// +// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") +func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { + if !assert.NotSubsetf(t, list, subset, msg, args...) { + t.FailNow() + } +} + +// NotZero asserts that i is not the zero value for its type. +func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { + if !assert.NotZero(t, i, msgAndArgs...) { + t.FailNow() + } +} + +// NotZerof asserts that i is not the zero value for its type. +func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { + if !assert.NotZerof(t, i, msg, args...) { + t.FailNow() + } +} + +// Panics asserts that the code inside the specified PanicTestFunc panics. +// +// assert.Panics(t, func(){ GoCrazy() }) +func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { + if !assert.Panics(t, f, msgAndArgs...) { + t.FailNow() + } +} + +// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that +// the recovered panic value equals the expected panic value. +// +// assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) +func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { + if !assert.PanicsWithValue(t, expected, f, msgAndArgs...) { + t.FailNow() + } +} + +// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that +// the recovered panic value equals the expected panic value. +// +// assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") +func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { + if !assert.PanicsWithValuef(t, expected, f, msg, args...) { + t.FailNow() + } +} + +// Panicsf asserts that the code inside the specified PanicTestFunc panics. +// +// assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") +func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { + if !assert.Panicsf(t, f, msg, args...) { + t.FailNow() + } +} + +// Regexp asserts that a specified regexp matches a string. +// +// assert.Regexp(t, regexp.MustCompile("start"), "it's starting") +// assert.Regexp(t, "start...$", "it's not starting") +func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { + if !assert.Regexp(t, rx, str, msgAndArgs...) { + t.FailNow() + } +} + +// Regexpf asserts that a specified regexp matches a string. +// +// assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting") +// assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") +func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { + if !assert.Regexpf(t, rx, str, msg, args...) { + t.FailNow() + } +} + +// Subset asserts that the specified list(array, slice...) contains all +// elements given in the specified subset(array, slice...). +// +// assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") +func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { + if !assert.Subset(t, list, subset, msgAndArgs...) { + t.FailNow() + } +} + +// Subsetf asserts that the specified list(array, slice...) contains all +// elements given in the specified subset(array, slice...). +// +// assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") +func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { + if !assert.Subsetf(t, list, subset, msg, args...) { + t.FailNow() + } +} + +// True asserts that the specified value is true. +// +// assert.True(t, myBool) +func True(t TestingT, value bool, msgAndArgs ...interface{}) { + if !assert.True(t, value, msgAndArgs...) { + t.FailNow() + } +} + +// Truef asserts that the specified value is true. +// +// assert.Truef(t, myBool, "error message %s", "formatted") +func Truef(t TestingT, value bool, msg string, args ...interface{}) { + if !assert.Truef(t, value, msg, args...) { + t.FailNow() + } +} + +// WithinDuration asserts that the two times are within duration delta of each other. +// +// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) +func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { + if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) { + t.FailNow() + } +} + +// WithinDurationf asserts that the two times are within duration delta of each other. +// +// assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") +func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { + if !assert.WithinDurationf(t, expected, actual, delta, msg, args...) { + t.FailNow() + } +} + +// Zero asserts that i is the zero value for its type. +func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { + if !assert.Zero(t, i, msgAndArgs...) { + t.FailNow() + } +} + +// Zerof asserts that i is the zero value for its type. +func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { + if !assert.Zerof(t, i, msg, args...) { + t.FailNow() + } +} diff --git a/vendor/github.com/stretchr/testify/require/require_forward.go b/vendor/github.com/stretchr/testify/require/require_forward.go new file mode 100644 index 000000000..299ceb95a --- /dev/null +++ b/vendor/github.com/stretchr/testify/require/require_forward.go @@ -0,0 +1,687 @@ +/* +* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen +* THIS FILE MUST NOT BE EDITED BY HAND + */ + +package require + +import ( + assert "github.com/stretchr/testify/assert" + http "net/http" + url "net/url" + time "time" +) + +// Condition uses a Comparison to assert a complex condition. +func (a *Assertions) Condition(comp assert.Comparison, msgAndArgs ...interface{}) { + Condition(a.t, comp, msgAndArgs...) +} + +// Conditionf uses a Comparison to assert a complex condition. +func (a *Assertions) Conditionf(comp assert.Comparison, msg string, args ...interface{}) { + Conditionf(a.t, comp, msg, args...) +} + +// Contains asserts that the specified string, list(array, slice...) or map contains the +// specified substring or element. +// +// a.Contains("Hello World", "World") +// a.Contains(["Hello", "World"], "World") +// a.Contains({"Hello": "World"}, "Hello") +func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) { + Contains(a.t, s, contains, msgAndArgs...) +} + +// Containsf asserts that the specified string, list(array, slice...) or map contains the +// specified substring or element. +// +// a.Containsf("Hello World", "World", "error message %s", "formatted") +// a.Containsf(["Hello", "World"], "World", "error message %s", "formatted") +// a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted") +func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) { + Containsf(a.t, s, contains, msg, args...) +} + +// DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. +func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) { + DirExists(a.t, path, msgAndArgs...) +} + +// DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. +func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) { + DirExistsf(a.t, path, msg, args...) +} + +// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should match. +// +// a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2]) +func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) { + ElementsMatch(a.t, listA, listB, msgAndArgs...) +} + +// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should match. +// +// a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") +func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) { + ElementsMatchf(a.t, listA, listB, msg, args...) +} + +// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// a.Empty(obj) +func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) { + Empty(a.t, object, msgAndArgs...) +} + +// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// a.Emptyf(obj, "error message %s", "formatted") +func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) { + Emptyf(a.t, object, msg, args...) +} + +// Equal asserts that two objects are equal. +// +// a.Equal(123, 123) +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). Function equality +// cannot be determined and will always fail. +func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + Equal(a.t, expected, actual, msgAndArgs...) +} + +// EqualError asserts that a function returned an error (i.e. not `nil`) +// and that it is equal to the provided error. +// +// actualObj, err := SomeFunction() +// a.EqualError(err, expectedErrorString) +func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) { + EqualError(a.t, theError, errString, msgAndArgs...) +} + +// EqualErrorf asserts that a function returned an error (i.e. not `nil`) +// and that it is equal to the provided error. +// +// actualObj, err := SomeFunction() +// a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted") +func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) { + EqualErrorf(a.t, theError, errString, msg, args...) +} + +// EqualValues asserts that two objects are equal or convertable to the same types +// and equal. +// +// a.EqualValues(uint32(123), int32(123)) +func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + EqualValues(a.t, expected, actual, msgAndArgs...) +} + +// EqualValuesf asserts that two objects are equal or convertable to the same types +// and equal. +// +// a.EqualValuesf(uint32(123, "error message %s", "formatted"), int32(123)) +func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) { + EqualValuesf(a.t, expected, actual, msg, args...) +} + +// Equalf asserts that two objects are equal. +// +// a.Equalf(123, 123, "error message %s", "formatted") +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). Function equality +// cannot be determined and will always fail. +func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) { + Equalf(a.t, expected, actual, msg, args...) +} + +// Error asserts that a function returned an error (i.e. not `nil`). +// +// actualObj, err := SomeFunction() +// if a.Error(err) { +// assert.Equal(t, expectedError, err) +// } +func (a *Assertions) Error(err error, msgAndArgs ...interface{}) { + Error(a.t, err, msgAndArgs...) +} + +// Errorf asserts that a function returned an error (i.e. not `nil`). +// +// actualObj, err := SomeFunction() +// if a.Errorf(err, "error message %s", "formatted") { +// assert.Equal(t, expectedErrorf, err) +// } +func (a *Assertions) Errorf(err error, msg string, args ...interface{}) { + Errorf(a.t, err, msg, args...) +} + +// Exactly asserts that two objects are equal in value and type. +// +// a.Exactly(int32(123), int64(123)) +func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + Exactly(a.t, expected, actual, msgAndArgs...) +} + +// Exactlyf asserts that two objects are equal in value and type. +// +// a.Exactlyf(int32(123, "error message %s", "formatted"), int64(123)) +func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) { + Exactlyf(a.t, expected, actual, msg, args...) +} + +// Fail reports a failure through +func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) { + Fail(a.t, failureMessage, msgAndArgs...) +} + +// FailNow fails test +func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) { + FailNow(a.t, failureMessage, msgAndArgs...) +} + +// FailNowf fails test +func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) { + FailNowf(a.t, failureMessage, msg, args...) +} + +// Failf reports a failure through +func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) { + Failf(a.t, failureMessage, msg, args...) +} + +// False asserts that the specified value is false. +// +// a.False(myBool) +func (a *Assertions) False(value bool, msgAndArgs ...interface{}) { + False(a.t, value, msgAndArgs...) +} + +// Falsef asserts that the specified value is false. +// +// a.Falsef(myBool, "error message %s", "formatted") +func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) { + Falsef(a.t, value, msg, args...) +} + +// FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. +func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) { + FileExists(a.t, path, msgAndArgs...) +} + +// FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. +func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) { + FileExistsf(a.t, path, msg, args...) +} + +// HTTPBodyContains asserts that a specified handler returns a +// body that contains a string. +// +// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { + HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...) +} + +// HTTPBodyContainsf asserts that a specified handler returns a +// body that contains a string. +// +// a.HTTPBodyContainsf(myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { + HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...) +} + +// HTTPBodyNotContains asserts that a specified handler returns a +// body that does not contain a string. +// +// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { + HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...) +} + +// HTTPBodyNotContainsf asserts that a specified handler returns a +// body that does not contain a string. +// +// a.HTTPBodyNotContainsf(myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { + HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...) +} + +// HTTPError asserts that a specified handler returns an error status code. +// +// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { + HTTPError(a.t, handler, method, url, values, msgAndArgs...) +} + +// HTTPErrorf asserts that a specified handler returns an error status code. +// +// a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). +func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { + HTTPErrorf(a.t, handler, method, url, values, msg, args...) +} + +// HTTPRedirect asserts that a specified handler returns a redirect status code. +// +// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { + HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...) +} + +// HTTPRedirectf asserts that a specified handler returns a redirect status code. +// +// a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). +func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { + HTTPRedirectf(a.t, handler, method, url, values, msg, args...) +} + +// HTTPSuccess asserts that a specified handler returns a success status code. +// +// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil) +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { + HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...) +} + +// HTTPSuccessf asserts that a specified handler returns a success status code. +// +// a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { + HTTPSuccessf(a.t, handler, method, url, values, msg, args...) +} + +// Implements asserts that an object is implemented by the specified interface. +// +// a.Implements((*MyInterface)(nil), new(MyObject)) +func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { + Implements(a.t, interfaceObject, object, msgAndArgs...) +} + +// Implementsf asserts that an object is implemented by the specified interface. +// +// a.Implementsf((*MyInterface, "error message %s", "formatted")(nil), new(MyObject)) +func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { + Implementsf(a.t, interfaceObject, object, msg, args...) +} + +// InDelta asserts that the two numerals are within delta of each other. +// +// a.InDelta(math.Pi, (22 / 7.0), 0.01) +func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { + InDelta(a.t, expected, actual, delta, msgAndArgs...) +} + +// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. +func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { + InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...) +} + +// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. +func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { + InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...) +} + +// InDeltaSlice is the same as InDelta, except it compares two slices. +func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { + InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...) +} + +// InDeltaSlicef is the same as InDelta, except it compares two slices. +func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { + InDeltaSlicef(a.t, expected, actual, delta, msg, args...) +} + +// InDeltaf asserts that the two numerals are within delta of each other. +// +// a.InDeltaf(math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01) +func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { + InDeltaf(a.t, expected, actual, delta, msg, args...) +} + +// InEpsilon asserts that expected and actual have a relative error less than epsilon +func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { + InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) +} + +// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. +func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { + InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...) +} + +// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. +func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { + InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...) +} + +// InEpsilonf asserts that expected and actual have a relative error less than epsilon +func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { + InEpsilonf(a.t, expected, actual, epsilon, msg, args...) +} + +// IsType asserts that the specified objects are of the same type. +func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { + IsType(a.t, expectedType, object, msgAndArgs...) +} + +// IsTypef asserts that the specified objects are of the same type. +func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) { + IsTypef(a.t, expectedType, object, msg, args...) +} + +// JSONEq asserts that two JSON strings are equivalent. +// +// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) +func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) { + JSONEq(a.t, expected, actual, msgAndArgs...) +} + +// JSONEqf asserts that two JSON strings are equivalent. +// +// a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") +func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) { + JSONEqf(a.t, expected, actual, msg, args...) +} + +// Len asserts that the specified object has specific length. +// Len also fails if the object has a type that len() not accept. +// +// a.Len(mySlice, 3) +func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) { + Len(a.t, object, length, msgAndArgs...) +} + +// Lenf asserts that the specified object has specific length. +// Lenf also fails if the object has a type that len() not accept. +// +// a.Lenf(mySlice, 3, "error message %s", "formatted") +func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) { + Lenf(a.t, object, length, msg, args...) +} + +// Nil asserts that the specified object is nil. +// +// a.Nil(err) +func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) { + Nil(a.t, object, msgAndArgs...) +} + +// Nilf asserts that the specified object is nil. +// +// a.Nilf(err, "error message %s", "formatted") +func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) { + Nilf(a.t, object, msg, args...) +} + +// NoError asserts that a function returned no error (i.e. `nil`). +// +// actualObj, err := SomeFunction() +// if a.NoError(err) { +// assert.Equal(t, expectedObj, actualObj) +// } +func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) { + NoError(a.t, err, msgAndArgs...) +} + +// NoErrorf asserts that a function returned no error (i.e. `nil`). +// +// actualObj, err := SomeFunction() +// if a.NoErrorf(err, "error message %s", "formatted") { +// assert.Equal(t, expectedObj, actualObj) +// } +func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) { + NoErrorf(a.t, err, msg, args...) +} + +// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the +// specified substring or element. +// +// a.NotContains("Hello World", "Earth") +// a.NotContains(["Hello", "World"], "Earth") +// a.NotContains({"Hello": "World"}, "Earth") +func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) { + NotContains(a.t, s, contains, msgAndArgs...) +} + +// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the +// specified substring or element. +// +// a.NotContainsf("Hello World", "Earth", "error message %s", "formatted") +// a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted") +// a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted") +func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) { + NotContainsf(a.t, s, contains, msg, args...) +} + +// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// if a.NotEmpty(obj) { +// assert.Equal(t, "two", obj[1]) +// } +func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) { + NotEmpty(a.t, object, msgAndArgs...) +} + +// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// if a.NotEmptyf(obj, "error message %s", "formatted") { +// assert.Equal(t, "two", obj[1]) +// } +func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) { + NotEmptyf(a.t, object, msg, args...) +} + +// NotEqual asserts that the specified values are NOT equal. +// +// a.NotEqual(obj1, obj2) +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). +func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + NotEqual(a.t, expected, actual, msgAndArgs...) +} + +// NotEqualf asserts that the specified values are NOT equal. +// +// a.NotEqualf(obj1, obj2, "error message %s", "formatted") +// +// Pointer variable equality is determined based on the equality of the +// referenced values (as opposed to the memory addresses). +func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) { + NotEqualf(a.t, expected, actual, msg, args...) +} + +// NotNil asserts that the specified object is not nil. +// +// a.NotNil(err) +func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) { + NotNil(a.t, object, msgAndArgs...) +} + +// NotNilf asserts that the specified object is not nil. +// +// a.NotNilf(err, "error message %s", "formatted") +func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) { + NotNilf(a.t, object, msg, args...) +} + +// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. +// +// a.NotPanics(func(){ RemainCalm() }) +func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) { + NotPanics(a.t, f, msgAndArgs...) +} + +// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. +// +// a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted") +func (a *Assertions) NotPanicsf(f assert.PanicTestFunc, msg string, args ...interface{}) { + NotPanicsf(a.t, f, msg, args...) +} + +// NotRegexp asserts that a specified regexp does not match a string. +// +// a.NotRegexp(regexp.MustCompile("starts"), "it's starting") +// a.NotRegexp("^start", "it's not starting") +func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { + NotRegexp(a.t, rx, str, msgAndArgs...) +} + +// NotRegexpf asserts that a specified regexp does not match a string. +// +// a.NotRegexpf(regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting") +// a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted") +func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) { + NotRegexpf(a.t, rx, str, msg, args...) +} + +// NotSubset asserts that the specified list(array, slice...) contains not all +// elements given in the specified subset(array, slice...). +// +// a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") +func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) { + NotSubset(a.t, list, subset, msgAndArgs...) +} + +// NotSubsetf asserts that the specified list(array, slice...) contains not all +// elements given in the specified subset(array, slice...). +// +// a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") +func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) { + NotSubsetf(a.t, list, subset, msg, args...) +} + +// NotZero asserts that i is not the zero value for its type. +func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) { + NotZero(a.t, i, msgAndArgs...) +} + +// NotZerof asserts that i is not the zero value for its type. +func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) { + NotZerof(a.t, i, msg, args...) +} + +// Panics asserts that the code inside the specified PanicTestFunc panics. +// +// a.Panics(func(){ GoCrazy() }) +func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) { + Panics(a.t, f, msgAndArgs...) +} + +// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that +// the recovered panic value equals the expected panic value. +// +// a.PanicsWithValue("crazy error", func(){ GoCrazy() }) +func (a *Assertions) PanicsWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { + PanicsWithValue(a.t, expected, f, msgAndArgs...) +} + +// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that +// the recovered panic value equals the expected panic value. +// +// a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted") +func (a *Assertions) PanicsWithValuef(expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { + PanicsWithValuef(a.t, expected, f, msg, args...) +} + +// Panicsf asserts that the code inside the specified PanicTestFunc panics. +// +// a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted") +func (a *Assertions) Panicsf(f assert.PanicTestFunc, msg string, args ...interface{}) { + Panicsf(a.t, f, msg, args...) +} + +// Regexp asserts that a specified regexp matches a string. +// +// a.Regexp(regexp.MustCompile("start"), "it's starting") +// a.Regexp("start...$", "it's not starting") +func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { + Regexp(a.t, rx, str, msgAndArgs...) +} + +// Regexpf asserts that a specified regexp matches a string. +// +// a.Regexpf(regexp.MustCompile("start", "error message %s", "formatted"), "it's starting") +// a.Regexpf("start...$", "it's not starting", "error message %s", "formatted") +func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) { + Regexpf(a.t, rx, str, msg, args...) +} + +// Subset asserts that the specified list(array, slice...) contains all +// elements given in the specified subset(array, slice...). +// +// a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") +func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) { + Subset(a.t, list, subset, msgAndArgs...) +} + +// Subsetf asserts that the specified list(array, slice...) contains all +// elements given in the specified subset(array, slice...). +// +// a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") +func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) { + Subsetf(a.t, list, subset, msg, args...) +} + +// True asserts that the specified value is true. +// +// a.True(myBool) +func (a *Assertions) True(value bool, msgAndArgs ...interface{}) { + True(a.t, value, msgAndArgs...) +} + +// Truef asserts that the specified value is true. +// +// a.Truef(myBool, "error message %s", "formatted") +func (a *Assertions) Truef(value bool, msg string, args ...interface{}) { + Truef(a.t, value, msg, args...) +} + +// WithinDuration asserts that the two times are within duration delta of each other. +// +// a.WithinDuration(time.Now(), time.Now(), 10*time.Second) +func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { + WithinDuration(a.t, expected, actual, delta, msgAndArgs...) +} + +// WithinDurationf asserts that the two times are within duration delta of each other. +// +// a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") +func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { + WithinDurationf(a.t, expected, actual, delta, msg, args...) +} + +// Zero asserts that i is the zero value for its type. +func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) { + Zero(a.t, i, msgAndArgs...) +} + +// Zerof asserts that i is the zero value for its type. +func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) { + Zerof(a.t, i, msg, args...) +} diff --git a/vendor/github.com/stretchr/testify/require/requirements.go b/vendor/github.com/stretchr/testify/require/requirements.go new file mode 100644 index 000000000..e404f016d --- /dev/null +++ b/vendor/github.com/stretchr/testify/require/requirements.go @@ -0,0 +1,9 @@ +package require + +// TestingT is an interface wrapper around *testing.T +type TestingT interface { + Errorf(format string, args ...interface{}) + FailNow() +} + +//go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl -include-format-funcs