From 530f3618a8f4c7d9c8d3981548112439b22e09e7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 16 Dec 2024 17:50:57 -0600 Subject: update to libgit2 version 1.8.4. dump old github and vendor stuff go install go.wit.com/apps/go-clone@latest go install go.wit.com/apps/go-mod-clean@latest go-clone --recusive go.wit.com/lib/git2go Signed-off-by: Jeff Carr --- .github/workflows/backport.yml | 54 ----------------- .github/workflows/ci.yml | 130 ----------------------------------------- .github/workflows/tag.yml | 28 --------- .gitignore | 2 + .gitmodules | 3 - Build_system_dynamic.go | 3 - Makefile | 5 +- README.md | 12 ++++ go.mod | 9 --- go.sum | 18 ------ rebase.go | 2 +- rebase_test.go | 104 ++++++++++++++++----------------- remote.go | 7 ++- vendor/libgit2 | 1 - wrapper.c | 2 +- 15 files changed, 77 insertions(+), 303 deletions(-) delete mode 100644 .github/workflows/backport.yml delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/tag.yml delete mode 100644 .gitmodules delete mode 100644 go.mod delete mode 100644 go.sum delete mode 160000 vendor/libgit2 diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml deleted file mode 100644 index b3fbb4e..0000000 --- a/.github/workflows/backport.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Backport to older releases -on: - push: - branches: - - main - -jobs: - - backport: - name: Backport change to branch ${{ matrix.branch }} - continue-on-error: true - strategy: - fail-fast: false - matrix: - branch: [ 'release-1.3', 'release-1.2', 'release-1.1', 'release-1.0', 'release-0.28', 'release-0.27' ] - - runs-on: ubuntu-20.04 - - steps: - - name: Check out code - uses: actions/checkout@v1 - with: - fetch-depth: 0 - - name: Create a cherry-pick PR - run: | - if ! git diff --quiet HEAD^ HEAD -- vendor/libgit2; then - echo '::warning::Skipping cherry-pick since it is a vendored libgit2 bump' - exit 0 - fi - - BRANCH_NAME="cherry-pick-${{ github.run_id }}-${{ matrix.branch }}" - - # Setup usernames and authentication - git config --global user.name "${{ github.actor }}" - git config --global user.email "${{ github.actor }}@users.noreply.github.com" - cat <<- EOF > $HOME/.netrc - machine github.com - login ${{ github.actor }} - password ${{ secrets.GITHUB_TOKEN }} - machine api.github.com - login ${{ github.actor }} - password ${{ secrets.GITHUB_TOKEN }} - EOF - chmod 600 $HOME/.netrc - - # Create the cherry-pick commit and create the PR for it. - git checkout "${{ matrix.branch }}" - git switch -c "${BRANCH_NAME}" - git cherry-pick -x "${{ github.sha }}" - git push --set-upstream origin "${BRANCH_NAME}" - GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" gh pr create \ - --base "${{ matrix.branch }}" \ - --title "$(git --no-pager show --format="%s" --no-patch HEAD)" \ - --body "$(git --no-pager show --format="%b" --no-patch HEAD)" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 4c884fe..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,130 +0,0 @@ -name: git2go CI -on: - pull_request: - push: - branches: - - main - - release-* - - v* - -jobs: - - build-static: - strategy: - fail-fast: false - matrix: - go: [ '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17' ] - name: Go ${{ matrix.go }} - - runs-on: ubuntu-20.04 - - steps: - - name: Set up Go - uses: actions/setup-go@v1 - with: - go-version: ${{ matrix.go }} - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - name: Build - run: | - git submodule update --init - sudo apt-get install -y --no-install-recommends libssh2-1-dev - make build-libgit2-static - - name: Test - run: make TEST_ARGS=-test.v test-static - - build-dynamic: - strategy: - fail-fast: false - name: Go (dynamic) - - runs-on: ubuntu-20.04 - - steps: - - name: Set up Go - uses: actions/setup-go@v1 - with: - go-version: '1.17' - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - name: Build - run: | - git submodule update --init - sudo apt-get install -y --no-install-recommends libssh2-1-dev - make build-libgit2-dynamic - - name: Test - run: make TEST_ARGS=-test.v test-dynamic - - build-system-dynamic: - strategy: - fail-fast: false - matrix: - libgit2: - - 'v1.5.0' - name: Go (system-wide, dynamic) - - runs-on: ubuntu-20.04 - - steps: - - name: Set up Go - uses: actions/setup-go@v1 - with: - go-version: '1.17' - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - name: Build libgit2 ${{ matrix.libgit2 }} - run: | - git submodule update --init - sudo apt-get install -y --no-install-recommends libssh2-1-dev - sudo env BUILD_LIBGIT_REF=${{ matrix.libgit2 }} ./script/build-libgit2.sh --dynamic --system - - name: Test - run: make TEST_ARGS=-test.v test - - build-system-static: - strategy: - fail-fast: false - name: Go (system-wide, static) - - runs-on: ubuntu-20.04 - - steps: - - name: Set up Go - uses: actions/setup-go@v1 - with: - go-version: '1.17' - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - name: Build libgit2 - run: | - git submodule update --init - sudo apt-get install -y --no-install-recommends libssh2-1-dev - sudo ./script/build-libgit2.sh --static --system - - name: Test - run: go test --count=1 --tags "static,system_libgit2" ./... - - check-generate: - name: Check generated files were not modified - runs-on: ubuntu-20.04 - steps: - - name: Set up Go - uses: actions/setup-go@v1 - with: - go-version: '1.17' - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: Install libgit2 build dependencies - run: | - git submodule update --init - sudo apt-get install -y --no-install-recommends libssh2-1-dev - go install golang.org/x/tools/cmd/stringer@latest - - name: Generate files - run: | - export PATH=$(go env GOPATH)/bin:$PATH - make generate - - name: Check nothing changed - run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml deleted file mode 100644 index d939528..0000000 --- a/.github/workflows/tag.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Tag new releases -on: - push: - branches: - - main - - release-* - -jobs: - - tag-release: - name: Bump tag in ${{ github.ref }} - - runs-on: ubuntu-20.04 - - steps: - - name: Check out code - uses: actions/checkout@v1 - with: - fetch-depth: 0 - - name: Bump version and push tag - id: bump-version - uses: anothrNick/github-tag-action@43ed073f5c1445ca8b80d920ce2f8fa550ae4e8d - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - WITH_V: true - DEFAULT_BUMP: patch - TAG_CONTEXT: branch - RELEASE_BRANCHES: .* diff --git a/.gitignore b/.gitignore index 713781b..8b95a22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /static-build/ /dynamic-build/ + +go.* diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8eb5872..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "vendor/libgit2"] - path = vendor/libgit2 - url = https://github.com/libgit2/libgit2 diff --git a/Build_system_dynamic.go b/Build_system_dynamic.go index bc423b5..646bf24 100644 --- a/Build_system_dynamic.go +++ b/Build_system_dynamic.go @@ -8,8 +8,5 @@ package git #cgo CFLAGS: -DLIBGIT2_DYNAMIC #include -#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5 -# error "Invalid libgit2 version; this git2go supports libgit2 between v1.5.0 and v1.5.0" -#endif */ import "C" diff --git a/Makefile b/Makefile index 71c5ee0..406cfc2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ TEST_ARGS ?= --count=1 -default: test +default: goimports test +goimports: + goimports -w *.go generate: static-build/install/lib/libgit2.a go generate --tags "static" ./... @@ -10,6 +12,7 @@ generate: static-build/install/lib/libgit2.a # ============== # This uses whatever version of libgit2 can be found in the system. test: + go-mod-clean # go install go.wit.com/apps/go-mod-clean@latest go run script/check-MakeGitError-thread-lock.go go test $(TEST_ARGS) ./... diff --git a/README.md b/README.md index 2816590..b825597 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,18 @@ git2go Go bindings for [libgit2](http://libgit2.github.com/). +### Updated 2024/12/16 + +* This package is updated to work against libgit2 version 1.8 on Debian sid +* There is one line commented out which needs to be fixed in remote.go +* some of the tests seem to run + +```sh +go install go.wit.com/apps/go-clone@latest +go install go.wit.com/apps/go-mod-clean@latest +go-clone --recusive go.wit.com/lib/git2go +``` + ### Which Go version to use Due to the fact that Go 1.11 module versions have semantic meaning and don't necessarily align with libgit2's release schedule, please consult the following table for a mapping between libgit2 and git2go module versions: diff --git a/go.mod b/go.mod deleted file mode 100644 index 3735628..0000000 --- a/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/libgit2/git2go/v34 - -go 1.13 - -require ( - github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 - github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 0d6ad9b..0000000 --- a/go.sum +++ /dev/null @@ -1,18 +0,0 @@ -github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 h1:ra2OtmuW0AE5csawV4YXMNGNQQXvLRps3z2Z59OPO+I= -github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4/go.mod h1:UBYPn8k0D56RtnR8RFQMjmh4KrZzWJ5o7Z9SYjossQ8= -github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= -github.com/cloudflare/circl v1.1.0 h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GKY= -github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= -github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= -github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw= -golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/rebase.go b/rebase.go index b9c94fd..a147429 100644 --- a/rebase.go +++ b/rebase.go @@ -479,7 +479,7 @@ func (r *Rebase) Free() { } func newRebaseFromC(ptr *C.git_rebase, repo *Repository, opts *C.git_rebase_options) *Rebase { - rebase := &Rebase{ptr: ptr, r: repo, options: opts} + rebase := &Rebase{ptr: ptr, r: repo, options: opts} runtime.SetFinalizer(rebase, (*Rebase).Free) return rebase } diff --git a/rebase_test.go b/rebase_test.go index efe93cf..9c1b85e 100644 --- a/rebase_test.go +++ b/rebase_test.go @@ -19,73 +19,73 @@ func TestRebaseInMemoryWithConflict(t *testing.T) { defer cleanupTestRepo(t, repo) seedTestRepo(t, repo) - // Create two branches with common history, where both modify "common-file" - // in a conflicting way. - _, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{}) - checkFatal(t, err) + // Create two branches with common history, where both modify "common-file" + // in a conflicting way. + _, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{}) + checkFatal(t, err) checkFatal(t, createBranch(repo, "branch-a")) checkFatal(t, createBranch(repo, "branch-b")) checkFatal(t, repo.SetHead("refs/heads/branch-a")) - _, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{}) - checkFatal(t, err) + _, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{}) + checkFatal(t, err) checkFatal(t, repo.SetHead("refs/heads/branch-b")) - _, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{}) - checkFatal(t, err) + _, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{}) + checkFatal(t, err) branchA, err := repo.LookupBranch("branch-a", BranchLocal) - checkFatal(t, err) + checkFatal(t, err) onto, err := repo.AnnotatedCommitFromRef(branchA.Reference) - checkFatal(t, err) + checkFatal(t, err) - // We then rebase "branch-b" onto "branch-a" in-memory, which should result - // in a conflict. - rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1}) - checkFatal(t, err) + // We then rebase "branch-b" onto "branch-a" in-memory, which should result + // in a conflict. + rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1}) + checkFatal(t, err) - _, err = rebase.Next() + _, err = rebase.Next() checkFatal(t, err) - index, err := rebase.InmemoryIndex() + index, err := rebase.InmemoryIndex() checkFatal(t, err) - // We simply resolve the conflict and commit the rebase. - if !index.HasConflicts() { - t.Fatal("expected index to have conflicts") - } - - conflict, err := index.Conflict("common-file") - checkFatal(t, err) - - resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents")) - checkFatal(t, err) - - resolvedEntry := *conflict.Our - resolvedEntry.Id = resolvedBlobID - checkFatal(t, index.Add(&resolvedEntry)) - checkFatal(t, index.RemoveConflict("common-file")) - - var commitID Oid - checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message")) - checkFatal(t, rebase.Finish()) - - // And then assert that we can look up the new merge commit, and that the - // "common-file" has the expected contents. - commit, err := repo.LookupCommit(&commitID) - checkFatal(t, err) - if commit.Message() != "rebased message" { - t.Fatalf("unexpected commit message %q", commit.Message()) - } - - tree, err := commit.Tree() - checkFatal(t, err) - - blob, err := repo.LookupBlob(tree.EntryByName("common-file").Id) - checkFatal(t, err) - if string(blob.Contents()) != "resolved contents" { - t.Fatalf("unexpected resolved blob contents %q", string(blob.Contents())) - } + // We simply resolve the conflict and commit the rebase. + if !index.HasConflicts() { + t.Fatal("expected index to have conflicts") + } + + conflict, err := index.Conflict("common-file") + checkFatal(t, err) + + resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents")) + checkFatal(t, err) + + resolvedEntry := *conflict.Our + resolvedEntry.Id = resolvedBlobID + checkFatal(t, index.Add(&resolvedEntry)) + checkFatal(t, index.RemoveConflict("common-file")) + + var commitID Oid + checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message")) + checkFatal(t, rebase.Finish()) + + // And then assert that we can look up the new merge commit, and that the + // "common-file" has the expected contents. + commit, err := repo.LookupCommit(&commitID) + checkFatal(t, err) + if commit.Message() != "rebased message" { + t.Fatalf("unexpected commit message %q", commit.Message()) + } + + tree, err := commit.Tree() + checkFatal(t, err) + + blob, err := repo.LookupBlob(tree.EntryByName("common-file").Id) + checkFatal(t, err) + if string(blob.Contents()) != "resolved contents" { + t.Fatalf("unexpected resolved blob contents %q", string(blob.Contents())) + } } func TestRebaseAbort(t *testing.T) { diff --git a/remote.go b/remote.go index a294ca2..7a816ac 100644 --- a/remote.go +++ b/remote.go @@ -12,6 +12,7 @@ import "C" import ( "crypto/x509" "errors" + "fmt" "reflect" "runtime" "strings" @@ -685,7 +686,7 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) { return remote, nil } -//CreateWithOptions Creates a repository object with extended options. +// CreateWithOptions Creates a repository object with extended options. func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) { remote := &Remote{repo: c.repo} @@ -983,7 +984,9 @@ func populateFetchOptions(copts *C.git_fetch_options, opts *FetchOptions, errorT } populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget) copts.prune = C.git_fetch_prune_t(opts.Prune) - copts.update_fetchhead = cbool(opts.UpdateFetchhead) + fmt.Println("populateFetchOptions() is broken. fixme!") + // fix this line: ./remote.go:988:27: cannot use cbool(opts.UpdateFetchhead) (value of type _Ctype_int) as _Ctype_uint value in assignment + // copts.update_fetchhead = cbool(opts.UpdateFetchhead) copts.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags) copts.custom_headers = C.git_strarray{ diff --git a/vendor/libgit2 b/vendor/libgit2 deleted file mode 160000 index fbea439..0000000 --- a/vendor/libgit2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fbea439d4b6fc91c6b619d01b85ab3b7746e4c19 diff --git a/wrapper.c b/wrapper.c index e999136..738cadf 100644 --- a/wrapper.c +++ b/wrapper.c @@ -104,7 +104,7 @@ static int set_callback_error(char *error_message, int ret) { if (error_message != NULL) { if (ret < 0) - git_error_set_str(GIT_ERROR_CALLBACK, error_message); + giterr_set_str(GIT_ERROR_CALLBACK, error_message); free(error_message); } return ret; -- cgit v1.2.3