Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit 99d89b0

Browse files
committed
feat(commands): Add Sync All command
1 parent 81234ef commit 99d89b0

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎lib/commands/sync-all.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** @babel */
2+
3+
import gitCmd from "../git-cmd";
4+
import Notifications from "../Notifications";
5+
import {command as sync} from "./sync";
6+
7+
export default {
8+
label: "Sync All",
9+
description: "Pull then push all project repos",
10+
confirm: {
11+
message: "Are you sure you want to sync all project repos?"
12+
},
13+
async command(filePaths, statusBar, git = gitCmd, notifications = Notifications, title = "Sync All") {
14+
const syncs = await Promise.all(atom.project.getPaths().map(root => {
15+
return sync(root, statusBar, git, notifications).catch(() => null);
16+
}));
17+
18+
const failed = syncs.filter(p => !p);
19+
let num = "all";
20+
if (failed.length > 0) {
21+
num = syncs.length - failed.length;
22+
}
23+
24+
return {
25+
title,
26+
message: `Synced ${num} repos.`,
27+
};
28+
},
29+
};

‎spec/commands/sync-all-spec.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** @babel */
2+
3+
import syncAll from "../../lib/commands/sync-all";
4+
import sync from "../../lib/commands/sync";
5+
import {removeGitRoot, createGitRoot} from "../mocks";
6+
7+
describe("sync-all", function () {
8+
9+
beforeEach(async function () {
10+
await atom.packages.activatePackage("git-menu");
11+
this.gitRoot1 = await createGitRoot();
12+
this.gitRoot2 = await createGitRoot();
13+
atom.project.setPaths([this.gitRoot1, this.gitRoot2]);
14+
});
15+
16+
afterEach(async function () {
17+
await removeGitRoot(this.gitRoot1);
18+
await removeGitRoot(this.gitRoot2);
19+
});
20+
21+
it("should call sync with project folders", async function () {
22+
spyOn(sync, "command").and.callFake(() => Promise.resolve());
23+
await syncAll.command();
24+
expect(sync.command).toHaveBeenCalledTimes(2);
25+
expect(sync.command.calls.argsFor(0)[0]).toEqual(this.gitRoot1);
26+
expect(sync.command.calls.argsFor(1)[0]).toEqual(this.gitRoot2);
27+
});
28+
});

0 commit comments

Comments
 (0)