Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to prevent error while committing with no changes #390

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gautamkrishnar
Copy link

@gautamkrishnar gautamkrishnar commented Nov 18, 2020

As of now if someone is using the example code from the readme and they don't have any local changes, the workflow will fail with an error. It's better to prevent this in the example code itself. Added code to prevent error while committing with no changes, This will check whether the Head has changed and will execute the commit command only if it changed. It will prevent the following error:

> git commit -m "hello"           
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
> echo $?
1

Git commit command returns a non zero exit status if there's no change

Solution

git diff-index --quiet HEAD will return non zero status only if there's a change added via git add this will jump into the || or condition and executes the git commit command. If git diff-index --quiet HEAD returns zero (when there's no change), the git commit command will not be executed, hence it will prevent the error code from getting thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants