From fc6eaf36388841b16ff004e1d48e887d3f9613dc Mon Sep 17 00:00:00 2001 From: michael boulton <61595820+mbfr@users.noreply.github.com> Date: Fri, 14 Aug 2020 19:19:21 +0100 Subject: [PATCH 1/4] Fix null pointer dereference in status.ByIndex (#628) `git_status_byindex` can return a null pointer if there is no statuses. --- status.go | 4 ++++ status_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/status.go b/status.go index e37a96d..3923e1a 100644 --- a/status.go +++ b/status.go @@ -6,6 +6,7 @@ package git import "C" import ( + "errors" "runtime" "unsafe" ) @@ -86,6 +87,9 @@ func (statusList *StatusList) ByIndex(index int) (StatusEntry, error) { return StatusEntry{}, ErrInvalid } ptr := C.git_status_byindex(statusList.ptr, C.size_t(index)) + if ptr == nil { + return StatusEntry{}, errors.New("index out of Bounds") + } entry := statusEntryFromC(ptr) runtime.KeepAlive(statusList) diff --git a/status_test.go b/status_test.go index 17ed94f..d5cd530 100644 --- a/status_test.go +++ b/status_test.go @@ -61,3 +61,31 @@ func TestStatusList(t *testing.T) { t.Fatal("Incorrect entry path: ", entry.IndexToWorkdir.NewFile.Path) } } + +func TestStatusNothing(t *testing.T) { + t.Parallel() + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + seedTestRepo(t, repo) + + opts := &StatusOptions{ + Show: StatusShowIndexAndWorkdir, + Flags: StatusOptIncludeUntracked | StatusOptRenamesHeadToIndex | StatusOptSortCaseSensitively, + } + + statusList, err := repo.StatusList(opts) + checkFatal(t, err) + + entryCount, err := statusList.EntryCount() + checkFatal(t, err) + + if entryCount != 0 { + t.Fatal("expected no statuses in empty repo") + } + + _, err = statusList.ByIndex(0) + if err == nil { + t.Error("expected error getting status by index") + } +} From 53149517592d613935e6bcbcea18f8ddb6bb546e Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 15 Aug 2020 17:19:53 -0700 Subject: [PATCH 2/4] Refresh the GitHub Actions CI (#632) This change: * Builds the library with Go 1.14, too. * Builds the non-legacy tests with Ubuntu Focal (20.04). * Adds testing for system-wide libraries, both static and dynamic versions. * Fixes a typo in the README. --- .github/workflows/ci.yml | 52 +++++++++++++++++++++++++++++++++--- README.md | 2 +- script/build-libgit2.sh | 57 +++++++++++++++++++++++++++------------- 3 files changed, 88 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5472f22..88e6c57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,10 +46,10 @@ jobs: strategy: fail-fast: false matrix: - go: [ '1.11', '1.12', '1.13' ] + go: [ '1.11', '1.12', '1.13', '1.14' ] name: Go ${{ matrix.go }} - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: Set up Go @@ -71,13 +71,13 @@ jobs: fail-fast: false name: Go (dynamic) - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: Set up Go uses: actions/setup-go@v1 with: - go-version: '1.13' + go-version: '1.14' id: go - name: Check out code into the Go module directory uses: actions/checkout@v1 @@ -87,3 +87,47 @@ jobs: make build-libgit2-dynamic - name: Test run: make test-dynamic + + build-system-dynamic: + strategy: + fail-fast: false + name: Go (system-wide, dynamic) + + runs-on: ubuntu-20.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: '1.14' + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: Build libgit2 + run: | + git submodule update --init + sudo ./script/build-libgit2.sh --dynamic --system + - name: Test + run: make 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.14' + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: Build libgit2 + run: | + git submodule update --init + sudo ./script/build-libgit2.sh --static --system + - name: Test + run: go test --count=1 --tags "static,system_libgit2" ./... diff --git a/README.md b/README.md index 05dddec..79a96e9 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The `master` branch follows the tip of libgit2 itself (with some lag) and as suc ### Which branch to send Pull requests to -If there's something version-specific that you'd want to contribute to, you can send them to the `release-${MAJOR}-${MINOR}` branches, which follow libgit2's releases. +If there's something version-specific that you'd want to contribute to, you can send them to the `release-${MAJOR}.${MINOR}` branches, which follow libgit2's releases. Installing ---------- diff --git a/script/build-libgit2.sh b/script/build-libgit2.sh index 7398cd9..98ff78b 100755 --- a/script/build-libgit2.sh +++ b/script/build-libgit2.sh @@ -6,33 +6,54 @@ set -e -if [ "$#" -eq "0" ]; then - echo "Usage: $0 <--dynamic|--static>">&2 +usage() { + echo "Usage: $0 <--dynamic|--static> [--system]">&2 exit 1 +} + +if [ "$#" -eq "0" ]; then + usage fi ROOT="$(cd "$(dirname "$0")/.." && echo "${PWD}")" VENDORED_PATH="${ROOT}/vendor/libgit2" +BUILD_SYSTEM=OFF -case "$1" in - --static) - BUILD_PATH="${ROOT}/static-build" - BUILD_SHARED_LIBS=OFF - ;; +while [ $# -gt 0 ]; do + case "$1" in + --static) + BUILD_PATH="${ROOT}/static-build" + BUILD_SHARED_LIBS=OFF + ;; - --dynamic) - BUILD_PATH="${ROOT}/dynamic-build" - BUILD_SHARED_LIBS=ON - ;; + --dynamic) + BUILD_PATH="${ROOT}/dynamic-build" + BUILD_SHARED_LIBS=ON + ;; - *) - echo "Usage: $0 <--dynamic|--static>">&2 - exit 1 - ;; -esac + --system) + BUILD_SYSTEM=ON + ;; -mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" + *) + usage + ;; + esac + shift +done +if [ -z "${BUILD_SHARED_LIBS}" ]; then + usage +fi + +if [ "${BUILD_SYSTEM}" = "ON" ]; then + BUILD_INSTALL_PREFIX="/usr" +else + BUILD_INSTALL_PREFIX="${BUILD_PATH}/install" + mkdir -p "${BUILD_PATH}/install/lib" +fi + +mkdir -p "${BUILD_PATH}/build" && cd "${BUILD_PATH}/build" && cmake -DTHREADSAFE=ON \ -DBUILD_CLAR=OFF \ @@ -40,7 +61,7 @@ cmake -DTHREADSAFE=ON \ -DREGEX_BACKEND=builtin \ -DCMAKE_C_FLAGS=-fPIC \ -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ + -DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \ -DCMAKE_INSTALL_LIBDIR="lib" \ "${VENDORED_PATH}" && From bbaf9746f96d8b6e7dcd623ae47e18db73840ec8 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 15 Aug 2020 19:27:43 -0700 Subject: [PATCH 3/4] Add two more GitHub Actions workflows This change adds: * `tag.yml`: Creates a new tag every time the master or a release branch is pushed. * `backport.yml`: Creates a cherry-pick in older release branches to keep them up to date with little cost. --- .github/workflows/backport.yml | 53 ++++++++++++++++++++++++++++++++++ .github/workflows/tag.yml | 28 ++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/backport.yml create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 0000000..4337fb1 --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,53 @@ +name: Backport to older releases +on: + push: + branches: + - master + +jobs: + + backport: + strategy: + fail-fast: false + matrix: + branch: [ 'release-0.28', 'release-0.27' ] + name: Backport change to branch ${{ matrix.branch }} + + 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/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..b293274 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,28 @@ +name: Tag new releases +on: + push: + branches: + - master + - 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@9aaabdb5e989894e95288328d8b17a6347217ae3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: patch + TAG_CONTEXT: branch + RELEASE_BRANCHES: .* From 2ac9f4e69bd57a686d15176d199a3c9cc4a6bb91 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sun, 16 Aug 2020 07:27:17 -0700 Subject: [PATCH 4/4] Add two more GitHub Actions workflows (#633) This change adds: * `tag.yml`: Creates a new tag every time the master or a release branch is pushed. * `backport.yml`: Creates a cherry-pick in older release branches to keep them up to date with little cost. --- .github/workflows/backport.yml | 53 ++++++++++++++++++++++++++++++++++ .github/workflows/tag.yml | 28 ++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/backport.yml create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 0000000..4337fb1 --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,53 @@ +name: Backport to older releases +on: + push: + branches: + - master + +jobs: + + backport: + strategy: + fail-fast: false + matrix: + branch: [ 'release-0.28', 'release-0.27' ] + name: Backport change to branch ${{ matrix.branch }} + + 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/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..b293274 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,28 @@ +name: Tag new releases +on: + push: + branches: + - master + - 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@9aaabdb5e989894e95288328d8b17a6347217ae3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: patch + TAG_CONTEXT: branch + RELEASE_BRANCHES: .*