guitarrapc / git-shallow-clone-orb

circleci orb to execute git shallow clone for faster checkout.
https://circleci.com/orbs/registry/orb/guitarrapc/git-shallow-clone
MIT License
21 stars 11 forks source link

feat: add no_tags to git-shallow-clone/checkout, add test and examples. #24

Closed guitarrapc closed 2 years ago

guitarrapc commented 2 years ago

additional PR to release https://github.com/guitarrapc/git-shallow-clone-orb/pull/23

tl;dr;

Summary

checkout also need no_tags options.

add no_tags: <boolean> to handle --no-tags on checkout command.

    steps:
      - git-shallow-clone/checkout:
          fetch_depth: 1000
          no_tags: true

checkout_advanced need example

Only use --no-tags on tag_fetch_options will fetch all tags on pr or push.

    steps:
      - git-shallow-clone/checkout_advanced:
          clone_options: "--depth 1"
          fetch_options: "--depth 1000"
          tag_fetch_options: "--no-tags"
      - run: git tag --list
# Fetch remote and check the commit ID of the checked out code
if [ -n "$CIRCLE_TAG" ]
then
  # tag
  git fetch --no-tags --depth 1000 --force origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
elif [[ $(echo $CIRCLE_BRANCH | grep -e ^pull\/*) ]] # sh version of bash `elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]]`
then
  # pull request
  git fetch --depth 1000 --force origin "${CIRCLE_BRANCH}/head:remotes/origin/${CIRCLE_BRANCH}"
else
  # others
  git fetch --depth 1000 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
fi
git tag --list
WARNING: terminal is not fully functional
-  (press RETURN)v0.1.0
v0.1.1
v0.1.2
v0.1.3
v0.2.0
v1.0.0
v1.0.1
v1.1.0
v1.1.1
v1.1.2
v1.2.0
v1.2.1
v1.2.2
v1.2.3
v2.0.0
v2.0.1
v2.0.2
v2.0.3
v2.1.0
v2.3.0

There are 2 choice to handle tag fetch on pr and push.

Let's use Choise 2 for simpler usage. To skip fetch tag on pr, and fetch single tag on tag operation "add --no-tags to both fetch_options and tag_fetch_options".

    steps:
      - git-shallow-clone/checkout_advanced:
          clone_options: "--depth 1"
          fetch_options: "--depth 1000 --no-tags"
          tag_fetch_options: "--no-tags"
      - run: git tag --list