View Source Bonfire.Common.Extensions.Diff (Bonfire v0.9.10-classic-beta.169)

Provides functionality to generate and parse diffs from git repositories.

Summary

Functions

Analyzes the diff stream from the specified path.

Generates a diff between the specified reference or branch and the latest commit in the repository.

Executes a git command with the specified arguments.

Generates a diff and saves it to the specified output path.

Parses the latest diff from the specified path. See GitDiff.parse_patch/1 for details about what it outputs.

Fetches the latest diff from the specified reference or branch in the repository.

Functions

Link to this function

analyse_repo_latest_diff_stream(path_diff)

View Source

Analyzes the diff stream from the specified path.

This function streams the diff data and processes it as it becomes available. See GitDiff.stream_patch/1 for details on the expected output.

Parameters

  • path_diff: The path to the file containing the diff.

Examples

> {:ok, stream} = Bonfire.Common.Extensions.Diff.analyse_repo_latest_diff_stream("./path/to/diff.patch")
Link to this function

generate_diff(ref_or_branch, repo_path)

View Source

Generates a diff between the specified reference or branch and the latest commit in the repository.

Parameters

  • ref_or_branch: The reference or branch to compare against.
  • repo_path: The path to the repository.

Examples

> Bonfire.Common.Extensions.Diff.generate_diff("main", "./")
{:ok, "Diff generated successfully", "...diff content..."}

> Bonfire.Common.Extensions.Diff.generate_diff("test_fake_branch", "./")
{:error, "Could not generate latest diff."}
Link to this function

git!(args, repo_path \\ ".", into \\ default_into(), original_cwd \\ root())

View Source

Executes a git command with the specified arguments.

Parameters

  • args: The list of arguments for the git command.
  • repo_path: The path to the repository.
  • into: Optional destination for command output (defaults to standard output)
  • original_cwd: The original working directory.

Examples

> Bonfire.Common.Extensions.Diff.git!(["status"], "./")
Link to this function

git_generate_diff(ref_or_branch, repo_path, path_output, extra_opt \\ "--cached")

View Source

Generates a diff and saves it to the specified output path.

Parameters

  • ref_or_branch: The reference or branch to compare against.
  • repo_path: The path to the repository.
  • path_output: The path where the diff output will be saved.
  • extra_opt: Optional extra options for git diff command.

Examples

iex> Bonfire.Common.Extensions.Diff.git_generate_diff("main", "./", "./data/test_output.patch")
Link to this function

git_pre_configure(repo_path)

View Source
Link to this function

parse_repo_latest_diff(path_diff)

View Source

Parses the latest diff from the specified path. See GitDiff.parse_patch/1 for details about what it outputs.

Parameters

  • path_diff: The path to the file containing the diff.

Examples

> Bonfire.Common.Extensions.Diff.parse_repo_latest_diff("./path/to/diff.patch")
{:ok, ...}

> Bonfire.Common.Extensions.Diff.parse_repo_latest_diff("./path/to/empty.patch")
{:error, :no_diff}
Link to this function

repo_latest_diff(ref_or_branch, repo_path, msg \\ nil)

View Source

Fetches the latest diff from the specified reference or branch in the repository.

Parameters

  • ref_or_branch: The reference or branch to compare against.
  • repo_path: The path to the repository.
  • msg: Optional message to include with the diff.

Examples

> Bonfire.Common.Extensions.Diff.repo_latest_diff("main", "./")
{:ok, "Diff message", "...diff content..."}

> Bonfire.Common.Extensions.Diff.repo_latest_diff("test_fake_branch", "./")
{:error, :no_diff}