Skip to content

Commit

Permalink
fix: git log --pretty delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
tuchk4 committed Mar 2, 2020
1 parent 67fbfc3 commit 1e96cbd
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,31 @@ export interface CommitListItem {
}

export function listCommits(from: string, to: string = ""): CommitListItem[] {
// Prints "<short-hash>;<ref-name>;<summary>;<date>"
// Prints "hash<short-hash> ref<ref-name> message<summary> date<date>"
// This format is used in `getCommitInfos` for easily analize the commit.
return execa
.sync("git", ["log", "--oneline", "--pretty=%h;%D;%s;%cd", "--date=short", `${from}..${to}`])
.sync("git", [
"log",
"--oneline",
"--pretty=hash<%h> ref<%D> message<%s> date<%cd>",
"--date=short",
`${from}..${to}`,
])
.stdout.split("\n")
.filter(Boolean)
.map((commit: string) => {
const parts = commit.split(";");
const sha = parts[0];
const refName = parts[1];
const summary = parts[2];
const date = parts[3];
const parts = commit.match(/hash<(.+)> ref<(.*)> message<(.*)> date<(.*)>/) || [];

if (!parts) {
return null;
}

const sha = parts[1];
const refName = parts[2];
const summary = parts[3];
const date = parts[4];

return { sha, refName, summary, date };
});
})
.filter(Boolean);
}

0 comments on commit 1e96cbd

Please sign in to comment.