Skip to content

Commit

Permalink
feat: fix clone overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Aug 13, 2022
1 parent 8f28de8 commit d853a4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class IsomorphicGit extends GitManager {
try {
await git.clone({
...this.repo,
dir: dir,
url: url,
onProgress: (progress) => {
(progressNotice as any).noticeEl.innerText = this.getProgressText("Cloning", progress);
Expand Down
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ export default class ObsidianGit extends Plugin {
let dir = await new GeneralModal(this.app, [], "Enter directory for clone. It needs to be empty or not existent.", this.gitManager instanceof IsomorphicGit).open();
if (dir !== undefined) {
dir = normalize(dir);
if (dir === "" || dir === ".") {
const modal = new GeneralModal(this.app, ["NO", "YES"], `Does your remote repo contain a ${app.vault.configDir} directory at the root?`, false, true);
const containsConflictDir = await modal.open() === "YES";
if (containsConflictDir) {
const modal = new GeneralModal(this.app, ["Abort clone", "DELETE"], `To avoid conflicts, the local ${app.vault.configDir} directory needs to be deleted.`, false, true);
const shouldDelete = await modal.open() === "DELETE";
if (shouldDelete) {
await this.app.vault.adapter.rmdir(app.vault.configDir, true);
} else {
new Notice("Aborted clone");
return;
}
}
}
new Notice(`Cloning new repo into "${dir}"`);
await this.gitManager.clone(url, dir);
new Notice("Cloned new repo");
Expand Down

0 comments on commit d853a4e

Please sign in to comment.