Browse Source

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
release/v1.9
Lunny Xiao 3 years ago
committed by GitHub
parent
commit
d578b71d61
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      Gopkg.lock
  2. 2
      cmd/admin.go
  3. 2
      cmd/hook.go
  4. 2
      cmd/serv.go
  5. 2
      integrations/api_releases_test.go
  6. 2
      integrations/git_helper_for_declarative_test.go
  7. 2
      integrations/git_test.go
  8. 2
      integrations/ssh_key_test.go
  9. 2
      models/action.go
  10. 2
      models/action_test.go
  11. 2
      models/git_diff.go
  12. 2
      models/gpg_key.go
  13. 2
      models/graph.go
  14. 2
      models/graph_test.go
  15. 2
      models/issue_comment.go
  16. 2
      models/migrations/v28.go
  17. 2
      models/migrations/v39.go
  18. 2
      models/migrations/v82.go
  19. 2
      models/pull.go
  20. 4
      models/release.go
  21. 2
      models/release_test.go
  22. 2
      models/repo.go
  23. 2
      models/repo_branch.go
  24. 2
      models/repo_indexer.go
  25. 2
      models/repo_mirror.go
  26. 2
      models/repo_tag.go
  27. 2
      models/status.go
  28. 2
      models/update.go
  29. 2
      models/update_test.go
  30. 2
      models/user.go
  31. 3
      models/webhook_dingtalk.go
  32. 2
      models/webhook_discord.go
  33. 2
      models/webhook_slack.go
  34. 7
      models/wiki.go
  35. 3
      modules/base/tool.go
  36. 3
      modules/context/api.go
  37. 2
      modules/context/repo.go
  38. 3
      modules/git/README.md
  39. 0
      modules/git/blob.go
  40. 80
      modules/git/blob_test.go
  41. 0
      modules/git/cache.go
  42. 4
      modules/git/command.go
  43. 41
      modules/git/command_test.go
  44. 0
      modules/git/commit.go
  45. 0
      modules/git/commit_archive.go
  46. 0
      modules/git/commit_info.go
  47. 117
      modules/git/commit_info_test.go
  48. 38
      modules/git/commit_test.go
  49. 0
      modules/git/error.go
  50. 0
      modules/git/git.go
  51. 13
      modules/git/hook.go
  52. 0
      modules/git/parse.go
  53. 58
      modules/git/parse_test.go
  54. 0
      modules/git/ref.go
  55. 0
      modules/git/repo.go
  56. 0
      modules/git/repo_blame.go
  57. 0
      modules/git/repo_blob.go
  58. 66
      modules/git/repo_blob_test.go
  59. 0
      modules/git/repo_branch.go
  60. 39
      modules/git/repo_branch_test.go
  61. 4
      modules/git/repo_commit.go
  62. 59
      modules/git/repo_commit_test.go
  63. 2
      modules/git/repo_hook.go
  64. 0
      modules/git/repo_object.go
  65. 0
      modules/git/repo_pull.go
  66. 30
      modules/git/repo_pull_test.go
  67. 0
      modules/git/repo_ref.go
  68. 49
      modules/git/repo_ref_test.go
  69. 0
      modules/git/repo_tag.go
  70. 44
      modules/git/repo_tag_test.go
  71. 26
      modules/git/repo_test.go
  72. 2
      modules/git/repo_tree.go
  73. 0
      modules/git/sha1.go
  74. 0
      modules/git/signature.go
  75. 0
      modules/git/submodule.go
  76. 29
      modules/git/submodule_test.go
  77. 0
      modules/git/tag.go
  78. 1
      modules/git/tests/repos/repo1_bare/HEAD
  79. 4
      modules/git/tests/repos/repo1_bare/config
  80. 1
      modules/git/tests/repos/repo1_bare/description
  81. 15
      modules/git/tests/repos/repo1_bare/hooks/applypatch-msg.sample
  82. 24
      modules/git/tests/repos/repo1_bare/hooks/commit-msg.sample
  83. 8
      modules/git/tests/repos/repo1_bare/hooks/post-update.sample
  84. 14
      modules/git/tests/repos/repo1_bare/hooks/pre-applypatch.sample
  85. 49
      modules/git/tests/repos/repo1_bare/hooks/pre-commit.sample
  86. 53
      modules/git/tests/repos/repo1_bare/hooks/pre-push.sample
  87. 169
      modules/git/tests/repos/repo1_bare/hooks/pre-rebase.sample
  88. 24
      modules/git/tests/repos/repo1_bare/hooks/pre-receive.sample
  89. 36
      modules/git/tests/repos/repo1_bare/hooks/prepare-commit-msg.sample
  90. 128
      modules/git/tests/repos/repo1_bare/hooks/update.sample
  91. 6
      modules/git/tests/repos/repo1_bare/info/exclude
  92. BIN
      modules/git/tests/repos/repo1_bare/objects/0b/9f291245f6c596fd30bee925fe94fe0cbadd60
  93. BIN
      modules/git/tests/repos/repo1_bare/objects/11/93ff46343f4f6a0522e2b28b871e905178c1f0
  94. BIN
      modules/git/tests/repos/repo1_bare/objects/15/3f451b9ee7fa1da317ab17a127e9fd9d384310
  95. BIN
      modules/git/tests/repos/repo1_bare/objects/18/4d49c75a0b202b1d2ea2fcb5861c329321fcd6
  96. BIN
      modules/git/tests/repos/repo1_bare/objects/21/6bf54c2f2e2916b830ebe09e8c58a6ed52d86b
  97. 1
      modules/git/tests/repos/repo1_bare/objects/28/39944139e0de9737a044f78b0e4b40d989a9e3
  98. BIN
      modules/git/tests/repos/repo1_bare/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e
  99. BIN
      modules/git/tests/repos/repo1_bare/objects/30/4c56b3bef33d0afeb8515ee803c839daf30ab8
  100. BIN
      modules/git/tests/repos/repo1_bare/objects/34/d1da713bf7de1c535e1d7d3ca985afd84bc7e5

