Skip to content

Commit

Permalink
fix: discard not tracked directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Sep 11, 2024
1 parent cd9ffc2 commit 183929b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ export class SimpleGit extends GitManager {
}

async isTracked(path: string): Promise<boolean> {
const pathExists = await this.app.vault.adapter.exists(
this.getRelativeVaultPath(path)
);
if (!pathExists) {
return false;
}

const inSubmodule = await this.getSubmoduleOfFile(path);
const args = inSubmodule ? ["-C", inSubmodule.submodule] : [];
const relativePath = inSubmodule ? inSubmodule.relativeFilepath : path;
Expand Down Expand Up @@ -365,7 +372,16 @@ export class SimpleGit extends GitManager {

async discard(filepath: string): Promise<void> {
this.plugin.setState(PluginState.add);
await this.git.checkout(["--", filepath], (err) => this.onError(err));
if (await this.isTracked(filepath)) {
await this.git.checkout(["--", filepath], (err) =>
this.onError(err)
);
} else {
await this.app.vault.adapter.rmdir(
this.getRelativeVaultPath(filepath),
true
);
}
this.plugin.setState(PluginState.idle);
}

Expand Down

0 comments on commit 183929b

Please sign in to comment.