Class: Fastlane::Actions::GitCommitAction

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

Constant Summary

Constants inherited from Fastlane::Action

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

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, details, lane_context, method_missing, other_action, return_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



62
63
64
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 62

def self.authors
  ["KrauseFx"]
end

.available_optionsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 37

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :path,
                                 description: "The file you want to commit",
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :message,
                                 description: "The commit message that should be used"),
    FastlaneCore::ConfigItem.new(key: :skip_git_hooks,
                                 description: "Set to true to pass --no-verify to git",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :allow_nothing_to_commit,
                                 description: "Set to true to allow commit without any git changes in the files you want to commit",
                                 type: Boolean,
                                 optional: true)
  ]
end

.categoryObject



79
80
81
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 79

def self.category
  :source_control
end

.descriptionObject



33
34
35
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 33

def self.description
  "Directly commit the given file with the given message"
end

.example_codeObject



70
71
72
73
74
75
76
77
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 70

def self.example_code
  [
    'git_commit(path: "./version.txt", message: "Version Bump")',
    'git_commit(path: ["./version.txt", "./changelog.txt"], message: "Version Bump")',
    'git_commit(path: ["./*.txt", "./*.md"], message: "Update documentation")',
    'git_commit(path: ["./*.txt", "./*.md"], message: "Update documentation", skip_git_hooks: true)'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



66
67
68
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 66

def self.is_supported?(platform)
  true
end

.outputObject



55
56
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 55

def self.output
end

.return_valueObject



58
59
60
# File 'fastlane/lib/fastlane/actions/git_commit.rb', line 58

def self.return_value
  nil
end

.run(params) ⇒ Object



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

def self.run(params)
  if params[:path].kind_of?(String)
    paths = params[:path].shellescape
  else
    paths = params[:path].map(&:shellescape).join(' ')
  end

  skip_git_hooks = params[:skip_git_hooks] ? '--no-verify' : ''

  if params[:allow_nothing_to_commit]
    # Here we check if the path passed in parameter contains any modification
    # and we skip the `git commit` command if there is none.
    # That means you can have other files modified that are not in the path parameter
    # and still make use of allow_nothing_to_commit.
    repo_clean = Actions.sh("git status #{paths} --porcelain").empty?
    UI.success("Nothing to commit, working tree clean ✅.") if repo_clean
    return if repo_clean
  end

  command = "git commit -m #{params[:message].shellescape} #{paths} #{skip_git_hooks}".strip
  result = Actions.sh(command)
  UI.success("Successfully committed \"#{params[:path]}\" 💾.")
  return result
end