Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(git): invoke pre-commit hook after changes are written correctly #38

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions git/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface CommitProps {
export interface CommitOptions {
groupBy?: (dependency: DependencyUpdate) => string;
composeCommitMessage?: (props: CommitProps) => string;
preCommit?: (commit: GitCommit) => void;
postCommit?: (commit: GitCommit) => void;
gitAddOptions?: string[];
gitCommitOptions?: string[];
}
Expand Down Expand Up @@ -73,18 +75,12 @@ export interface GitCommitSequence {
options: CommitOptions;
}

export interface ExecGitCommitSequenceOptions {
preCommit?: (commit: GitCommit) => void;
postCommit?: (commit: GitCommit) => void;
}

export function commitAll(
updates: DependencyUpdate[],
options?: CommitOptions & ExecGitCommitSequenceOptions,
options?: CommitOptions,
): void {
execGitCommitSequence(
createGitCommitSequence(updates, options),
options,
);
}

Expand Down Expand Up @@ -115,12 +111,9 @@ function createGitCommitSequence(

function execGitCommitSequence(
sequence: GitCommitSequence,
options?: ExecGitCommitSequenceOptions,
) {
for (const commit of sequence.commits) {
options?.preCommit?.(commit);
execGitCommit(commit, sequence.options);
options?.postCommit?.(commit);
}
}

Expand All @@ -130,8 +123,10 @@ function execGitCommit(
) {
const results = FileUpdate.collect(commit.updates);
FileUpdate.writeAll(results);
options?.preCommit?.(commit);
_add(results, options?.gitAddOptions ?? []);
_commit(commit.message, options?.gitCommitOptions ?? []);
options?.postCommit?.(commit);
}

function _add(
Expand Down