Skip to content

Commit

Permalink
fix: many issues with list changed files
Browse files Browse the repository at this point in the history
close #655
  • Loading branch information
Vinzent03 committed Jan 31, 2024
1 parent 20d5204 commit 8b3fc8b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/gitManager/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class IsomorphicGit extends GitManager {
const conflicted: string[] = [];
window.clearTimeout(timeout);
notice?.hide();
return { changed, staged, conflicted };
return { all: status, changed, staged, conflicted };
} catch (error) {
window.clearTimeout(timeout);
notice?.hide();
Expand Down Expand Up @@ -629,7 +629,7 @@ export class IsomorphicGit extends GitManager {
}
}

async branchIsMerged(branch: string): Promise<boolean> {
async branchIsMerged(_: string): Promise<boolean> {
return true;
}

Expand Down Expand Up @@ -826,7 +826,7 @@ export class IsomorphicGit extends GitManager {
await this.setConfig(`branch.${branch}.remote`, remote);
}

updateGitPath(gitPath: string): void {
updateGitPath(_: string): void {
// isomorphic-git library has its own git client
return;
}
Expand Down Expand Up @@ -1109,8 +1109,8 @@ export class IsomorphicGit extends GitManager {
return diff;
} else {
let workdirContent: string;
if (await app.vault.adapter.exists(vaultPath)) {
workdirContent = await app.vault.adapter.read(vaultPath);
if (await this.app.vault.adapter.exists(vaultPath)) {
workdirContent = await this.app.vault.adapter.read(vaultPath);
} else {
workdirContent = "";
}
Expand Down
40 changes: 16 additions & 24 deletions src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,23 @@ export class SimpleGit extends GitManager {
this.plugin.setState(PluginState.status);
const status = await this.git.status((err) => this.onError(err));
this.plugin.setState(PluginState.idle);
return {
changed: status.files
.filter((e) => e.working_dir !== " ")
.map((e) => {
const res = this.formatPath(e);

return <FileStatusResult>{
path: res.path,
from: res.from,
working_dir:
e.working_dir === "?" ? "U" : e.working_dir,
vault_path: this.getVaultPath(res.path),
};
}),
staged: status.files
.filter((e) => e.index !== " " && e.index != "?")
.map((e) => {
const res = this.formatPath(e, e.index === "R");
return <FileStatusResult>{
path: res.path,
from: res.from,
index: e.index,
vault_path: this.getVaultPath(res.path),
};
}),
const allFilesFormatted = status.files.map<FileStatusResult>((e) => {
const res = this.formatPath(e);
return {
path: res.path,
from: res.from,
index: e.index === "?" ? "U" : e.index,
working_dir: e.working_dir === "?" ? "U" : e.working_dir,
vault_path: this.getVaultPath(res.path),
};
});
return {
all: allFilesFormatted,
changed: allFilesFormatted.filter((e) => e.working_dir !== " "),
staged: allFilesFormatted.filter(
(e) => e.index !== " " && e.index != "U"
),
conflicted: status.conflicted.map(
(path) => this.formatPath({ path }).path
),
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ export default class ObsidianGit extends Plugin {
id: "add-to-gitignore",
name: "Add file to gitignore",
checkCallback: (checking) => {
const file = app.workspace.getActiveFile();
const file = this.app.workspace.getActiveFile();
if (checking) {
return file !== null;
} else {
app.vault.adapter
this.app.vault.adapter
.append(
this.gitManager.getVaultPath(".gitignore"),
"\n" +
Expand Down Expand Up @@ -491,13 +491,14 @@ export default class ObsidianGit extends Plugin {
if (!(await this.isAllInitialized())) return;

const status = await this.gitManager.status();
console.log(status);
this.setState(PluginState.idle);
if (status.changed.length + status.staged.length > 500) {
this.displayError("Too many changes to display");
return;
}

new ChangedFilesModal(this, status.changed).open();
new ChangedFilesModal(this, status.all).open();
},
});

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface Author {
}

export interface Status {
all: FileStatusResult[];
changed: FileStatusResult[];
staged: FileStatusResult[];
conflicted: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/ui/modals/changedFilesModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ChangedFilesModal extends FuzzySuggestModal<FileStatusResult> {
let index = "";

if (item.working_dir != " ")
working_dir = `Working dir: ${item.working_dir} `;
working_dir = `Working Dir: ${item.working_dir} `;
if (item.index != " ") index = `Index: ${item.index}`;

return `${working_dir}${index} | ${item.vault_path}`;
Expand Down

0 comments on commit 8b3fc8b

Please sign in to comment.