Skip to content

Commit 3bbe346

Browse files
authored
chore(build): ensure remote information is up-to-date MONGOSH-610 (#683)
1 parent 6f01aaa commit 3bbe346

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

packages/build/src/git/repository-status.spec.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ describe('git repository-status', () => {
1111

1212
describe('verifyGitStatus', () => {
1313
let getRepositoryStatus: sinon.SinonStub;
14+
let spawnSync: sinon.SinonStub;
1415

1516
beforeEach(()=> {
1617
getRepositoryStatus = sinon.stub();
18+
spawnSync = sinon.stub();
1719
});
1820

1921
[ 'master', 'main', 'release/v0.8.0', 'release/v0.8.x' ].forEach(branchName => {
@@ -28,8 +30,9 @@ describe('git repository-status', () => {
2830
hasUnpushedTags: false
2931
};
3032
getRepositoryStatus.returns(status);
31-
const returnedStatus = verifyGitStatus('root', getRepositoryStatus);
33+
const returnedStatus = verifyGitStatus('root', getRepositoryStatus, spawnSync);
3234
expect(returnedStatus).to.equal(status);
35+
expect(spawnSync).to.have.been.calledWith('git', ['fetch', '--tags'], sinon.match.object);
3336
});
3437
});
3538

@@ -40,7 +43,7 @@ describe('git repository-status', () => {
4043
};
4144
getRepositoryStatus.returns(status);
4245
try {
43-
verifyGitStatus('root', getRepositoryStatus);
46+
verifyGitStatus('root', getRepositoryStatus, spawnSync);
4447
} catch (e) {
4548
expect(e.message).to.contain('Could not determine local repository information');
4649
return;
@@ -60,7 +63,7 @@ describe('git repository-status', () => {
6063
};
6164
getRepositoryStatus.returns(status);
6265
try {
63-
verifyGitStatus('root', getRepositoryStatus);
66+
verifyGitStatus('root', getRepositoryStatus, spawnSync);
6467
} catch (e) {
6568
expect(e.message).to.contain('The current branch does not match');
6669
return;
@@ -80,7 +83,7 @@ describe('git repository-status', () => {
8083
};
8184
getRepositoryStatus.returns(status);
8285
try {
83-
verifyGitStatus('root', getRepositoryStatus);
86+
verifyGitStatus('root', getRepositoryStatus, spawnSync);
8487
} catch (e) {
8588
expect(e.message).to.contain('The branch you are on is not tracking any remote branch.');
8689
return;
@@ -100,7 +103,7 @@ describe('git repository-status', () => {
100103
};
101104
getRepositoryStatus.returns(status);
102105
try {
103-
verifyGitStatus('root', getRepositoryStatus);
106+
verifyGitStatus('root', getRepositoryStatus, spawnSync);
104107
} catch (e) {
105108
expect(e.message).to.contain('Your local repository is not clean or diverged from the remote branch');
106109
return;
@@ -120,7 +123,7 @@ describe('git repository-status', () => {
120123
};
121124
getRepositoryStatus.returns(status);
122125
try {
123-
verifyGitStatus('root', getRepositoryStatus);
126+
verifyGitStatus('root', getRepositoryStatus, spawnSync);
124127
} catch (e) {
125128
expect(e.message).to.contain('Your local repository is not clean or diverged from the remote branch');
126129
return;
@@ -140,7 +143,7 @@ describe('git repository-status', () => {
140143
};
141144
getRepositoryStatus.returns(status);
142145
try {
143-
verifyGitStatus('root', getRepositoryStatus);
146+
verifyGitStatus('root', getRepositoryStatus, spawnSync);
144147
} catch (e) {
145148
expect(e.message).to.contain('You have local tags that are not pushed to the remote');
146149
return;

packages/build/src/git/repository-status.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ const RELEASE_BRANCH = /^release\/v([a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+)$/;
1616

1717
export function verifyGitStatus(
1818
repositoryRoot: string,
19-
getRepositoryStatusFn: typeof getRepositoryStatus = getRepositoryStatus
19+
getRepositoryStatusFn: typeof getRepositoryStatus = getRepositoryStatus,
20+
spawnSync: typeof spawnSyncFn = spawnSyncFn
2021
): RepositoryStatus {
22+
spawnSync('git', ['fetch', '--tags'], {
23+
cwd: repositoryRoot,
24+
encoding: 'utf-8'
25+
});
26+
2127
const repositoryStatus = getRepositoryStatusFn(repositoryRoot);
2228
if (!repositoryStatus.branch?.local) {
2329
throw new Error('Could not determine local repository information - please verify your repository is intact.');

0 commit comments

Comments
 (0)