class Fastlane::Actions::GitSwitchBranchAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 24
def self.authors
  ["zhangqi"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 37
def self.available_options
  [
      FastlaneCore::ConfigItem.new(key: :branch,
                                   env_name: "FL_ENSURE_GIT_BRANCH_NAME",
                                   description: "The branch that should be checked for. String that can be either the full name of the branch or a regex to match",
                                   is_string: true,
                                   default_value: 'master')
  ]
end
description() click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 20
def self.description
  "switch to branch"
end
details() click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 32
def self.details
  # Optional:
  "ensure git switch to branch"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 47
def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
  #
  # [:ios, :mac, :android].include?(platform)
  true
end
return_value() click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 28
def self.return_value
  # If your method provides a return value, you can describe here what it does
end
run(params) click to toggle source
# File lib/fastlane/plugin/git_switch_branch/actions/git_switch_branch_action.rb, line 4
def self.run(params)
  branch = params[:branch]
  branch_expr = /#{branch}/
  if Actions.git_branch =~ branch_expr
    UI.success("Git branch match `#{branch}`, all good! 💪")
  else
    Actions.sh('git checkout .')
    result = Actions.sh("git checkout #{branch}")
    if result =~ /error:(.)/
      UI.error("Git is not on a branch matching `#{branch}`. Current branch is `#{now_branch}`! Reasoin: #{result}.")
    else
      UI.success("Git branch match `#{branch}`, all good! 💪")
    end
  end
end