Class: Fastlane::Actions::ResetGitRepoAction
- Inherits:
-
Fastlane::Action
- Object
- Fastlane::Action
- Fastlane::Actions::ResetGitRepoAction
- Defined in:
- lib/fastlane/actions/reset_git_repo.rb
Overview
Does a hard reset and clean on the repo
Class Method Summary collapse
- .author ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .run(params) ⇒ Object
Methods inherited from Fastlane::Action
Class Method Details
.author ⇒ Object
45 46 47 |
# File 'lib/fastlane/actions/reset_git_repo.rb', line 45 def self. 'lmirosevic' end |
.available_options ⇒ Object
38 39 40 41 42 43 |
# File 'lib/fastlane/actions/reset_git_repo.rb', line 38 def self. [ ['files', 'Array of files the changes should be discarded from. If not given, all files will be discarded'], ['force', 'Skip verifying of previously clean state of repo. Only recommended in combination with `files` option'] ] end |
.description ⇒ Object
26 27 28 |
# File 'lib/fastlane/actions/reset_git_repo.rb', line 26 def self.description "Resets git repo to a clean state by discarding uncommited changes" end |
.details ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/fastlane/actions/reset_git_repo.rb', line 30 def self.details [ "This action will reset your git repo to a clean state, discarding any uncommitted and untracked changes. Useful in case you need to revert the repo back to a clean state, e.g. after the fastlane run.", "It's a pretty drastic action so it comes with a sort of safety latch. It will only proceed with the reset if either of these conditions are met:", "You have called the ensure_git_status_clean action prior to calling this action. This ensures that your repo started off in a clean state, so the only things that will get destroyed by this action are files that are created as a byproduct of the fastlane run." ].join(' ') end |
.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 |