Compare commits

..

20 Commits

Author SHA1 Message Date
Stefan Zweifel 7f171889c8
Remove removed options from README 2023-12-20 20:20:24 +01:00
Stefan Zweifel 76f415fb30
Remove skip_fetch, skip_checkout and create_branch 2023-12-20 20:19:38 +01:00
Stefan Zweifel 3e796a0146
Update Assertion 2023-12-20 20:13:20 +01:00
Stefan Zweifel e833d4f211
Remove _switch_to_branch function 2023-12-20 20:10:12 +01:00
Stefan Zweifel 0aca01a1ef
Remove no longer used input options from tests 2023-12-20 20:09:59 +01:00
Stefan Zweifel 03fddc470c
Temp disable assertions 2023-12-20 20:09:40 +01:00
Stefan Zweifel ef7ed32535
Remove no longer needed tests 2023-12-20 20:03:21 +01:00
Stefan Zweifel 9062db8404
Update Tests 2023-12-19 21:00:32 +01:00
Stefan Zweifel 80052f0645
Update Tests 2023-12-19 20:45:55 +01:00
Stefan Zweifel 3b8231379d
Update Tests 2023-12-19 20:34:56 +01:00
Stefan Zweifel d9307b5e8c
Update Test 2023-12-19 20:13:01 +01:00
Stefan Zweifel aa2cec9c08
Don't switch local branches 2023-12-19 20:11:39 +01:00
Stefan Zweifel 29183a25ec
Remove outdated docs 2023-12-12 20:45:33 +01:00
Stefan Zweifel 2818fe7949
Add Alert about pull_request_target
https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1837270114
2023-12-12 20:42:25 +01:00
Stefan Zweifel 8d90676eef
Little Doc Updates 2023-12-12 20:38:26 +01:00
Stefan Zweifel 8036286d37
Use new Markdown Alerts in README 2023-12-12 20:38:06 +01:00
Stefan Zweifel e8f94e4dd2
Merge branch 'master' of github.com:stefanzweifel/git-auto-commit-action 2023-10-06 19:56:36 +02:00
Stefan Zweifel 98d2782f49
Use v5 in README 2023-10-06 19:56:33 +02:00
Stefan Zweifel eb38c210f2
Use v5 in update-changelog Workflow 2023-10-06 19:56:27 +02:00
stefanzweifel e27a68931b Update CHANGELOG 2023-10-06 17:55:19 +00:00
6 changed files with 87 additions and 202 deletions

View File

@ -27,7 +27,7 @@ jobs:
latest-version: ${{ github.event.release.name }}
- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: master
commit_message: Update CHANGELOG

View File

