From cee56c40edd9000abf0d0b5b5099382b2659c183 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Sat, 16 Sep 2023 19:17:16 -0700 Subject: [PATCH] fix: prefer upstream over origin when getting remote Fixes #363 --- lib/util/git.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/util/git.js b/lib/util/git.js index 1b35f660..c28760db 100644 --- a/lib/util/git.js +++ b/lib/util/git.js @@ -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) const { domain, user, project } = hgi.fromUrl(urlStr) const url = new URL(`https://${domain}`) url.pathname = `/${user}/${project}.git` @@ -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()