Sha256: 53f278b0caf197d0e0f3f7be94a8e43c51fd8426e27595709b1c51145e1ccde7

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Fastlane
  module Actions
    # Does a hard reset and clean on the repo
    class ResetGitRepoAction
      def self.run(params)
        hash = params.first
        if params.include?(:force) || hash[:force] || Actions.lane_context[SharedValues::GIT_REPO_WAS_CLEAN_ON_START]
          paths = (hash[:files] rescue nil)

          if (paths || []).count == 0
            Actions.sh('git reset --hard HEAD')
            Actions.sh('git clean -qfdx')
            Helper.log.info 'Git repo was reset and cleaned back to a pristine state.'.green
          else
            paths.each do |path|
              Helper.log.warn("Couldn't find file at path '#{path}'") unless File.exists?(path)
              Actions.sh("git checkout -- '#{path}'")
            end
            Helper.log.info "Git cleaned up #{paths.count} files.".green
          end
        else
          raise 'This is a destructive and potentially dangerous action. To protect from data loss, please add the `ensure_git_status_clean` action to the beginning of your lane, or if you\'re absolutely sure of what you\'re doing then call this action with the :force option.'.red
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fastlane-0.6.1 lib/fastlane/actions/reset_git_repo.rb