Skip to content

Commit

Permalink
fix: ignore empty stash
Browse files Browse the repository at this point in the history
Ignore "No stash entries found." when stashing
is enabled but no files were actually stashed.

Resolves: #55
  • Loading branch information
saitho committed Nov 27, 2023
1 parent 67192b9 commit 64bc3ab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/perform-backmerge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,45 @@ describe("perform-backmerge", () => {
verify(mockedGit.unstash()).calledAfter(pushAction);
});

it("stash and unstash with empty stash", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getModifiedFiles())
.thenReturn(new Promise<string[]>(resolve => resolve([])));
when(mockedGit.fetch()).thenResolve();
when(mockedGit.commit(anyString())).thenResolve();
when(mockedGit.rebase(anyString())).thenResolve();
when(mockedGit.unstash()).thenThrow(new Error('No stash entries found.'));
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context;

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
clearWorkspace: true,
restoreWorkspace: true
},
context
);
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).once();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

const checkoutDevelopAction = mockedGit.checkout('develop');
verify(mockedGit.stash()).calledBefore(checkoutDevelopAction);
verify(checkoutDevelopAction).once();
verify(mockedGit.rebase('master')).once();

const pushAction = mockedGit.push('my-repo', 'develop', false)
verify(pushAction).once();
verify(mockedGit.unstash()).calledAfter(pushAction);
});

it("merge as backmerge strategy", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
Expand Down
8 changes: 7 additions & 1 deletion src/perform-backmerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ export async function performBackmerge(git: Git, pluginConfig: Partial<Config>,

if (options.restoreWorkspace) {
context.logger.log('Restoring stashed files to Git workspace.');
await git.unstash();
try {
await git.unstash();
} catch (error: any) {
if (error?.message !== 'No stash entries found.') {
throw error;
}
}
}
}

Expand Down

0 comments on commit 64bc3ab

Please sign in to comment.