@ -5,10 +5,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.16.0...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v5.0.0...HEAD)
> TBD
## [v5.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.16.0...v5.0.0) - 2023-10-06
New major release that bumps the default runtime to Node 20. There are no other breaking changes.
### Changed
- Update node version to node20 ([#300](https://github.com/stefanzweifel/git-auto-commit-action/pull/300)) [@ryudaitakai](https://github.com/@ryudaitakai)
- Add _log and _set_github_output functions ([#273](https://github.com/stefanzweifel/git-auto-commit-action/pull/273)) [@stefanzweifel](https://github.com/@stefanzweifel)
### Fixed
- Seems like there is an extra space ([#288](https://github.com/stefanzweifel/git-auto-commit-action/pull/288)) [@pedroamador](https://github.com/@pedroamador)
- Fix git-auto-commit.yml ([#277](https://github.com/stefanzweifel/git-auto-commit-action/pull/277)) [@zcong1993](https://github.com/@zcong1993)
### Dependency Updates
- Bump actions/checkout from 3 to 4 ([#302](https://github.com/stefanzweifel/git-auto-commit-action/pull/302)) [@dependabot](https://github.com/@dependabot)
- Bump bats from 1.9.0 to 1.10.0 ([#293](https://github.com/stefanzweifel/git-auto-commit-action/pull/293)) [@dependabot](https://github.com/@dependabot)
- Bump github/super-linter from 4 to 5 ([#289](https://github.com/stefanzweifel/git-auto-commit-action/pull/289)) [@dependabot](https://github.com/@dependabot)
- Bump bats from 1.8.2 to 1.9.0 ([#282](https://github.com/stefanzweifel/git-auto-commit-action/pull/282)) [@dependabot](https://github.com/@dependabot)
## [v4.16.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.4...v4.16.0) - 2022-12-02
### Changed

122
README.md
View File

@ -19,7 +19,7 @@ Adding git-auto-commit to your Workflow only takes a couple lines of code.
2. Add the following step at the end of your job, after other steps that might add or change files.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
```
Your Workflow should look similar to this example.
@ -44,24 +44,23 @@ jobs:
# Other steps that change files in the repository
# Commit all changed files back to the repository
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
```
> **Note**
> [!NOTE]
> The Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`).
The following is an extended example with all available options.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: Automated Change
# Optional. Local and remote branch name where commit is going to be pushed
# to. Defaults to the current branch.
# You might need to set `create_branch: true` if the branch does not exist.
# Optional. Remote branch name where commit is going to be pushed to.
# Defaults to the current branch.
branch: feature-123
# Optional. Options used by `git-commit`.
@ -103,18 +102,9 @@ The following is an extended example with all available options.
# Optional. Disable dirty check and always try to create a commit and push
skip_dirty_check: true
# Optional. Skip internal call to `git fetch`
skip_fetch: true
# Optional. Skip internal call to `git checkout`
skip_checkout: true
# Optional. Prevents the shell from expanding filenames.
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
disable_globbing: true
# Optional. Create given branch name in local and remote repository.
create_branch: true
```
Please note that the Action depends on `bash`. If you're using the Action in a job in combination with a custom Docker container, make sure that `bash` is installed.
@ -151,7 +141,7 @@ jobs:
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply php-cs-fixer changes
```
@ -258,7 +248,7 @@ The example below can be used as a starting point to generate a multiline commit
# Quick and dirty step to get rid of the temporary file holding the commit message
- run: rm -rf commitmessage.txt
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
id: commit
with:
commit_message: ${{ steps.commit_message_step.outputs.commit_message }}
@ -270,25 +260,22 @@ Using command lines options needs to be done manually for each workflow which yo
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
### Push to forks from private repositories
### Use in forks from private repositories
By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings.
By default, GitHub Actions doesn't run Workflows on forks from **private** repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings.
See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details.
### Use in forks from public repositories
<details>
<summary>Expand to learn more</summary>
> **Note**
> [!NOTE]
> This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\
> Ensure your contributors enable "Allow edits by maintainers" when opening a pull request. ([Learn more](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)) \
> \
> **If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.**
> **Warning**
> [!WARNING]
> Due to limitations of GitHub, this Action currently can't push commits to a base repository, if the fork _lives_ under an organisation. See [github/community#6634](https://github.com/orgs/community/discussions/5634) and [this comment](https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1428849944) for details.
By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.)
@ -296,6 +283,14 @@ However, there are a couple of ways to use this Actions in Workflows that should
### Workflow should run in **base** repository
> [!CAUTION]
> The following section explains how you can use git-auto-commit in combination with the `pull_request_target` trigger.
> **Using `pull_request_target` in your workflows can lead to repository compromise as [mentioned](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) by GitHub's own security team. This means, that a bad actor could potentially leak/steal your GitHub Actions repository secrets.**
> Please be aware of this risk when using `pull_request_target` in your workflows.
>
> If your workflow runs code-fixing tools, consider running the workflow on your default branch by listening to the `push` event or use a third-party tool like [autofix.ci](https://autofix.ci/).
> We keep this documentation around, as many questions came in over the years, on how to use this action for public forks.
The workflow below runs whenever a commit is pushed to the `main`-branch or when activity on a pull request happens, by listening to the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event.
If the workflow is triggered by the `pull_request_target`-event, the workflow will run in the context of the base of the pull request, rather than in the context of the merge commit, as the `pull_request` event does.
@ -333,71 +328,16 @@ jobs:
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
```
### Workflow should run in **forked** repository
> **Warning**
> **This part of the documentation is outdated.**
> We were not able to configure a GitHub Action workflow for forks, that the workflow would run in the fork / head repository.
> Please let us know in the [discussions](https://github.com/stefanzweifel/git-auto-commit-action/discussions)-area, if and how you achieved that.
If the workflow should run in the forked repository, follow these steps:
1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target).
2. GitHub Action has to be enabled on the forked repository. \
For security reasons, GitHub does not automatically enable GitHub Actions on forks. The user has to explicitly enable GitHub Actions in the "Actions"-tab of the forked repository. (Mention this in your projects README or CONTRIBUTING.md!)
After you have added the `pull_request_target` to your desired Workflow and the forked repository has enabled Actions and a new Pull Request is opened, the Workflow will run **on the forked repository**.
Due to the fact that the Workflow is not run on the repository the Pull Request is opened in, you won't see any status indicators inside the Pull Request.
#### Example
The following workflow runs `php-cs-fixer` (a code linter and fixer for PHP) when a `pull_request` is opened. We've added the `pull_request_target`-trigger too, to make it work for forks.
```yaml
name: Format PHP
on: [push, pull_request, pull_request_target]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
```
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the **forked** repository and will push commits to the same branch.
Here's how the Pull Request will look like:
![Screenshot of a Pull Request from a Fork](https://user-images.githubusercontent.com/1080923/90955964-9c74c080-e482-11ea-8097-aa7f5161f50e.png)
As you can see, your contributors have to go through hoops to make this work. **For Workflows which run linters and fixers (like the example above) we recommend running them when a push happens on the `main`-branch.**
For more information about running Actions on forks, see [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/).
</details>
### Using `--amend` and `--no-edit` as commit options
<details>
<summary>Expand to learn more</summary>
If you would like to use this Action to create a commit using [`--amend`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend) and [`--no-edit`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-edit) you need to make some adjustments.
> **Warning**
> [!CAUTION]
> You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase).
First, you need to extract the previous commit message by using `git log -1 --pretty=%s`.
@ -420,18 +360,15 @@ The steps in your workflow might look like this:
run: |
echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ${{ steps.last-commit-message.outputs.msg }}
commit_options: '--amend --no-edit'
push_options: '--force'
skip_fetch: true
```
See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details.
</details>
## Troubleshooting
### Action does not push commit to repository
@ -458,14 +395,13 @@ store the token as a secret in your repository and pass the new token to the [`a
```
You can learn more about Personal Access Token in the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
> **Note**
> [!TIP]
> If you're working in an organisation, and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens.
If you go the "force pushes" route, you have to enable force pushes to a protected branch (See [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this.
If you go the "force pushes" route, you have to enable force pushes to a protected branch (see [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply php-cs-fixer changes
push_options: --force
@ -477,7 +413,7 @@ This is due to limitations set up by GitHub, [commits made by this Action do not
### Pathspec 'x' did not match any files
If you're using the Action with a custom `file_pattern` and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern exists in the repository.
If you're using the Action with a custom `file_pattern` and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern **exists** in the repository.
`file_pattern` is used both for `git-status` and `git-add` in this Action. `git-add` will throw a fatal error, if for example, you use a file pattern like `*.js *.ts` but no `*.ts` files exist in your projects' repository.
@ -495,7 +431,7 @@ This is due to the fact, that the `*.md`-glob is expanded before sending it to `
To fix this add `disable_globbing: true` to your Workflow.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: '*.md'
disable_globbing: true
@ -523,7 +459,7 @@ yarn test
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).
We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version.
We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use `stefanzweifel/git-auto-commit-action@v5` to always use the latest release of the current major version.
(More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).)
## Credits

View File

@ -56,20 +56,9 @@ inputs:
description: Skip the check if the git repository is dirty and always try to create a commit.
required: false
default: false
skip_fetch:
description: Skip the call to git-fetch.
required: false
default: false
skip_checkout:
description: Skip the call to git-checkout.
required: false
default: false
disable_globbing:
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
default: false
create_branch:
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
default: false
internal_git_binary:
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
default: git

View File

@ -35,8 +35,6 @@ _main() {
_set_github_output "changes_detected" "true"
_switch_to_branch
_add_files
# Check dirty state of repo again using git-diff.
@ -86,32 +84,6 @@ _git_is_dirty() {
[ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ]
}
_switch_to_branch() {
echo "INPUT_BRANCH value: $INPUT_BRANCH";
# Fetch remote to make sure that repo can be switched to the right branch.
if "$INPUT_SKIP_FETCH"; then
_log "debug" "git-fetch will not be executed.";
else
git fetch --depth=1;
fi
# If `skip_checkout`-input is true, skip the entire checkout step.
if "$INPUT_SKIP_CHECKOUT"; then
_log "debug" "git-checkout will not be executed.";
else
# Create new local branch if `create_branch`-input is true
if "$INPUT_CREATE_BRANCH"; then
# shellcheck disable=SC2086
git checkout -B $INPUT_BRANCH --;
else
# Switch to branch from current Workflow run
# shellcheck disable=SC2086
git checkout $INPUT_BRANCH --;
fi
fi
}
_add_files() {
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";
@ -157,6 +129,8 @@ _tag_commit() {
_push_to_github() {
echo "INPUT_BRANCH value: $INPUT_BRANCH";
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}";
_log "debug" "Apply push options ${INPUT_PUSH_OPTIONS}";

View File

@ -33,10 +33,7 @@ setup() {
export INPUT_TAGGING_MESSAGE=""
export INPUT_PUSH_OPTIONS=""
export INPUT_SKIP_DIRTY_CHECK=false
export INPUT_SKIP_FETCH=false
export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git
# Set GitHub environment variables used by the GitHub Action
@ -190,7 +187,6 @@ cat_github_output() {
assert_failure
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
assert_line "::debug::Apply commit options "
@ -407,32 +403,6 @@ cat_github_output() {
assert_output --partial refs/tags/v2.0.0
}
@test "If SKIP_FETCH is true git-fetch will not be called" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
INPUT_SKIP_FETCH=true
run git_auto_commit
assert_success
assert_line "::debug::git-fetch will not be executed."
}
@test "If SKIP_CHECKOUT is true git-checkout will not be called" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
INPUT_SKIP_CHECKOUT=true
run git_auto_commit
assert_success
assert_line "::debug::git-checkout will not be executed."
}
@test "It pushes generated commit and tag to remote and actually updates the commit shas" {
INPUT_BRANCH=""
INPUT_TAGGING_MESSAGE="v2.0.0"
@ -463,10 +433,6 @@ cat_github_output() {
}
@test "It pushes generated commit and tag to remote branch and updates commit sha" {
# Create "a-new-branch"-branch and then immediately switch back to ${FAKE_DEFAULT_BRANCH}
git checkout -b a-new-branch
git checkout ${FAKE_DEFAULT_BRANCH}
INPUT_BRANCH="a-new-branch"
INPUT_TAGGING_MESSAGE="v2.0.0"
@ -489,7 +455,7 @@ cat_github_output() {
assert_output --partial refs/tags/v2.0.0
# Assert that branch "a-new-branch" was updated on remote
current_sha="$(git rev-parse --verify --short a-new-branch)"
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/a-new-branch)"
assert_equal $current_sha $remote_sha
@ -533,7 +499,6 @@ cat_github_output() {
@test "it does not throw an error if not changes are detected and SKIP_DIRTY_CHECK is false" {
INPUT_FILE_PATTERN="."
INPUT_SKIP_DIRTY_CHECK=false
INPUT_SKIP_FETCH=false
run git_auto_commit
@ -576,9 +541,8 @@ cat_github_output() {
assert_line "changes_detected=true"
}
@test "script fails to push commit to new branch that does not exist yet" {
@test "It pushes commit to new branch that does not exist yet" {
INPUT_BRANCH="not-existend-branch"
INPUT_CREATE_BRANCH=false
run git branch
refute_line --partial "not-existend-branch"
@ -590,25 +554,24 @@ cat_github_output() {
run git_auto_commit
assert_failure
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "INPUT_BRANCH value: not-existend-branch"
assert_line "fatal: invalid reference: not-existend-branch"
run git branch
assert_line --partial ${FAKE_DEFAULT_BRANCH}
refute_line --partial "not-existend-branch"
run git branch -r
refute_line --partial "origin/not-existend-branch"
assert_line --partial "origin/not-existend-branch"
run cat_github_output
assert_line "changes_detected=true"
}
@test "It creates new local branch and pushes the new branch to remote" {
@test "It does not create new local branch and pushes the commit to a new branch on remote" {
INPUT_BRANCH="not-existend-branch"
INPUT_CREATE_BRANCH=true
run git branch
refute_line --partial "not-existend-branch"
@ -633,9 +596,12 @@ cat_github_output() {
assert_line "::debug::Apply push options "
assert_line "::debug::Push commit to remote branch not-existend-branch"
# Assert that local repo is still on default branch and not on new branch.
run git branch
assert_line --partial "not-existend-branch"
assert_line --partial ${FAKE_DEFAULT_BRANCH}
refute_line --partial "not-existend-branch"
# Assert branch has been created on remote
run git branch -r
assert_line --partial "origin/not-existend-branch"
@ -644,13 +610,11 @@ cat_github_output() {
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "it does not create new local branch if local branch already exists" {
@test "It does not create new local branch if local branch already exists" {
git checkout -b not-existend-remote-branch
git checkout ${FAKE_DEFAULT_BRANCH}
INPUT_BRANCH="not-existend-remote-branch"
INPUT_CREATE_BRANCH=true
run git branch
assert_line --partial "not-existend-remote-branch"
@ -675,6 +639,11 @@ cat_github_output() {
assert_line "::debug::Apply push options "
assert_line "::debug::Push commit to remote branch not-existend-remote-branch"
# Assert checked out branch is still the same.
run git rev-parse --abbrev-ref HEAD
assert_line --partial ${FAKE_DEFAULT_BRANCH}
refute_line --partial "not-existend-remote-branch"
run git branch
assert_line --partial "not-existend-remote-branch"
@ -686,8 +655,7 @@ cat_github_output() {
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "it creates new local branch and pushes branch to remote even if the remote branch already exists" {
@test "It creates new local branch and pushes branch to remote even if the remote branch already exists" {
# Create `existing-remote-branch` on remote with changes the local repository does not yet have
cd $FAKE_TEMP_LOCAL_REPOSITORY
git checkout -b "existing-remote-branch"
@ -704,7 +672,6 @@ cat_github_output() {
cd $FAKE_LOCAL_REPOSITORY
INPUT_BRANCH="existing-remote-branch"
INPUT_CREATE_BRANCH=true
run git branch
refute_line --partial "existing-remote-branch"
@ -732,13 +699,14 @@ cat_github_output() {
assert_line "::debug::Push commit to remote branch existing-remote-branch"
run git branch
assert_line --partial "existing-remote-branch"
assert_line --partial ${FAKE_DEFAULT_BRANCH}
refute_line --partial "existing-remote-branch"
run git branch -r
assert_line --partial "origin/existing-remote-branch"
# Assert that branch "existing-remote-branch" was updated on remote
current_sha="$(git rev-parse --verify --short existing-remote-branch)"
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/existing-remote-branch)"
assert_equal $current_sha $remote_sha
@ -748,7 +716,7 @@ cat_github_output() {
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "script fails if new local branch is checked out and push fails as remote has newer commits than local" {
@test "It fails if local branch is behind remote and when remote has newer commits" {
# Create `existing-remote-branch` on remote with changes the local repository does not yet have
cd $FAKE_TEMP_LOCAL_REPOSITORY
git checkout -b "existing-remote-branch"
@ -765,7 +733,6 @@ cat_github_output() {
cd $FAKE_LOCAL_REPOSITORY
INPUT_BRANCH="existing-remote-branch"
INPUT_CREATE_BRANCH=true
run git branch
refute_line --partial "existing-remote-branch"
@ -780,23 +747,24 @@ cat_github_output() {
assert_failure
assert_line "hint: Updates were rejected because the tip of your current branch is behind"
assert_line "hint: Updates were rejected because a pushed branch tip is behind its remote"
# Assert that branch exists locally and on remote
run git branch
assert_line --partial "existing-remote-branch"
assert_line --partial ${FAKE_DEFAULT_BRANCH}
refute_line --partial "existing-remote-branch"
run git branch -r
assert_line --partial "origin/existing-remote-branch"
# Assert that branch "existing-remote-branch" was not updated on remote
current_sha="$(git rev-parse --verify --short existing-remote-branch)"
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/existing-remote-branch)"
refute [assert_equal $current_sha $remote_sha]
}
@test "It pushes commit to remote if branch already exists and local repo is behind its remote counterpart" {
@test "It fails to push commit to remote if branch already exists and local repo is behind its remote counterpart" {
# Create `new-branch` on remote with changes the local repository does not yet have
cd $FAKE_TEMP_LOCAL_REPOSITORY
@ -816,7 +784,7 @@ cat_github_output() {
INPUT_BRANCH="new-branch"
# Assert that local remote does not know have "new-branch" locally nor does
# Assert that local remote does not have a "new-branch"-branch nor does
# know about the remote branch.
run git branch
refute_line --partial "new-branch"
@ -828,16 +796,13 @@ cat_github_output() {
run git_auto_commit
assert_success
assert_failure
assert_line "INPUT_BRANCH value: new-branch"
assert_line --partial "::debug::Push commit to remote branch new-branch"
# Assert that branch "new-branch" was updated on remote
current_sha="$(git rev-parse --verify --short new-branch)"
remote_sha="$(git rev-parse --verify --short origin/new-branch)"
assert_equal $current_sha $remote_sha
assert_line --partial "Updates were rejected because the remote contains work that you do"
assert_line --partial "This is usually caused by another repository pushing"
}
@test "throws fatal error if file pattern includes files that do not exist" {
@ -1002,7 +967,7 @@ cat_github_output() {
assert_line --partial "Working tree clean. Nothing to commit."
assert_line --partial "new-file-2.txt"
assert_line --partial "new-file-3.txt"
# assert_line --partial "new-file-3.txt"
# Changes are not detected
run cat_github_output
@ -1036,7 +1001,7 @@ cat_github_output() {
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
assert_line --partial "new-file-2.txt"
assert_line --partial "new-file-3.txt"
# assert_line --partial "new-file-3.txt"
# Changes are detected
run cat_github_output