This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to remap URLs before opening (#24)
This adds two options: sourcegraph.ignoreRemoteHostname: strips the hostname from a git-based remote. For example, `[email protected]:repo` becomes just `repo` if this is true sourcegraph.remoteUrlPrepend: a mapping from string -> string that allows simple remapping of remote names. If the remote hostname (user@host) matches the key, the value is prepended to the remote. For example, if this is `{"[email protected]": "two/"}, the repo `[email protected]:repo` becomes `two/repo` Fixes #8
- Loading branch information
1 parent
a9f62a9
commit e2ee51d
Showing
4 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import execa from 'execa' | ||
import * as path from 'path' | ||
import { log } from './log' | ||
import { getRemoteUrlReplacements } from './config' | ||
|
||
/** | ||
* Returns the names of all git remotes, e.g. ["origin", "foobar"] | ||
|
@@ -15,7 +16,15 @@ async function gitRemotes(repoDir: string): Promise<string[]> { | |
* e.g. `origin` -> `[email protected]:foo/bar` | ||
*/ | ||
async function gitRemoteURL(repoDir: string, remoteName: string): Promise<string> { | ||
const { stdout } = await execa('git', ['remote', 'get-url', remoteName], { cwd: repoDir }) | ||
let { stdout } = await execa('git', ['remote', 'get-url', remoteName], { cwd: repoDir }) | ||
const replacementsList = getRemoteUrlReplacements() | ||
|
||
for (const r in replacementsList) { | ||
if (typeof r === 'string') { | ||
stdout = stdout.replace(r, replacementsList[r]) | ||
} | ||
} | ||
|
||
return stdout | ||
} | ||
|
||
|