Class: Fastlane::Actions::ResetGitRepoAction

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/actions/reset_git_repo.rb

Overview

Does a hard reset and clean on the repo

Class Method Summary collapse

Class Method Details

.run(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fastlane/actions/reset_git_repo.rb', line 5

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