Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Overcommit Changelog

* Add `staged_changes?` check to avoid stashing files if no changes has been staged.

## 0.57.0

* Fix `CommitMsg` hooks to be able to call `modified_lines_in_file`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup_environment
# Don't attempt to stash changes if all changes are staged, as this
# prevents us from modifying files at all, which plays better with
# editors/tools which watch for file changes.
if !initial_commit? && unstaged_changes?
if !initial_commit? && unstaged_changes? && staged_changes?
stash_changes

# While running hooks make it appear as if nothing changed
Expand Down Expand Up @@ -74,6 +74,13 @@ def unstaged_changes?
!result.success?
end

# Checks whether there are any staged changes.
# https://github.com/sds/overcommit/issues/751
def staged_changes?
result = Overcommit::Utils.execute(%w[git --no-pager diff --cached --quiet])
!result.success?
end

def stash_changes
@stash_attempted = true

Expand Down