Skip to content

Commit

Permalink
[fastlane][action] fix git_branch when not in a git repo (#18525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Holtz committed Apr 12, 2021
1 parent 5339882 commit 24e54d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/git_branch.rb
Expand Up @@ -2,7 +2,7 @@ module Fastlane
module Actions
class GitBranchAction < Action
def self.run(params)
branch = Actions.git_branch
branch = Actions.git_branch || ""
return "" if branch == "HEAD" # Backwards compatibility with the original (and documented) implementation
branch
end
Expand Down
10 changes: 9 additions & 1 deletion fastlane/lib/fastlane/helper/git_helper.rb
Expand Up @@ -123,7 +123,15 @@ def self.last_git_commit_hash(short)
# Can be replaced using the environment variable `GIT_BRANCH`
def self.git_branch
env_name = SharedValues::GIT_BRANCH_ENV_VARS.find { |env_var| FastlaneCore::Env.truthy?(env_var) }
ENV.fetch(env_name.to_s) { Actions.sh("git rev-parse --abbrev-ref HEAD", log: false).chomp }
ENV.fetch(env_name.to_s) do
# Rescues if not a git repo or no commits in a git repo
begin
Actions.sh("git rev-parse --abbrev-ref HEAD", log: false).chomp
rescue => err
UI.verbose("Error getting git branch: #{err.message}")
nil
end
end
end

private_class_method
Expand Down

0 comments on commit 24e54d7

Please sign in to comment.