Skip to content

Commit

Permalink
Wait for git extension to load to get path
Browse files Browse the repository at this point in the history
The path is essential to run Git Mob commands it the right folder

#44
  • Loading branch information
rkotze committed Oct 11, 2020
1 parent c48811f commit 7feb106
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
18 changes: 11 additions & 7 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ const { mob } = require("./src/git/commands");
const { setupGitMob } = require("./src/setup-git-mob");
const { GitExt } = require("./src/vscode-git-extension/git-ext");
const { installPrompt } = require("./src/install-prompt");
const { waitForRepos } = require("./src/wait-for-repos");

function activate(context) {
if (mob.gitMobLatest() === 1) {
installPrompt(() => {
setupGitMob(context, new GitExt());
});
} else {
setupGitMob(context, new GitExt());
}
const gitExt = new GitExt();
waitForRepos(gitExt, () => {
if (mob.gitMobLatest() === 1) {
installPrompt(() => {
setupGitMob(context, gitExt);
});
} else {
setupGitMob(context, gitExt);
}
});
}
exports.activate = activate;

Expand Down
17 changes: 1 addition & 16 deletions src/setup-git-mob.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,11 @@ const {
const { soloAfterCommit } = require("./ext-config/solo-after-commit");
const { searchGithubAuthors } = require("./commands/github-authors");

const MAX_RETRIES = 5;

function setupGitMob(context, gitExt) {
gitExt.gitApi.onDidOpenRepository(function () {
bootGitMob(context, gitExt);
});

waitForRepos(gitExt, MAX_RETRIES, () => {
bootGitMob(context, gitExt);
});
}

function waitForRepos(gitExt, retries, bootFn) {
if (gitExt.hasRepositories) {
bootFn();
} else {
if (retries > 0) {
setTimeout(() => waitForRepos(hasRepo, retries - 1, bootFn), 1000);
}
}
bootGitMob(context, gitExt);
}

function bootGitMob(context, gitExt) {
Expand Down
11 changes: 11 additions & 0 deletions src/wait-for-repos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function waitForRepos(gitExt, bootFn, retries = 5) {
if (gitExt.hasRepositories) {
bootFn();
} else {
if (retries > 0) {
setTimeout(() => waitForRepos(gitExt, bootFn, retries - 1), 1000);
}
}
}

exports.waitForRepos = waitForRepos;

0 comments on commit 7feb106

Please sign in to comment.