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

Failing because the branch already exists #245

Closed
bnb opened this issue Oct 29, 2020 · 17 comments · Fixed by #256
Closed

Failing because the branch already exists #245

bnb opened this issue Oct 29, 2020 · 17 comments · Fixed by #256
Labels

Comments

@bnb
Copy link
Contributor

bnb commented Oct 29, 2020

Perhaps I'm just misunderstanding how the branch property in the config is supposed to work, but in using it after the initial run where it was created the Action is failing on every subsequent run with the assertion that git checkout -b <branch> already exists.

Here's an example run:

https://github.com/bnb/node/runs/1327432876

Here's the error:

Remote branch "actions/authors-update" checked out locally.
Branch "actions/authors-update" does not yet exist on remote.
Error: Command failed with exit code 128 (Unknown system error -128): git checkout -b actions/authors-update
    at makeError (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:5673:11)
    at handlePromise (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:7624:26)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runShellCommand (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:707:32)
    at async checkOutRemoteBranch (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:699:5)
    at async main (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:567:32) {
  command: 'git checkout -b actions/authors-update',
  exitCode: 128,
  exitCodeName: 'Unknown system error -128',
  stdout: '',
  stderr: "fatal: A branch named 'actions/authors-update' already exists.",
  all: "fatal: A branch named 'actions/authors-update' already exists.",
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false,
  signal: undefined

@gr2m
Copy link
Owner

gr2m commented Oct 29, 2020

I think this is the same problem as described in #177. I could really use help from a git expert to debug and fix this problem, it's really annoying :( Can you think of someone who might be able to help?

@bnb
Copy link
Contributor Author

bnb commented Oct 29, 2020

perhaps @ethomson could help or knows someone who could? ❤️

@gr2m
Copy link
Owner

gr2m commented Oct 29, 2020

pretty pleeeaaseee?

image

@ethomson
Copy link

Well, here's what I'm seeing. @bnb's run first checks out the actions/authors-update branch locally. In other words, the local branch actions/authors-update will be created to track origin/actions/authors-update.

But the stack trace says that it failed to create a local actions/authors-update branch:

Error: Command failed with exit code 128 (Unknown system error -128): git checkout -b actions/authors-update
    at makeError (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:5673:11)
    at handlePromise (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:7624:26)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runShellCommand (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:707:32)
    at async checkOutRemoteBranch (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:699:5)
    at async main (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:567:32) {

This checkout -b is done in the exception handler.

So... something threw between the checkout step (which sent output indicating its success) and returning from the function.

That means that the runShellCommand that does the cherry-pick failed.

If it were me, I would:

  1. Not assume that an exception means that the remote branch doesn't exist. Instead I'd look for origin/{branch_name}. As we've seen, there are other failure modes.
  2. Log some error messages about the cherry-pick failure.

I don't have a guess yet for why the cherry-pick would fail, but I do think that it's what's failing here.

@gr2m
Copy link
Owner

gr2m commented Oct 29, 2020

Thanks Edward, I'll look into this tomorrow

@bnb
Copy link
Contributor Author

bnb commented Nov 11, 2020

hey @gr2m! 👋🏻

wanted to follow up to see if that was the right path?

@gr2m
Copy link
Owner

gr2m commented Nov 11, 2020

sorry I didn't have a chance to look into it yet, but I have it on my todo list. I'll bump it to the top and keep you posted

gr2m added a commit that referenced this issue Nov 12, 2020
@github-actions github-actions bot mentioned this issue Nov 12, 2020
@gr2m
Copy link
Owner

gr2m commented Nov 12, 2020

I tried a few things to intentionally reproduce the problem but had no luck. If anyone could help me produce a test case I'd appreciate it. For now I'll add more error logging as suggested by @ethomson

@gr2m
Copy link
Owner

gr2m commented Nov 13, 2020

Can you add a ACTIONS_STEP_DEBUG secret and set it to true as described here: https://github.com/gr2m/create-or-update-pull-request-action#debugging that will log the error from the git cherry-pick command to the build output

@gr2m
Copy link
Owner

gr2m commented Nov 13, 2020

I think the solution is to simplify the git commands in the first place. What I want is to update an existing branch update-branch, with unstaged changes in the default branch main. Or if update-branch does not yet exist, create it.

I don't want to commit the changes to main, I want to commit them to update-branch. I experimented with stashing but that didn't work well so I ended up creating a temporary branch and then cherry-picking the changes from there.

What would the git commands be you would use in such a situation?

@ethomson
Copy link

Ugh, this is one of those places where what you describe is relatively easy in the data modelling side (and I could whip you up some libgit2 to do this quite easily) but I'm not 100% sure what the git commands are to get you there.

I think that using git itself, I'd let it do the work against an alternate index file (in other words, stage all those changes, but not against the repository index, so the repo will still see them as unchanged), and create a commit from it and then set that to the head of update-branch.

I think that this will work:

TMPFILE=$(mktemp)

# add the files to the temporary staging area
GIT_INDEX_FILE="${TMPFILE}" git add .

# turn the temporary staging area into a tree object
TREE_ID=$(GIT_INDEX_FILE="${TMPFILE}" git write-tree)

# create a commit that points to that tree object
COMMIT_ID=$(git commit-tree -p HEAD -m 'commit message goes here' $TREE_ID)

# create or update the branch to the new commit
git branch -f 'branch_name_goes_here' $COMMIT_ID

@bnb
Copy link
Contributor Author

bnb commented Nov 13, 2020

@gr2m
Copy link
Owner

gr2m commented Nov 13, 2020

Thanks @ethomson! Maybe we can make the current version work, but if not, I'll try the commands you suggested. Regarding libgit2, aren't there bindings for Node we could use? Would that help in this case?

Thanks @bnb, here is the full error we are facing

$ git cherry-pick --strategy recursive --strategy-option theirs tmp-create-or-update-pull-request-action-ow2fj5il2e
Error: Command failed with exit code 1 (EPERM): git cherry-pick --strategy recursive --strategy-option theirs tmp-create-or-update-pull-request-action-ow2fj5il2e
    at makeError (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:5673:11)
    at handlePromise (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:7624:26)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runShellCommand (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:707:32)
    at async checkOutRemoteBranch (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:692:5)
    at async main (/home/runner/work/_actions/gr2m/create-or-update-pull-request-action/v1.x/dist/index.js:567:32) {
  command: 'git cherry-pick --strategy recursive --strategy-option theirs tmp-create-or-update-pull-request-action-ow2fj5il2e',
  exitCode: 1,
  exitCodeName: 'EPERM',
  stdout: 'On branch actions/authors-update\n' +
    'You are currently cherry-picking commit c8d45a65ec.\n' +
    '  (all conflicts fixed: run "git cherry-pick --continue")\n' +
    '  (use "git cherry-pick --skip" to skip this patch)\n' +
    '  (use "git cherry-pick --abort" to cancel the cherry-pick operation)\n' +
    '\n' +
    'nothing to commit, working tree clean',
  stderr: 'The previous cherry-pick is now empty, possibly due to conflict resolution.\n' +
    'If you wish to commit it anyway, use:\n' +
    '\n' +
    '    git commit --allow-empty\n' +
    '\n' +
    "Otherwise, please use 'git cherry-pick --skip'",
  all: 'The previous cherry-pick is now empty, possibly due to conflict resolution.\n' +
    'If you wish to commit it anyway, use:\n' +
    '\n' +
    '    git commit --allow-empty\n' +
    '\n' +
    "Otherwise, please use 'git cherry-pick --skip'\n" +
    'On branch actions/authors-update\n' +
    'You are currently cherry-picking commit c8d45a65ec.\n' +
    '  (all conflicts fixed: run "git cherry-pick --continue")\n' +
    '  (use "git cherry-pick --skip" to skip this patch)\n' +
    '  (use "git cherry-pick --abort" to cancel the cherry-pick operation)\n' +
    '\n' +
    'nothing to commit, working tree clean',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false,
  signal: undefined
}

It sounds like the problem is

nothing to commit, working tree clean

Sounds like this could be fixed by adding --allow-empty to the command? 🙏🏼 Let me try that

so the action was triggered, no change occurred, and that's why the cherry pick failed somehow? I wish I could reproduce the state with pure git commands for easier debugging, I didn't manage to yet.

gr2m added a commit that referenced this issue Nov 13, 2020
that resolves "The previous cherry-pick is now empty, possibly due to conflict resolution" error. Ref #245
@gr2m
Copy link
Owner

gr2m commented Nov 13, 2020

Sounds like this could be fixed by adding --allow-empty to the command?

That did not seem to have worked 🤷🏼
https://github.com/octokit/graphql-schema/runs/1397579382?check_suite_focus=true#step:7:326

But running git cherry-pick --skip in case of a "The previous cherry-pick is now empty" error did, at least in this case. Let me ship that and then see if that resolves the problem for you, too, @bnb?

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 1.3.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@bnb
Copy link
Contributor Author

bnb commented Nov 16, 2020

@gr2m
Copy link
Owner

gr2m commented Nov 16, 2020

yay! Thank you all for your help!

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

Successfully merging a pull request may close this issue.

3 participants