-
Notifications
You must be signed in to change notification settings - Fork 130
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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:
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 commentThe reason will be displayed to describe this comment to others. Learn more. I use this in my zsh function, it's a bit different: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 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
} |
||
return refsOutput.stdout | ||
} | ||
|
||
func getLinkedExecutables() -> [Path] { | ||
guard linkPath.exists, | ||
let packages = try? linkPath.children() else { | ||
|
@@ -164,14 +169,14 @@ public class Mint { | |
|
||
let tagReferences = tagOutput.stdout | ||
if tagReferences.isEmpty { | ||
package.version = "master" | ||
package.version = try getDefaultGitBranch() | ||
} else { | ||
let tags = tagReferences.split(separator: "\n").map { String($0.split(separator: "\t").last!.split(separator: "/").last!) } | ||
let versions = convertTagsToVersionMap(tags) | ||
if let latestVersion = versions.keys.sorted().last, let tag = versions[latestVersion] { | ||
package.version = tag | ||
} else { | ||
package.version = "master" | ||
package.version = try getDefaultGitBranch() | ||
} | ||
} | ||
} catch { | ||
|
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.
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