mirror of
https://github.com/desktop/desktop
synced 2024-10-01 05:43:50 +00:00
Merge pull request #18876 from desktop/now-you-have-two-problems
Parse remote urls containing spaces
This commit is contained in:
commit
1cc7544c5a
|
@ -21,14 +21,9 @@ export async function getRemotes(
|
|||
return []
|
||||
}
|
||||
|
||||
const output = result.stdout
|
||||
const lines = output.split('\n')
|
||||
const remotes = lines
|
||||
.filter(x => /\(fetch\)( \[.+\])?$/.test(x))
|
||||
.map(x => x.split(/\s+/))
|
||||
.map(x => ({ name: x[0], url: x[1] }))
|
||||
|
||||
return remotes
|
||||
return [...result.stdout.matchAll(/^(.+)\t(.+)\s\(fetch\)/gm)].map(
|
||||
([, name, url]) => ({ name, url })
|
||||
)
|
||||
}
|
||||
|
||||
/** Add a new remote with the given URL. */
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
} from '../../helpers/repositories'
|
||||
import { findDefaultRemote } from '../../../src/lib/stores/helpers/find-default-remote'
|
||||
import { GitProcess } from 'dugite'
|
||||
import { setConfigValue } from '../../../src/lib/git'
|
||||
|
||||
describe('git/remote', () => {
|
||||
describe('getRemotes', () => {
|
||||
|
@ -20,6 +21,7 @@ describe('git/remote', () => {
|
|||
'repo-with-multiple-remotes'
|
||||
)
|
||||
const repository = new Repository(testRepoPath, -1, null, false)
|
||||
await addRemote(repository, 'spaces-in-path', '/path/with spaces/foo')
|
||||
|
||||
// NB: We don't check for exact URL equality because CircleCI's git config
|
||||
// rewrites HTTPS URLs to SSH.
|
||||
|
@ -27,11 +29,18 @@ describe('git/remote', () => {
|
|||
|
||||
const result = await getRemotes(repository)
|
||||
|
||||
// Changes the output of git remote -v, see
|
||||
// https://github.com/git/git/blob/9005149a4a77e2d3409c6127bf4fd1a0893c3495/builtin/remote.c#L1223-L1226
|
||||
setConfigValue(repository, 'remote.bassoon.partialclonefilter', 'foo')
|
||||
|
||||
expect(result[0].name).toEqual('bassoon')
|
||||
expect(result[0].url.endsWith(nwo)).toEqual(true)
|
||||
|
||||
expect(result[1].name).toEqual('origin')
|
||||
expect(result[1].url.endsWith(nwo)).toEqual(true)
|
||||
|
||||
expect(result[2].name).toEqual('spaces-in-path')
|
||||
expect(result[2].url).toEqual('/path/with spaces/foo')
|
||||
})
|
||||
|
||||
it('returns remotes sorted alphabetically', async () => {
|
||||
|
|
Loading…
Reference in a new issue