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

Commits that edit the same file squash into the first #3743

Open
grahamc opened this issue Feb 20, 2025 · 2 comments · Fixed by DeterminateSystems/propose-release#2 · May be fixed by #3744
Open

Commits that edit the same file squash into the first #3743

grahamc opened this issue Feb 20, 2025 · 2 comments · Fixed by DeterminateSystems/propose-release#2 · May be fixed by #3744

Comments

@grahamc
Copy link

grahamc commented Feb 20, 2025

I'm using this in a GitHub Actions workflow that edits a few files in separate commits, and then PR's them. I've found that if two separate commits touch the same file, this action squashes all those edits into the first commit that edited the file.

I have a two examples to demonstrate the problem.

Three commits, each editing a log file and each creating a new file

In this example I have three steps (1,2,3) that append "step-N" to a file named log, create an empty file step-N, and make a commit for that step. When this is PR'd, it ends up with:

  • step-1 commit: create the step-1 file, and step-1, step-2, and step-3, in the log file.
  • step-2 commit: only create the step-2 file
  • step-3 commit: only create the step-3 file

I would instead expect step-1 commit to only include the step-1 line in the log, and step-2 and step-3 log lines to appear in their respective commits.

on:
  workflow_dispatch:

jobs:
  make-pr:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
    env:
      GIT_COMMITTER_NAME: example
      GIT_COMMITTER_EMAIL: example@example.com
      GIT_AUTHOR_NAME: example
      GIT_AUTHOR_EMAIL: example@example.com

    steps:
      - uses: actions/checkout@v4
      - run: |
          echo "step-1" >> log
          touch step-1
          git add log step-1
          git commit -m "step-1"
      - run: |
          echo "step-2" >> log
          touch step-2
          git add log step-2
          git commit -m "step-2"
      - run: |
          echo "step-3" >> log
          touch step-3
          git add log step-3
          git commit -m "step-3"
        
      - uses: peter-evans/create-pull-request@v7
        with:
          branch: example-patches
          delete-branch: true
          sign-commits: true
          title: step 1, 2, and 3
          body: |
            hello world

Three commits, each only editing a log file

In this example I have three steps (1,2,3) that append "step-N" to a file named log and make a commit for that step. When this is PR'd, it ends up with:

  • step-1 commit: create the log file with the log lines from all three steps: step-1, step-2, and step-3.
  • step-2 commit: an empty commit
  • step-3 commit: an empty commit

I would instead expect step-1 commit to only include the step-1 line in the log, and step-2 and step-3 log lines to appear in their respective commits.

on:
  workflow_dispatch:

jobs:
  make-pr:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
    env:
      GIT_COMMITTER_NAME: example
      GIT_COMMITTER_EMAIL: example@example.com
      GIT_AUTHOR_NAME: example
      GIT_AUTHOR_EMAIL: example@example.com

    steps:
      - uses: actions/checkout@v4
      - run: |
          echo "step-1" >> log
          git add log
          git commit -m "step-1"
      - run: |
          echo "step-2" >> log
          git add log
          git commit -m "step-2"
      - run: |
          echo "step-3" >> log
          git add log
          git commit -m "step-3"
        
      - uses: peter-evans/create-pull-request@v7
        with:
          branch: example-patches
          delete-branch: true
          sign-commits: true
          title: step 1, 2, and 3
          body: |
            hello world

--

Overall, I would expect each commit to be submitted in the pull request as originally committed, instead of having the changes squash.

@grahamc
Copy link
Author

grahamc commented Feb 20, 2025

I think the problem is here:

const {data: blob} = await blobCreationLimit(() =>
this.octokit.rest.git.createBlob({
...repository,
content: utils.readFileBase64([repoPath, path]),

where it is probably reading the file from the final commit, but putting it into a specific commit.

I wonder if this would be better:

git show 58f8ea8fcc8e07c2d066388e21e20d2302f61cfc:./.github/workflows/workflow.yml

...though looking at the implementation of symlinks in readFileBase64, I'm not sure...

it works perfectly:

% ls -la bar
lrwxr-xr-x  1 grahamc  staff  11 Feb 20 14:57 bar -> ./README.md

% git show 0ce9c743878a568d7adf7e03e3f60da501235c77:./bar
./README.md

@grahamc
Copy link
Author

grahamc commented Feb 20, 2025

Arg, I am ... surprised ... I was able to close an issue on your repo from my repo ... but I don't have permission to reopen it 🤷.

@peter-evans peter-evans reopened this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants