Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match init assumes a default branch of master when using git storage, which is no longer the Github default #21879

Open
4 tasks done
gemmakbarlow opened this issue Feb 17, 2024 · 1 comment

Comments

@gemmakbarlow
Copy link

gemmakbarlow commented Feb 17, 2024

New Issue Checklist

Issue Description

After setting up a new app recently with fastlane match I noticed the default Matchfile generate assumes GitHub's default branch to be master, not main. main is now the default for all new GitHub repositories - see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches#about-the-default-branch and this caused a small amount of reconfiguration work.

I'd suggest we should now be prompting for a default branch name on match init, and fallback to master if none is provided.

If there's agreement, happy to PR that.

Command executed

fastlane match init

Complete output when running fastlane, including the stack trace and command used
  • N / A

Environment

  • N / A
@lacostej
Copy link
Collaborator

It sounds like a good idea. Here are 2 complementing ideas to your proposal:

  1. we try detect the default branch name.
def default_git_branch
  default_branch  = Fastlane::Actions.git_remote_branch_name(nil)
  default_branch = default_branch.split("\n")[0] if default_branch
  default_branch ||= "main"
end

or

def default_git_branch
  begin
    first_remote = Fastlane::Actions.sh("git remote | head -1", log: false).chomp
    default_branch = Fastlane::Actions.git_remote_branch_name(first_remote)
  rescue => e
  end
  default_branch ||= "main"
end

Also I am using here "main" as default branch. Any reason we should stick to master? We will eventually have to change, right?

Side note: I wish the git_remote_branch_name method was fixed to only return the head of the first remote. We could maybe add a fix for that first. It doesn't really make sense to return a "master\nmaster" if you have 2 remotes with master as default branch. It would also make this code simpler, something like

def default_git_branch
  default_branch  = Fastlane::Actions.git_remote_branch_name(nil)
  default_branch ||= "main"
end
  1. if we really want to ask the user, we could combine asking the user and identifying the default_branch using the above code as first default choice.

Feel free to start your PR, consider using one of the 2 options above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants