Class: Fastlane::Actions::EnsureGitStatusCleanAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/ensure_git_status_clean.rb

Overview

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

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



51
52
53
# File 'fastlane/lib/fastlane/actions/ensure_git_status_clean.rb', line 51

def self.author
  ["lmirosevic", "antondomashnev"]
end

.available_optionsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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,
                                 is_string: false),
    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,
                                 is_string: false),
    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,
                                 is_string: true)
  ]
end

.categoryObject



83
84
85
# File 'fastlane/lib/fastlane/actions/ensure_git_status_clean.rb', line 83

def self.category
  :source_control
end

.descriptionObject



33
34
35
# 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

.detailsObject



37
38
39
40
41
42
43
# 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_codeObject



55
56
57
58
59
# File 'fastlane/lib/fastlane/actions/ensure_git_status_clean.rb', line 55

def self.example_code
  [
    'ensure_git_status_clean'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



87
88
89
# File 'fastlane/lib/fastlane/actions/ensure_git_status_clean.rb', line 87

def self.is_supported?(platform)
  true
end

.outputObject



45
46
47
48
49
# 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) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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