-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add support for main
as the default branch
#204
base: master
Are you sure you want to change the base?
Add support for main
as the default branch
#204
Conversation
main
as the default branch
Heya @yonaskolb! Just wanted to check if you had time to look at this, or had any comments/questions about it. Thank you 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rastersize, great change. Note sure it always works though.
Could you also please add a changelog entry
@@ -15,7 +15,7 @@ class PackageCommand: MintfileCommand { | |||
\(description) | |||
|
|||
The package can be a shorthand for a github repo \"githubName/repo\", or a fully qualified .git path. | |||
An optional version can be specified by appending @version to the repo, otherwise the newest tag will be used (or master if no tags are found.) | |||
An optional version can be specified by appending @version to the repo, otherwise the newest tag will be used (or main, then master if no tags are found.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An optional version can be specified by appending @version to the repo, otherwise the newest tag will be used (or main, then master if no tags are found.) | |
An optional version can be specified by appending @version to the repo, otherwise the newest tag will be used, or the default branch if untagged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update the same message in the Readme, under Package reference
@@ -84,6 +84,11 @@ public class Mint { | |||
return gitRepos | |||
} | |||
|
|||
func getDefaultGitBranch() throws -> String { | |||
let refsOutput = try Task.capture(bash: "git ls-remote --heads --quiet | cut -f2 | cut -d'/' -f3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this always works? I tried locally in some repos. Some I got an access error if though they have public remotes:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
And some I just got a list of the branches in the repo, and not just the default branch. I'm on Git 2.24.3 and zsh 5.8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use this in my zsh function, it's a bit different: defaultBranch=$(git ls-remote --symref "$remoteUrl" HEAD | grep "^ref: " | sed 's@^ref: refs/heads/\([^[:space:]]*\).*@\1@')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming pipefail is on, my version will result in an error in the rare case where the default branch is not set, while the original code will probably not result in an error. (I'm not on my dev machine, so I can't check but I'm 99% sure about this)
related git docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-headem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's assume both 1) that the repo was cloned, not created locally, and 2) that the first (or only) remote is the one that matters), this should be as good as it seems to be possible to get within the bounds of what's practical (I know the string extraction is a bit tortured; while either sed
or the new regex support in Swift 5.7 could do this less painfully, sed
is not always dependable between platforms, and 5.7 is a bit of a jump from this project's current minimum supported version of 5.0):
let symref = try Task.capture(bash: "git ls-remote --symref . 'refs/remotes/*/HEAD'")
if symref.starts(with: "ref:") { return symref
.prefix { !$0.isNewline } // "ref: refs/remotes/origin/main refs/remotes/origin/HEAD"
.dropFirst(17) // "origin/main refs/remotes/origin/HEAD"
.drop { $0 != "/" } // "/main refs/remotes/origin/HEAD"
.dropFirst() // "main refs/remotes/origin/HEAD"
.prefix { !$0.isWhitespace } // "main"
} else {
// no remote configured?
return "HEAD" // fall back to current checked out revision
}
The actual default fails to install as per the current `README.md` this is needed until `mint` team support `main` as alternative to `master` Refer: XcodeMigrate#29 yonaskolb/Mint#204
The actual default fails to install as per the current `README.md` this is needed until `mint` team support `main` as alternative to `master` Refer: #29 yonaskolb/Mint#204
GitHub and others are moving to use
main
as the default branch name. In fact newly created repositories use it by default now. The most recent version/commit of Mint fails to clone tools that don’t have any tags and usesmain
:This PR aims to resolve that by adding support for both
main
andmaster
. It should in theory support any name for the default branch as it usesgit
to look up the name of the branch.With this patch the invocation above succeeds:
$ .build/debug/mint run rastersize/apollo-codegen apollo-codegen --help 🌱 Finding latest version of apollo-codegen 🌱 Cloning apollo-codegen main 🌱 Resolving package 🌱 Building package 🌱 Installed apollo-codegen main 🌱 Running apollo-codegen main... OVERVIEW: A utility for performing Apollo GraphQL related tasks. [...]