def setup_environment
      store_modified_times
      Overcommit::GitRepo.store_merge_state
      Overcommit::GitRepo.store_cherry_pick_state

      if !initial_commit? && any_changes?
        @stash_attempted = true

        stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}"
        result = Overcommit::Utils.execute(
          %w[git -c commit.gpgsign=false stash save --keep-index --quiet] + [stash_message]
        )

        unless result.success?
          # Failure to stash in this case is likely due to a configuration
          # issue (e.g. author/email not set or GPG signing key incorrect)
          raise Overcommit::Exceptions::HookSetupFailed,
                "Unable to setup environment for #{hook_script_name} hook run:" \
                "\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
        end

        @changes_stashed = `git stash list -1`.include?(stash_message)
      end

      # While running the hooks make it appear as if nothing changed
      restore_modified_times
    end
def setup_environment
      store_modified_times
      Overcommit::GitRepo.store_merge_state
      Overcommit::GitRepo.store_cherry_pick_state

      if !initial_commit? && any_changes?
        @stash_attempted = true

        stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}"
        result = Overcommit::Utils.execute(
          %w[git -c commit.gpgsign=false stash save --keep-index --quiet] + [stash_message]
        )

        unless result.success?
          # Failure to stash in this case is likely due to a configuration
          # issue (e.g. author/email not set or GPG signing key incorrect)
          raise Overcommit::Exceptions::HookSetupFailed,
                "Unable to setup environment for #{hook_script_name} hook run:" \
                "\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
        end

        @changes_stashed = `git stash list -1`.include?(stash_message)
      end

      # While running the hooks make it appear as if nothing changed
      restore_modified_times
    end
Stash unstaged contents of files so hooks don't see changes that aren't
 about to be committed.