Skip to content

Commit cf96c45

Browse files
authored
Fix branch conflicts (#7)
* Add branch check * Improve docs
1 parent 98ce691 commit cf96c45

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ Add a step like this to your workflow:
3737
The only `env` variable required is the token for the action to run: GitHub generates one automatically, but you need to pass it through `env` to make it available to actions. You can find more about `GITHUB_TOKEN` [here](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
3838
With that said, you can just copy the example line and don't worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
3939

40+
### Deleting files:
41+
42+
This action only **adds** files so in order to commit a file deletion you need to stage that separately: for that, you can run `git rm` in a previous step. Here's a quick example:
43+
44+
```yaml
45+
- run: git rm delete_me.txt
46+
47+
- uses: EndBug/add-and-commit@issue-6
48+
with:
49+
author_name: Your Name
50+
author_email: [email protected]
51+
message: "Remove file"
52+
path: "."
53+
pattern: "*.js" # The path is not important, the file will get removed anyway: that means you can still use the action as usual
54+
force: true
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
```
58+
4059
### Example:
4160

4261
You want to lint your JavaScript files, located in the `src` folder, with ESLint so that fixable changes are done without your intervention. You can use a workflow like this:
@@ -78,4 +97,4 @@ jobs:
7897

7998
## License
8099

81-
This action is distributed under the MIT license, check the [license](LICENSE) for more info.
100+
This action is distributed under the MIT license, check the [license](LICENSE) for more info.

entrypoint.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ then
3737

3838
git fetch
3939

40-
# Switch to branch from current Workflow run
41-
echo "Creating and switching branch..."
42-
git branch "${GITHUB_REF:11}"
40+
# Verify if the branch needs to be created
41+
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"
42+
then
43+
echo "Creating branch..."
44+
git branch "${GITHUB_REF:11}"
45+
fi
46+
47+
# Switch to branch from current workflow run
48+
echo "Switching branch..."
4349
git checkout "${GITHUB_REF:11}"
4450

4551
echo "Adding files..."

0 commit comments

Comments
 (0)