Skip to content

Commit 5340397

Browse files
Merge pull request #160 from github/ketchup-lrotschy/automaticallyGetNonOriginRemote
Automatically detect a remote that is not called "origin" so that users don't have to enter the remote name manually
2 parents 268138e + 32ed6f0 commit 5340397

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/git/repository.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ export async function getGitHubUrls(): Promise<GitHubUrls[] | null> {
6666
logDebug("Find `origin` remote for repository", r.rootUri.path);
6767
await r.status();
6868

69-
const originRemote = r.state.remotes.filter(remote => remote.name === remoteName);
70-
if (originRemote.length > 0 && originRemote[0].pushUrl?.indexOf("github.com") !== -1) {
71-
const url = originRemote[0].pushUrl;
69+
// Try to get "origin" remote first
70+
let remote = r.state.remotes.filter(remote => remote.name === remoteName);
71+
72+
// If "origin" does not exist, automatically get another remote
73+
if (r.state.remotes.length !== 0 && remote.length === 0) {
74+
remote = [r.state.remotes[0]];
75+
}
76+
77+
if (remote.length > 0 && remote[0].pushUrl?.indexOf("github.com") !== -1) {
78+
const url = remote[0].pushUrl;
7279

7380
return {
7481
workspaceUri: r.rootUri,

0 commit comments

Comments
 (0)