Skip to content

Commit 6bdf043

Browse files
authored
feat(plugin-git): make git: protocol default to HEAD (#2557)
* feat(plugin-git): make git: protocol default to HEAD * test: update snapshot
1 parent 6ef152b commit 6bdf043

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

.yarn/versions/a278601e.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/plugin-git": minor
4+
"@yarnpkg/plugin-github": minor
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-init"
12+
- "@yarnpkg/plugin-interactive-tools"
13+
- "@yarnpkg/plugin-node-modules"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-pack"
16+
- "@yarnpkg/plugin-patch"
17+
- "@yarnpkg/plugin-pnp"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"

packages/plugin-git/sources/__snapshots__/gitUtils.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Object {
9494
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
9595
"treeish": Object {
9696
"protocol": "head",
97-
"request": "master",
97+
"request": "HEAD",
9898
},
9999
}
100100
`;
@@ -164,7 +164,7 @@ Object {
164164
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
165165
"treeish": Object {
166166
"protocol": "head",
167-
"request": "master",
167+
"request": "HEAD",
168168
},
169169
}
170170
`;
@@ -175,7 +175,7 @@ Object {
175175
"repo": "https://github.com/GitHubOrg/foo2bar.js.git",
176176
"treeish": Object {
177177
"protocol": "head",
178-
"request": "master",
178+
"request": "HEAD",
179179
},
180180
}
181181
`;
@@ -241,7 +241,7 @@ Object {
241241
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
242242
"treeish": Object {
243243
"protocol": "head",
244-
"request": "master",
244+
"request": "HEAD",
245245
},
246246
}
247247
`;

packages/plugin-git/sources/gitUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function splitRepoUrl(url: string): RepoUrlParts {
6060
repo: url,
6161
treeish: {
6262
protocol: TreeishProtocols.Head,
63-
request: `master`,
63+
request: `HEAD`,
6464
},
6565
extra: {},
6666
};
@@ -89,7 +89,7 @@ export function splitRepoUrl(url: string): RepoUrlParts {
8989
request = extra[requestedProtocol]! as string;
9090
} else {
9191
protocol = TreeishProtocols.Head;
92-
request = `master`;
92+
request = `HEAD`;
9393
}
9494

9595
for (const key of Object.values(TreeishProtocols))
@@ -176,7 +176,7 @@ export async function lsRemote(repo: string, configuration: Configuration) {
176176

177177
let res: {stdout: string};
178178
try {
179-
res = await execUtils.execvp(`git`, [`ls-remote`, `--refs`, normalizedRepoUrl], {
179+
res = await execUtils.execvp(`git`, [`ls-remote`, normalizedRepoUrl], {
180180
cwd: configuration.startingCwd,
181181
env: makeGitEnvironment(),
182182
strict: true,
@@ -188,7 +188,7 @@ export async function lsRemote(repo: string, configuration: Configuration) {
188188

189189
const refs = new Map();
190190

191-
const matcher = /^([a-f0-9]{40})\t(refs\/[^\n]+)/gm;
191+
const matcher = /^([a-f0-9]{40})\t([^\n]+)/gm;
192192
let match;
193193

194194
while ((match = matcher.exec(res.stdout)) !== null)
@@ -214,7 +214,7 @@ export async function resolveUrl(url: string, configuration: Configuration) {
214214
}
215215

216216
case TreeishProtocols.Head: {
217-
const head = refs.get(`refs/heads/${request}`);
217+
const head = refs.get(request === `HEAD` ? request : `refs/heads/${request}`);
218218
if (typeof head === `undefined`)
219219
throw new Error(`Unknown head ("${request}")`);
220220

0 commit comments

Comments
 (0)