Skip to content

Commit

Permalink
Revert to 6.2.2 (#203)
Browse files Browse the repository at this point in the history
* Copied code from 6.2.2

* Fixed incorrect spelling of output names
  • Loading branch information
vshah23 authored Feb 6, 2023
1 parent 2237d7d commit b1bf5cb
Show file tree
Hide file tree
Showing 278 changed files with 4,029 additions and 87,673 deletions.
86 changes: 45 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@

[![Step changelog](https://shields.io/github/v/release/bitrise-steplib/steps-git-clone?include_prereleases&label=changelog&color=blueviolet)](https://github.com/bitrise-steplib/steps-git-clone/releases)

Checks out the repository, updates submodules and exports git metadata as Step outputs.
The Step checks out the defined repository state, optionally updates the repository submodules and exports the achieved git repository state properties.

<details>
<summary>Description</summary>

The checkout process depends on the Step settings and the build trigger parameters (coming from your git server).

Depending on the conditions, the step can checkout:
- the merged state of a Pull Request
- the head of a Pull Request
- a git tag
- a specific commit on a branch
- the head of a branch

The Step also supports more advanced features, such as updating submodules and sparse checkouts.
The checkout process depends on the checkout properties: the Step either checks out a repository state defined by a git commit or a git tag, or achieves a merged state of a pull / merge request.
The Step uses two solutions to achieve the merged state of the pull / merge request: auto merge in the case of a merge branch or diff file (provided by the Git service) and manual merge otherwise.
Once the desired state is checked out, the Step optionally updates the submodules. In the case of pull / merge request, the Step checks out a detach head and exports the achieved git state properties.

### Configuring the Step

The step should work with its default configuration if build triggers and webhooks are set up correctly.
1. The **Git repository URL** and the ** Clone destination (local)directory path** fields are required fields and are automatically filled out based on your project settings.
Optionally, you can modify the following fields in the **Clone Config** section:
1. You can set the **Update the registered submodules?** option to `yes` to pull the most up-to-date version of the submodule from the submodule's repository.
2. You can set the number of commits you want the Step to fetch in the **Limit fetching to the specified number of commits** option. Make sure you set a decimal number.

By default, the Step performs a shallow clone in most cases (fetching only the latest commit) to make the clone fast and efficient. If your workflow requires a deeper commit history, you can override this using the **Clone depth** input.
Other **Clone config** inputs are not editable unless you go to the **bitrise.yml** tab, however, to avoid issues, we suggest you to contact our Support team instead.

### Troubleshooting
If you have GitHub Enterprise set up, it works slightly differently on [bitrise.io](https://www.bitrise.io) than on [github.com](https://github.com). You have to manually set the git clone URL, register the SSH key and the webhook.
If you face network issues in the case of self-hosted git servers, we advise you to contact our Support Team to help you out.
If you face slow clone speed, set the **Limit fetching to the specified number of commits** to the number of commits you want to clone instead of cloning the whole commit history or you can use the Git LFS solution provided by the git provider.

### Useful links

- [How to register a GitHub Enterprise repository](https://discuss.bitrise.io/t/how-to-register-a-github-enterprise-repository/218)
- [Code security](https://devcenter.bitrise.io/getting-started/code-security/)

### Related Steps

- [Activate SSH key (RSA private key)](https://www.bitrise.io/integrations/steps/activate-ssh-key)
- [Generate changelog](https://bitrise.io/integrations/steps/generate-changelog)
- [Bitrise.io Cache:Pull](https://www.bitrise.io/integrations/steps/cache-pull)
- [Bitrise.io Cache:Push](https://www.bitrise.io/integrations/steps/cache-push)

</details>

Expand All @@ -49,39 +51,41 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris

| Key | Description | Flags | Default |
| --- | --- | --- | --- |
| `merge_pr` | This only applies to builds triggered by pull requests. Options: - `yes`: Depending on the information in the build trigger, either fetches the PR merge ref or creates the merged state locally. - `no`: Checks out the head of the PR branch without merging it into the destination branch. | | `yes` |
| `clone_into_dir` | Local directory where the repository is cloned | required | `$BITRISE_SOURCE_DIR` |
| `clone_depth` | Limit fetching to the specified number of commits. By default, the Step tries to do a shallow clone (depth of 1) if it's possible based on the build trigger parameters. If it's not possible, it applies a low depth value, unless another value is specified here. It's not recommended to define this input because a shallow clone ensures fast clone times. Examples of when you want to override the clone depth: - A Step in the workflow reads the commit history in order to generate a changelog - A Step in the workflow runs a git diff against a previous commit Use the value `-1` to disable the depth limit completely and fetch the entire repo history. | | |
| `update_submodules` | Update registered submodules to match what the superproject expects. If set to `no`, `git fetch` calls will use the `--no-recurse-submodules` flag. | | `yes` |
| `submodule_update_depth` | When updating submodules, limit fetching to the specified number of commits. The value should be a decimal number, for example `10`. | | |
| `fetch_tags` | yes - fetch all tags from the remote by adding `--tags` flag to `git fetch` calls no - disable automatic tag following by adding `--no-tags` flag to `git fetch` calls | | `no` |
| `sparse_directories` | Limit which directories to clone using [sparse-checkout](https://git-scm.com/docs/git-sparse-checkout). This is useful for monorepos where the current workflow only needs a subfolder. For example, specifying `src/android` the Step will only clone: - contents of the root directory and - contents of the `src/android` directory and all of its subdirectories On the other hand, `src/ios` will not be cloned. This input accepts one path per line, separate entries by a linebreak. | | |
| `repository_url` | SSH or HTTPS URL of the repository to clone | required | `$GIT_REPOSITORY_URL` |
| `commit` | Commit SHA to checkout | | `$BITRISE_GIT_COMMIT` |
| `tag` | Git tag to checkout | | `$BITRISE_GIT_TAG` |
| `branch` | Git branch to checkout | | `$BITRISE_GIT_BRANCH` |
| `branch_dest` | The branch that the pull request targets, such as `main` | | `$BITRISEIO_GIT_BRANCH_DEST` |
| `pull_request_repository_url` | URL of the source repository of a pull request. This points to the fork repository in builds triggered by pull requests. | | `$BITRISEIO_PULL_REQUEST_REPOSITORY_URL` |
| `pull_request_merge_branch` | Git ref pointing to the result of merging the PR branch into the destination branch. Even if the source of the PR is a fork, this is a reference to the destination repository. Example: `refs/pull/14/merge` Note: not all Git services provide this value. | | `$BITRISEIO_PULL_REQUEST_MERGE_BRANCH` |
| `pull_request_head_branch` | Git ref pointing to the head of the PR branch. Even if the source of the PR is a fork, this is a reference to the destination repository. Example: `refs/pull/14/head` Note: not all Git services provide this value. | | `$BITRISEIO_PULL_REQUEST_HEAD_BRANCH` |
| `reset_repository` | Reset repository contents with `git reset --hard HEAD` and `git clean -f` before fetching. | | `No` |
| `repository_url` | | required | `$GIT_REPOSITORY_URL` |
| `clone_into_dir` | | required | `$BITRISE_SOURCE_DIR` |
| `commit` | | | `$BITRISE_GIT_COMMIT` |
| `tag` | | | `$BITRISE_GIT_TAG` |
| `branch` | | | `$BITRISE_GIT_BRANCH` |
| `branch_dest` | | | `$BITRISEIO_GIT_BRANCH_DEST` |
| `pull_request_id` | | | `$PULL_REQUEST_ID` |
| `pull_request_repository_url` | | | `$BITRISEIO_PULL_REQUEST_REPOSITORY_URL` |
| `pull_request_merge_branch` | | | `$BITRISEIO_PULL_REQUEST_MERGE_BRANCH` |
| `pull_request_head_branch` | If the Git hosting provider system supports and provides this, this special git ref should point to the source of the pull request. | | `$BITRISEIO_PULL_REQUEST_HEAD_BRANCH` |
| `update_submodules` | Update the registered submodules to match what the superproject expects by cloning missing submodules, fetching missing commits in submodules and updating the working tree of the submodules. If set to "no" `git fetch` calls will get the `--no-recurse-submodules` flag. | | `yes` |
| `clone_depth` | Limit fetching to the specified number of commits. The value should be a decimal number, for example `10`. | | |
| `submodule_update_depth` | Truncate the history to the specified number of revisions. The value should be a decimal number, for example `10`. | | |
| `merge_pr` | Disables merging the source and destination branches. - `yes`: The default setting. Merges the source branch into the destination branch. - `no`: Treats Pull Request events as Push events on the source branch. | | `yes` |
| `sparse_directories` | Limit which directories should be cloned during the build. This could be useful if a repository contains multiple platforms, so called monorepositories, and the build is only targeting a single platform. For example, specifying "src/android" the Step will only clone: - contents of the root directory and - contents of the "src/android" directory and all subdirectories of "src/android". On the other hand, "src/ios" and any other directories will not be cloned. | | |
| `reset_repository` | | | `No` |
| `manual_merge` | Prefer to do a manual `git merge` by default. When the Pull Request is from a GitHub or Bitbucket private fork repository set this to `no`. | | `yes` |
| `fetch_tags` | yes - fetch all tags from the remote by adding `--tags` flag to git fetch calls no - disable automatic tag following by adding `--no-tags` flag to git fetch calls | | `no` |
| `build_url` | Unique build URL of this build on Bitrise.io | | `$BITRISE_BUILD_URL` |
| `build_api_token` | The build's API Token for the build on Bitrise.io | sensitive | `$BITRISE_BUILD_API_TOKEN` |
</details>

<details>
<summary>Outputs</summary>

| Environment Variable | Description |
| --- | --- |
| `GIT_CLONE_COMMIT_HASH` | SHA hash of the checked-out commit. |
| `GIT_CLONE_COMMIT_MESSAGE_SUBJECT` | Commit message of the checked-out commit. |
| `GIT_CLONE_COMMIT_MESSAGE_BODY` | Commit message body of the checked-out commit. |
| `GIT_CLONE_COMMIT_COUNT` | Commit count after checkout. Count will only work properly if no `--depth` option is set. If `--depth` is set then the history truncated to the specified number of commits. Count will **not** fail but will be the clone depth. |
| `GIT_CLONE_COMMIT_AUTHOR_NAME` | Author of the checked-out commit. |
| `GIT_CLONE_COMMIT_AUTHOR_EMAIL` | Email of the checked-out commit. |
| `GIT_CLONE_COMMIT_COMMITTER_NAME` | Committer name of the checked-out commit. |
| `GIT_CLONE_COMMIT_COMMITTER_EMAIL` | Email of the checked-out commit. |
| Environment Variable | Description |
|------------------------------------| --- |
| `GIT_CLONE_COMMIT_HASH` | |
| `GIT_CLONE_COMMIT_MESSAGE_SUBJECT` | |
| `GIT_CLONE_COMMIT_MESSAGE_BODY` | |
| `GIT_CLONE_COMMIT_COUNT` | Count will only work properly if no `--depth` option is set. If `--depth` is set then the history truncated to the specified number of commits. Count will **not** fail but will be the clone depth. |
| `GIT_CLONE_COMMIT_AUTHOR_NAME` | |
| `GIT_CLONE_COMMIT_AUTHOR_EMAIL` | |
| `GIT_CLONE_COMMIT_COMMITTER_NAME` | |
| `GIT_CLONE_COMMIT_COMMITTER_EMAIL` | |
</details>

## 🙋 Contributing
Expand Down
61 changes: 48 additions & 13 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ app:
- MERGE_PR: "yes"
- CLONE_DEPTH: ""
- SPARSE_DIRECTORIES: ""
- MANUAL_MERGE: "yes"
# define these envs in your .bitrise.secrets.yml
- GIT_CLONE_SSH_PRIVATE_KEY: $GIT_CLONE_SSH_PRIVATE_KEY

Expand All @@ -21,7 +22,6 @@ workflows:
- BRANCH: test/generate-changelog
- FETCH_TAGS: "yes"
- UPDATE_SUBMODULES: "no"
- CLONE_DEPTH: 78
before_run:
- _setup
after_run:
Expand All @@ -36,7 +36,6 @@ workflows:
- BRANCH: test/generate-changelog
- FETCH_TAGS: "yes"
- UPDATE_SUBMODULES: "no"
- CLONE_DEPTH: 46
before_run:
- _setup
after_run:
Expand Down Expand Up @@ -185,9 +184,11 @@ workflows:

test_checkout_github_pull_request:
envs:
- PULL_REQUEST_ID: 5
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/5/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/5/head
- BITRISEIO_GIT_BRANCH_DEST: master
- MANUAL_MERGE: "no"
- UPDATE_SUBMODULES: "no"
before_run:
- _setup
Expand All @@ -198,11 +199,12 @@ workflows:

test_checkout_pull_request_no_merge:
envs:
- PULL_REQUEST_ID: 5
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/5/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/5/head
- BITRISEIO_GIT_BRANCH_DEST: master
- COMMIT: 4301a9b8499ed3e87778dd053c55fd698d0a3b7e
- CLONE_DEPTH: 1
- MANUAL_MERGE: "no"
- MERGE_PR: "no"
- UPDATE_SUBMODULES: "no"
before_run:
Expand All @@ -212,12 +214,44 @@ workflows:
- _check_outputs
- _teardown

test_checkout_pull_request_standard_branch:
envs:
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pr_test
- BITRISEIO_GIT_BRANCH_DEST: master
- MANUAL_MERGE: "no"
- UPDATE_SUBMODULES: "no"
before_run:
- _setup
after_run:
- _run
- _check_outputs
- _teardown

test_checkout_pull_request_with_depth:
envs:
- PULL_REQUEST_ID: 5
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/5/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/5/head
- BITRISEIO_GIT_BRANCH_DEST: master
- CLONE_DEPTH: 1
- MANUAL_MERGE: "no"
before_run:
- _setup
after_run:
- _run
- _check_outputs
- _teardown

test_manual_merge_unshallow:
envs:
- PULL_REQUEST_ID: 5
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/7/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/7/head
- BITRISEIO_GIT_BRANCH_DEST: master
- COMMIT: 76a934ae80f12bb9b504bbc86f64a1d310e5db64
- BRANCH: test/commit-messages
- CLONE_DEPTH: 1
- UPDATE_SUBMODULES: "no"
before_run:
- _setup
after_run:
Expand Down Expand Up @@ -266,9 +300,9 @@ workflows:

test_hosted_git_notfork:
envs:
- PULL_REQUEST_ID: 7
- BITRISEIO_PULL_REQUEST_REPOSITORY_URL: [email protected]:bitrise-io/git-clone-test.git
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/7/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/7/head
- BITRISEIO_GIT_BRANCH_DEST: master
- COMMIT: 76a934ae80f12bb9b504bbc86f64a1d310e5db64
- BRANCH: test/commit-messages
Expand All @@ -295,13 +329,15 @@ workflows:

test_fork_with_head_branch:
envs:
- PULL_REQUEST_ID: 7
# Alternate URL for repository, the difference causes the Step to handle it as a fork
- BITRISEIO_PULL_REQUEST_REPOSITORY_URL: https://github.com/bitrise-samples/git-clone-test/
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/7/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/7/head
- BITRISEIO_GIT_BRANCH_DEST: master
- COMMIT: 76a934ae80f12bb9b504bbc86f64a1d310e5db64
- BRANCH: test/commit-messages
- MANUAL_MERGE: "no"
before_run:
- _setup
after_run:
Expand All @@ -311,12 +347,13 @@ workflows:

test_unrelated_histories:
envs:
- PULL_REQUEST_ID: 8
- BITRISEIO_PULL_REQUEST_MERGE_BRANCH: pull/8/merge
- BITRISEIO_PULL_REQUEST_HEAD_BRANCH: pull/8/head
- BITRISEIO_PULL_REQUEST_REPOSITORY_URL: $TEST_REPO_URL
- BITRISEIO_GIT_BRANCH_DEST: unrelated-histories/master
- COMMIT: 62af44590c7a2b937726f2c3024a88a129b330b5
- CLONE_DEPTH: 1
- MANUAL_MERGE: "no"
- UPDATE_SUBMODULES: "no"
before_run:
- _setup
Expand Down Expand Up @@ -379,11 +416,13 @@ workflows:
inputs:
- repository_url: $TEST_DIFF_REPO_URL
- clone_into_dir: $TEST_DIFF_CLONE_DIR
- pull_request_id: 8
- pull_request_repository_url: $TEST_DIFF_PR_REPOSITORY_URL
- branch_dest: master
- branch: master
- commit: c6810e6
- clone_depth: 1
- manual_merge: "no"
- script:
inputs:
- content: |-
Expand Down Expand Up @@ -453,7 +492,7 @@ workflows:
inputs:
- content: |-
#!/bin/env bash
set -e
set -ex
EXPECTED_CHANGELOG="* [a409478] Add newline to the description.
* [b002ab7] Add repository description.
Expand All @@ -464,11 +503,6 @@ workflows:
echo "Expected changelog generated."
else
echo "Invalid changelog generated:"
echo ""
echo "Expected changelog:"
echo "$EXPECTED_CHANGELOG"
echo ""
echo "Generated changelog:"
echo "$BITRISE_CHANGELOG"
exit 1
fi
Expand All @@ -492,7 +526,7 @@ workflows:
check "GIT_CLONE_COMMIT_HASH" "76a934ae80f12bb9b504bbc86f64a1d310e5db64"
check "GIT_CLONE_COMMIT_MESSAGE_SUBJECT" "Sample commit message subject"
check "GIT_CLONE_COMMIT_MESSAGE_BODY" "Sample commit message body"
check "GIT_CLONE_COMMIT_COUNT" "1"
check "GIT_CLONE_COMMIT_COUNT" "25"
check "GIT_CLONE_COMMIT_AUTHOR_NAME" "Krisztian Dobmayer"
check "GIT_CLONE_COMMIT_AUTHOR_EMAIL" "[email protected]"
check "GIT_CLONE_COMMIT_COMMITTER_NAME" "Krisztian Dobmayer"
Expand Down Expand Up @@ -544,6 +578,7 @@ workflows:
envman unset --key BITRISE_GIT_TAG
envman unset --key BITRISE_GIT_BRANCH
envman unset --key BITRISEIO_GIT_BRANCH_DEST
envman unset --key PULL_REQUEST_ID
envman unset --key BITRISEIO_PULL_REQUEST_REPOSITORY_URL
envman unset --key BITRISEIO_PULL_REQUEST_MERGE_BRANCH
envman unset --key BITRISEIO_PULL_REQUEST_HEAD_BRANCH
Expand Down Expand Up @@ -579,7 +614,6 @@ workflows:
envman add --key WORKDIR_ABSOLUTE --value $WD
fi
- path::./:
run_if: "true"
inputs:
- repository_url: $TEST_REPO_URL
- clone_into_dir: $WORKDIR
Expand All @@ -591,6 +625,7 @@ workflows:
- merge_pr: $MERGE_PR
- clone_depth: $CLONE_DEPTH
- sparse_directories: $SPARSE_DIRECTORIES
- manual_merge: $MANUAL_MERGE

_teardown:
steps:
Expand Down
Loading

0 comments on commit b1bf5cb

Please sign in to comment.