class Fastlane::Actions::EnsureGitStatusCleanAction

Raises an exception and stop the lane execution if the repo is not in a clean state

Public Class Methods

author() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 51
def self.author
  ["lmirosevic", "antondomashnev"]
end
available_options() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 61
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :show_uncommitted_changes,
                                 env_name: "FL_ENSURE_GIT_STATUS_CLEAN_SHOW_UNCOMMITTED_CHANGES",
                                 description: "The flag whether to show uncommitted changes if the repo is dirty",
                                 optional: true,
                                 default_value: false,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :show_diff,
                                 env_name: "FL_ENSURE_GIT_STATUS_CLEAN_SHOW_DIFF",
                                 description: "The flag whether to show the git diff if the repo is dirty",
                                 optional: true,
                                 default_value: false,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :ignored,
                                 env_name: "FL_ENSURE_GIT_STATUS_CLEAN_IGNORED_FILE",
                                 description: "The flag whether to ignore file the git status if the repo is dirty",
                                 optional: true)
  ]
end
category() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 82
def self.category
  :source_control
end
description() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 33
def self.description
  "Raises an exception if there are uncommitted git changes"
end
details() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 37
def self.details
  [
    "A sanity check to make sure you are working in a repo that is clean.",
    "Especially useful to put at the beginning of your Fastfile in the `before_all` block, if some of your other actions will touch your filesystem, do things to your git repo, or just as a general reminder to save your work.",
    "Also needed as a prerequisite for some other actions like `reset_git_repo`."
  ].join("\n")
end
example_code() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 55
def self.example_code
  [
    'ensure_git_status_clean'
  ]
end
is_supported?(platform) click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 86
def self.is_supported?(platform)
  true
end
output() click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 45
def self.output
  [
    ['GIT_REPO_WAS_CLEAN_ON_START', 'Stores the fact that the git repo was clean at some point']
  ]
end
run(params) click to toggle source
# File fastlane/lib/fastlane/actions/ensure_git_status_clean.rb, line 9
def self.run(params)
  if params[:ignored]
    ignored_file = params[:ignored]
    repo_status = Actions.sh("git status --porcelain --ignored #{ignored_file}")
  else
    repo_status = Actions.sh("git status --porcelain")
  end

  repo_clean = repo_status.empty?

  if repo_clean
    UI.success('Git status is clean, all good! 💪')
    Actions.lane_context[SharedValues::GIT_REPO_WAS_CLEAN_ON_START] = true
  else
    error_message = "Git repository is dirty! Please ensure the repo is in a clean state by committing/stashing/discarding all changes first."
    error_message += "\nUncommitted changes:\n#{repo_status}" if params[:show_uncommitted_changes]
    if params[:show_diff]
      repo_diff = Actions.sh("git diff")
      error_message += "\nGit diff: \n#{repo_diff}"
    end
    UI.user_error!(error_message)
  end
end