Skip to content

Commit

Permalink
fix(mobile): set correct base path after clone
Browse files Browse the repository at this point in the history
close #282
  • Loading branch information
Vinzent03 committed Aug 21, 2022
1 parent ad74e0b commit 3a69b79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"isomorphic-git": "^1.19.1",
"supports-color": "^7.2.0",
"buffer": "^6.0.3",
"path-normalize": "^6.0.6",
"simple-git": "^3.12.0"
},
"moduleFileExtensions": [
Expand Down
24 changes: 18 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce, Debouncer, EventRef, Menu, Notice, Plugin, TAbstractFile, TFile } from "obsidian";
import { debounce, Debouncer, EventRef, Menu, normalizePath, Notice, Plugin, TAbstractFile, TFile } from "obsidian";
import { PromiseQueue } from "src/promiseQueue";
import { ObsidianGitSettingsTab } from "src/settings";
import { StatusBar } from "src/statusBar";
Expand All @@ -14,7 +14,6 @@ import DiffView from "./ui/diff/diffView";
import { GeneralModal } from "./ui/modals/generalModal";
import { IgnoreModal } from "./ui/modals/ignoreModal";
import GitView from "./ui/sidebar/sidebarView";
const normalize = require("path-normalize");

export default class ObsidianGit extends Plugin {
gitManager: GitManager;
Expand Down Expand Up @@ -496,13 +495,26 @@ export default class ObsidianGit extends Plugin {
}

async cloneNewRepo() {
console.log(normalizePath(""));
console.log(normalizePath("."));
console.log(normalizePath("/"));
console.log(normalizePath("./"));

const modal = new GeneralModal(this.app, [], "Enter remote URL");
const url = await modal.open();
if (url) {
let dir = await new GeneralModal(this.app, [], "Enter directory for clone. It needs to be empty or not existent.", this.gitManager instanceof IsomorphicGit).open();
let dir = await new GeneralModal(this.app, ["Vault root"], "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 === ".") {
if (dir === "Vault root") {
dir = ".";
}

dir = normalizePath(dir);
if (dir === "/") {
dir = ".";
}

if (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();
if (containsConflictDir === undefined) {
Expand All @@ -524,7 +536,7 @@ export default class ObsidianGit extends Plugin {
new Notice("Cloned new repo.");
new Notice("Please restart Obsidian");

if (dir) {
if (dir && dir !== ".") {
this.settings.basePath = dir;
this.saveSettings();
}
Expand Down
8 changes: 7 additions & 1 deletion src/ui/modals/generalModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export class GeneralModal extends SuggestModal<string> {
}

selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void {
if (this.resolve) this.resolve((this.allowEmpty && value === " ") ? "" : value);
if (this.resolve) {
let res;
if (this.allowEmpty && value === " ") res = "";
else if (value === "...") res = undefined;
else res = value;
this.resolve(res);
}
super.selectSuggestion(value, evt);
}

Expand Down

0 comments on commit 3a69b79

Please sign in to comment.