19
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",

2
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"

2
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"

2
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"

2
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"

2
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"

2
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"
)

2
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"
)

2
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"

2
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"

2
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"

2
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"

2
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"
)

2
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) {

2
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"

2
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"

2
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"

2
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"
)

2
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"

4
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"
)

2
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"
)

2
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"

2
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"

2
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"

2
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"

2
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

2
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"

2
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"
)

2
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"
)

2
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"

3
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"
)

2
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"
)

2
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"
)

7
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 (

3
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"

3
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"
)

2
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"

3
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.

0
vendor/code.gitea.io/git/blob.go → modules/git/blob.go

80
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)
}
}
}

0
vendor/code.gitea.io/git/cache.go → modules/git/cache.go

4
vendor/code.gitea.io/git/command.go → 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)

41
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)
}
}
}
}

0
vendor/code.gitea.io/git/commit.go → modules/git/commit.go

0
vendor/code.gitea.io/git/commit_archive.go → modules/git/commit_archive.go

0
vendor/code.gitea.io/git/commit_info.go → modules/git/commit_info.go

117
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)
}
}
})
}
}

38
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: ]")
}
}

0
vendor/code.gitea.io/git/error.go → modules/git/error.go

0
vendor/code.gitea.io/git/git.go → modules/git/git.go

13
vendor/code.gitea.io/git/hook.go → 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.

0
vendor/code.gitea.io/git/parse.go → modules/git/parse.go

58
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)
}
}

0
vendor/code.gitea.io/git/ref.go → modules/git/ref.go

0
vendor/code.gitea.io/git/repo.go → modules/git/repo.go

0
vendor/code.gitea.io/git/repo_blame.go → modules/git/repo_blame.go

0
vendor/code.gitea.io/git/repo_blob.go → modules/git/repo_blob.go

66
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())
}

0
vendor/code.gitea.io/git/repo_branch.go → modules/git/repo_branch.go

39
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)
}
}
}

4
vendor/code.gitea.io/git/repo_commit.go → 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)

59
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: ]")
}

2
vendor/code.gitea.io/git/repo_hook.go → 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)
}

0
vendor/code.gitea.io/git/repo_object.go → modules/git/repo_object.go

0
vendor/code.gitea.io/git/repo_pull.go → modules/git/repo_pull.go

30
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")
}

0
vendor/code.gitea.io/git/repo_ref.go → modules/git/repo_ref.go

49
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())
}
}

0
vendor/code.gitea.io/git/repo_tag.go → modules/git/repo_tag.go

44
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)
}

26
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)
}

2
vendor/code.gitea.io/git/repo_tree.go → 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]

0
vendor/code.gitea.io/git/sha1.go → modules/git/sha1.go

0
vendor/code.gitea.io/git/signature.go → modules/git/signature.go

0
vendor/code.gitea.io/git/submodule.go → modules/git/submodule.go

29
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))
}
}

0
vendor/code.gitea.io/git/tag.go → modules/git/tag.go

1
modules/git/tests/repos/repo1_bare/HEAD

@ -0,0 +1 @@
ref: refs/heads/master

4
modules/git/tests/repos/repo1_bare/config

@ -0,0 +1,4 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true

1
modules/git/tests/repos/repo1_bare/description

@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.

15
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+"$@"}
:

24
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
}

8
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

14
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+"$@"}
: