ILikePlayingGames / line-diff-action

Gets the git diff between two commits, formats it using Delta, and writes it to `./diff.txt`.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

line-diff-action status

Line Diff V1


This action gets the line by line differences between two commits and formats the result using Delta. The result is then written to ./diff.txt on the runner. It cannot be passed as a step output or an environment variable due to the ANSI escape codes and other special characters that may be present in the diff.

Usage


The Checkout action checks out just the commit at HEAD by default. Make sure fetch-depth is set to the number of commits between the commit hash you want to diff and HEAD so both commits are fetched. Please see the checkout action repository linked above for more details about the use of the fetch-depth parameter.

Options

Parameter Required Description
commit-hash true The commit hash to compare to HEAD, or second-commit-hash if provided
second-commit-hash false The commit hash to compare the first commit hash to, defaults to HEAD
diff-algorithm false The git diff algorithm to use (see man page for details
delta-theme false The name of the theme that Delta will use to format the diff (see the delta theme list for options

Diff Previous Commit and HEAD

- uses: actions/checkout@v4
  with:
    # Fetch HEAD and the commit before it
    fetch-depth: 2
  # Get the formatted line-by-line diff
- id: get_diff
  uses: ILikePlayingGames/line-diff
  with:
    commit-hash: '@~'
  # Read ./diff.txt in your next step to use the diff.
- run: cat ./diff.txt

Diff Specific Commit and HEAD

  - uses: actions/checkout@v4
    with:
      # Make sure fetch depth is set to include
      # the commit hash below.
      fetch-depth: 0
  # Get the formatted line-by-line diff
  - id: get_diff
    uses: ILikePlayingGames/line-diff
    with:
      commit-hash: '7a118f3040c7cbe7373bc03783a3e65d5cd42cd4'
  # Read ./diff.txt in your next step to use the diff.
  - run: cat ./diff.txt

Diff Two Arbitrary Commits

- uses: actions/checkout@v4
  with:
    # Make sure fetch depth is set to include
    # the commit hashes below.
    fetch-depth: 0
# Get the formatted line-by-line diff
- id: get_diff
  uses: ILikePlayingGames/line-diff
  with:
    commit-hash: '7a118f3040c7cbe7373bc03783a3e65d5cd42cd4'
    second-commit-hash: 'a757538ac02bdb031ad72c00f7966bffa1f4349b'
  # Read ./diff.txt in your next step to use the diff.
- run: cat ./diff.txt

Diff With Different Algorithm

- uses: actions/checkout@v4
  with:
    # Make sure fetch depth is set to include
    # the commit hash below.
    fetch-depth: 0
# Get the formatted line-by-line diff
- id: get_diff
  uses: ILikePlayingGames/line-diff
  with:
    commit-hash: '7a118f3040c7cbe7373bc03783a3e65d5cd42cd4'
    # Please see git-diff documentation for options
    diff-algorithm: 'minimal'
  # Read ./diff.txt in your next step to use the diff.
- run: cat ./diff.txt

Use a custom theme

- uses: actions/checkout@v4
  with:
    # Fetch HEAD and the commit before it
    fetch-depth: 2
  # Get the formatted line-by-line diff
- id: get_diff
  uses: ILikePlayingGames/line-diff
  with:
    commit-hash: '@~'
    # Use the discord-dark custom theme
    delta-theme: discord-dark
  # Read ./diff.txt in your next step to use the diff.
- run: cat ./diff.txt

Credits


This action uses Delta to generate the formatted diffs. Thank you, @hrueger, for sharing the piped command workaround!

About

Gets the git diff between two commits, formats it using Delta, and writes it to `./diff.txt`.

License:MIT License


Languages

Language:TypeScript 95.7%Language:JavaScript 4.3%