8000 fix: fetch all tags even if the repo is not shallow · semantic-release/semantic-release@45eee4a · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 45eee4a

Browse files
committed
fix: fetch all tags even if the repo is not shallow
1 parent 2d3a5e5 commit 45eee4a

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const getLastRelease = require('./lib/get-last-release');
1313
const {extractErrors} = require('./lib/utils');
1414
const getGitAuthUrl = require('./lib/get-git-auth-url');
1515
const logger = require('./lib/logger');
16-
const {unshallow, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
16+
const {fetch, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
1717
const getError = require('./lib/get-error');
1818
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
1919

@@ -75,8 +75,7 @@ async function run(options, plugins) {
7575
logger.log('Call plugin %s', 'verify-conditions');
7676
await plugins.verifyConditions({options, logger}, {settleAll: true});
7777

78-
// Unshallow the repo in order to get all the tags
79-
await unshallow(options.repositoryUrl);
78+
await fetch(options.repositoryUrl);
8079

8180
const lastRelease = await getLastRelease(options.tagFormat, logger);
8281
const commits = await getCommits(lastRelease.gitHead, options.branch, logger);

lib/git.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ async function isRefInHistory(ref) {
4949
}
5050

5151
/**
52-
* Unshallow the git repository (retriving every commits and tags).
52+
* Unshallow the git repository if necessary and fetch all the tags.
5353
*
5454
* @param {String} repositoryUrl The remote repository URL.
5555
*/
56-
async function unshallow(repositoryUrl) {
56+
async function fetch(repositoryUrl) {
5757
try {
5858
await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl]);
5959
} catch (err) {
60-
debug(err);
60+
await execa('git', ['fetch', '--tags', repositoryUrl]);
6161
}
6262
}
6363

@@ -164,7 +164,7 @@ module.exports = {
164164
gitTagHead,
165165
gitTags,
166166
isRefInHistory,
167-
unshallow,
167+
fetch,
168168
gitHead,
169169
repoUrl,
170170
isGitRepo,

test/git.test.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import tempy from 'tempy';
33
import {
44
gitTagHead,
55
isRefInHistory,
6-
unshallow,
6+
fetch,
77
gitHead,
88
repoUrl,
99
tag,
@@ -24,6 +24,7 @@ import {
2424
gitCommitTag,
2525
gitRemoteTagHead,
2626
gitPush,
27+
gitDetachedHead,
2728
} from './helpers/git-utils';
2829

2930
// Save the current working diretory
@@ -52,7 +53,7 @@ test.serial('Throw error if the last commit sha cannot be found', async t => {
5253
await t.throws(gitHead(), Error);
5354
});
5455

55-
test.serial('Unshallow repository', async t => {
56+
test.serial('Unshallow and fetch repository', async t => {
5657
// Create a git repository, set the current working directory at the root of the repo
5758
const repo = await gitRepo();
5859
// Add commits to the master branch
@@ -63,7 +64,7 @@ test.serial('Unshallow repository', async t => {
6364
// Verify the shallow clone contains only one commit
6465
t.is((await gitGetCommits()).length, 1);
6566

66-
await unshallow(repo);
67+
await fetch(repo);
6768

6869
// Verify the shallow clone contains all the commits
6970
t.is((await gitGetCommits()).length, 2);
@@ -74,7 +75,24 @@ test.serial('Do not throw error when unshallow a complete repository', async t =
7475
const repo = await gitRepo();
7576
// Add commits to the master branch
7677
await gitCommits(['First']);
77-
await t.notThrows(unshallow(repo));
78+
await t.notThrows(fetch(repo));
79+
});
80+
81+
test.serial('Fetch all tags on a detached head repository', async t => {
82+
const repo = await gitRepo(true);
83+
84+
await gitCommits(['First']);
85+
await gitTagVersion('v1.0.0');
86+
await gitCommits(['Second']);
87+
await gitTagVersion('v1.0.1');
88+
const [commit] = await gitCommits(['Third']);
89+
await gitTagVersion('v1.1.0');
90+
await gitPush();
91+
await gitDetachedHead(repo, commit.hash);
92+
93+
await fetch(repo);
94+
95+
t.deepEqual((await gitTags()).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
7896
});
7997

8098
test.serial('Verify if the commit `sha` is in the direct history of the current branch', async t => {

test/helpers/git-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export async function gitDetachedHead(repositoryUrl, head) {
151151
process.chdir(dir);
152152
await execa('git', ['init']);
153153
await execa('git', ['remote', 'add', 'origin', repositoryUrl]);
154-
await execa('git', ['fetch']);
154+
await execa('git', ['fetch', repositoryUrl]);
155155
await execa('git', ['checkout', head]);
156156
return dir;
157157
}

0 commit comments

Comments
 (0)
0