Ignore Working Tree Clean

I’ve got an Action that lints my code base, which works fine. However, when there is no change, say I update some data files, the Action fails as follows:

Run git config --global user.name 'nqp2'
  git config --global user.name 'nqp2'
  git config --global user.email 'snayff@users.noreply.github.com'
  git commit -am "ci lint and test"
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
    pythonLocation: C:\hostedtoolcache\windows\Python\3.8.10\x64
On branch feature/update_gh_actions
Your branch is up to date with 'origin/feature/update_gh_actions'.

nothing to commit, working tree clean
Error: Process completed with exit code 1.

Is there a way to elegantly handle this, such that the Action passes when there is no action to take?


You could check if there are changes using git diff --exit-code and make the commit only if there are any, e.g.:

git diff --exit-code || git commit -am "ci lint and test"
1 Like
if ! git diff-index --quiet HEAD --; then 
          // Do whatever when there are changes

Example: zap-extensions/create_retirejs_update.yml at daace7400391da3218d8e213889c3cdb27b11861 · zaproxy/zap-extensions · GitHub

1 Like