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

Option to disable resetting working base branch to its remote #609

Closed
ttshivers opened this issue Oct 14, 2020 · 3 comments
Closed

Option to disable resetting working base branch to its remote #609

ttshivers opened this issue Oct 14, 2020 · 3 comments

Comments

@ttshivers
Copy link

ttshivers commented Oct 14, 2020

I am trying to use this action to add new commits to a PR rather than having it replace the commits. I am running into issues with this action when it tries to reset the working base branch to its remote:

await git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force'])

What I am trying:

      - name: Checkout the testauthor/testrepo repo
        uses: actions/checkout@v2
        with:
          path: testrepo
          repository: testauthor/testrepo

      - name: Track our fork
        run: |
          cd testrepo
          git config user.email "${{ github.actor }}@users.noreply.github.com"
          git config user.name "${{ github.actor }}"
          git remote add bot-fork https://github.com/myuser/testrepo
          git fetch bot-fork
          git checkout -b mybranch --track bot-fork/mybranch

      # Step here that makes changes in testrepo dir

      - name: Commit changes
        run: |
          cd testrepo
          git add -A
          git diff-index --quiet HEAD || git commit -m "MyChange: ${{ github.event.pull_request.title }}"

      - name: Create PR in testauthor/testrepo
        id: create-pr
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.PAT }}
          push-to-fork: myuser/testrepo
          path: testrepo
          base: master
          branch: mybranch
          title: "MyChange: ${{ github.event.pull_request.title }}"
          body: |
            Pull Request: ${{ github.event.pull_request.html_url }}
            @myuser

What happens:
The action ends up failing at

await git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force'])

because it tries to:

/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --unshallow --force origin mybranch:mybranch
  fatal: couldn't find remote ref node
  Error: The process '/usr/bin/git' failed with exit code 128

This fails because there is no mybranch branch on the origin. It only exists on my fork. And even then, it's certainly possible to have the working branch not track any remote, and I would like this action to work in that case. It would be nice to be able to stop this action from trying to reset the working base branch to its remote in cases like these.

@peter-evans
Copy link
Owner

Hi @ttshivers

I can see the current workflow here and it looks like it's setup correctly and working fine. First of all I want to understand what you are trying to do. Correct me if I'm wrong, but it looks like you aren't happy that the action force updates the open PR and resets the commits? You are trying to maintain the update history?

Unfortunately, that is not how this action works and it is a conscious design decision. When a workflow executes the action to create or update a PR, fundamental to the design of the action is that the result of those two paths should not be different. Rebasing the PR branch and adding new commits is the best way to maintain that consistency. I have experimented in the past with trying to keep the full commit history each time the PR branch is updated, but it's more trouble than it's worth.

I notice you are trying to use the feature to control commits. This isn't going to preserve the update history on each execution of the action, if that's what you were expecting. It will reset the branch each time and make a new commit.

There might be a workaround if you really need the commit history on the PR branch. But first of all, I just want to check that I'm understanding the problem you are facing correctly. Please let me know.

@peter-evans
Copy link
Owner

Took another look at this today. I might have misread what your intentions were.

I read this comment in the PR. Did you try that? The action thinks the branch called node is the base of the PR.

I think you might need to add base: master in the action config, otherwise I think it will try and open a PR to a branch named node since that is what is checked out.

@peter-evans
Copy link
Owner

Closing for now, but feel free to continue the conversion if you need further help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants