Skip to content

Commit

Permalink
fix(git): invoke pre-commit hook after changes are written correctly (#…
Browse files Browse the repository at this point in the history
…38)

refactor(git)!: ExecGitCommitSequenceOptions are merged into CommitOptions
  • Loading branch information
hasundue authored Oct 16, 2023
1 parent 6969655 commit 50c4515
Showing 1 changed file with 5 additions and 10 deletions.
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

0 comments on commit 50c4515

Please sign in to comment.