Skip to content

Commit

Permalink
fix: limit amount of files to list in commit msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Jun 19, 2024
1 parent a6d6175 commit a0416ed
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/gitManager/gitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,27 @@ export abstract class GitManager {
status = status ?? (await this.status());

const changeset: { [key: string]: string[] } = {};
status.staged.forEach((value: FileStatusResult) => {
if (value.index in changeset) {
changeset[value.index].push(value.path);
} else {
changeset[value.index] = [value.path];
let files = "";
// If there are more than 100 files, we don't list them all
if (status.staged.length < 100) {
status.staged.forEach((value: FileStatusResult) => {
if (value.index in changeset) {
changeset[value.index].push(value.path);
} else {
changeset[value.index] = [value.path];
}
});

const chunks = [];
for (const [action, files] of Object.entries(changeset)) {
chunks.push(action + " " + files.join(" "));
}
});

const chunks = [];
for (const [action, files] of Object.entries(changeset)) {
chunks.push(action + " " + files.join(" "));
files = chunks.join(", ");
} else {
files = "Too many files to list";
}

const files = chunks.join(", ");

template = template.replace("{{files}}", files);
}

Expand All @@ -275,14 +281,15 @@ export abstract class GitManager {
moment().format(this.plugin.settings.commitDateFormat)
);
if (this.plugin.settings.listChangedFilesInMessageBody) {
template =
template +
"\n\n" +
"Affected files:" +
"\n" +
(status ?? (await this.status())).staged
.map((e) => e.path)
.join("\n");
const status2 = status ?? (await this.status());
let files = "";
// If there are more than 100 files, we don't list them all
if (status2.staged.length < 100) {
files = status2.staged.map((e) => e.path).join("\n");
} else {
files = "Too many files to list";
}
template = template + "\n\n" + "Affected files:" + "\n" + files;
}
return template;
}
Expand Down

0 comments on commit a0416ed

Please sign in to comment.