distributable:
  url: https://mirrors.edge.kernel.org/pub/software/scm/git/git-{{version}}.tar.xz
  strip-components: 1

versions:
  github: git/git/tags

dependencies:
  zlib.net: 1
  gnu.org/gettext: ^0.21
  curl.se: '>=5'
  curl.se/ca-certs: '*'
  perl.org: '*'
  libexpat.github.io: ~2
  pkgx.sh: ^1

runtime:
  env:
    GIT_TEMPLATE_DIR: '{{prefix}}/share/git-core/templates'
    GIT_SSL_CAINFO: ${{deps.curl.se/ca-certs.prefix}}/ssl/cert.pem

build:
  script:
    - mv props/config.mak .

    - ./configure
        --prefix={{ prefix }}
        --with-perl={{ deps.perl.org.prefix }}
        --with-gitconfig=etc/gitconfig

    - make install --jobs {{ hw.concurrency }} NO_TCLTK=1

    - run: |
        make
        make install
      working-directory: contrib/subtree

    - run: |
        make
        mv git-credential-osxkeychain "{{prefix}}"/bin
        make clean
      working-directory: contrib/credential/osxkeychain
      if: darwin

    - run: mv git-subtree "{{prefix}}"/libexec
      working-directory: contrib/subtree

    - run: fix-shebangs.ts bin/* libexec/*
      working-directory: ${{prefix}}

    - run: cp "$SRCROOT"/props/gitconfig "$SRCROOT"/props/gitignore .
      working-directory: ${{prefix}}/etc

    - run: |
        rm bin/git
        cp $SRCROOT/props/git-shim bin/git
      working-directory: ${{prefix}}
  env:
    V: 1
    INSTALL_STRIP: -s

test:
  # bug in pkgx where it doesn’t auto sync for --provides
  - pkgx --sync

  # check that the templates can be found
  - run: |
      git clone https://github.com/teaxyz/white-paper 2>&1 | tee clone-output.txt
      if grep -q 'warning: templates not found in' clone-output.txt; then
        exit 1
      fi
    working-directory: $(mktemp -d)

  - cd $(mktemp -d)

  - run: |
      touch .DS_Store testfile
      git init
      git add .
      test "$(git diff --name-only --cached)" = "testfile"

  # necessary so `git commit` will work
  - |
      git config user.email "you@example.com"
      git config user.name "Your Name"

  # necessary to check the libexec binaries work
  - git commit --message "test"

  - git subtree add --prefix teaxyz-subtree https://github.com/teaxyz/white-paper main --squash

  - git gone --version

provides:
  linux:
    - bin/git
    - bin/git-cvsserver
    - bin/git-receive-pack
    - bin/git-shell
    - bin/git-upload-archive
    - bin/git-upload-pack
    - bin/scalar
  darwin:
    - bin/git
    - bin/git-cvsserver
    - bin/git-receive-pack
    - bin/git-shell
    - bin/git-upload-archive
    - bin/git-upload-pack
    - bin/scalar
    - bin/git-credential-osxkeychain
