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

fix: prefer upstream over origin when getting remote #366

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const tryGit = async (path, ...args) => {

// parse a repo from a git origin into a format
// for a package.json#repository object
const getUrl = async (path) => {
const getRemoteUrl = async (path, remote) => {
try {
const urlStr = await tryGit(path, 'remote', 'get-url', 'origin')
const urlStr = await tryGit(path, 'remote', 'get-url', remote)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~/D/n/c/b/main (latest|✔) $ git remote get-url upstream
error: No such remote 'upstream'
~/D/n/c/b/main (latest|✔) $ echo $status
2

does this gracefully handle if it's missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it will return undefined if its missing and then move to the next remote

const { domain, user, project } = hgi.fromUrl(urlStr)
const url = new URL(`https://${domain}`)
url.pathname = `/${user}/${project}.git`
Expand All @@ -31,6 +31,10 @@ const getUrl = async (path) => {
}
}

const getUrl = async (path) => {
return (await getRemoteUrl(path, 'upstream')) ?? (await getRemoteUrl(path, 'origin'))
}

const getBranches = async (path, branchPatterns) => {
let matchingBranches = new Set()
let matchingPatterns = new Set()
Expand Down