A easy way to send back port PRs #355

Open
opened 2021-04-11 01:21:02 +00:00 by lunny · 4 comments
Owner
No description provided.
lunny added the
kind/proposal
label 2021-04-11 01:21:02 +00:00
Member

tea pr backport <remote target branch> <pr index> ?

  1. fetch source PR metadata
  2. fetch source PR commits
  3. checkout new branch from remote branch
  4. cherry pick each source commit
  5. push new branch
  6. modify source metadata: prefix backport of #<idx>\n\n---\n\n
  7. create new PR with same properties as source pr
  • Step 2 is probably easier by fetching the PR commits locally via git, instead of via API
  • Step 4 needs to be done with native git, as go-git does not support cherrypicks. (This is a deviation from the current approach taken for all other git operations)
  • Step 5 may need further input: to which remote should we push?
  • Step 7 could be made interactive, with inputs already populated
`tea pr backport <remote target branch> <pr index>` ? 1. fetch source PR metadata 2. fetch source PR commits 3. checkout new branch from remote branch 4. cherry pick each source commit 5. push new branch 6. modify source metadata: prefix `backport of #<idx>\n\n---\n\n` 7. create new PR with same properties as source pr - Step 2 is probably easier by fetching the PR commits locally via git, instead of via API - Step 4 needs to be done with native git, as go-git does not support cherrypicks. (This is a deviation from the current approach taken for all other git operations) - Step 5 may need further input: to which remote should we push? - Step 7 could be made interactive, with inputs already populated
Author
Owner

Or tea pr backport <pr index> <remote target branch>?

  1. fetch source PR merged commitid via API(According to different merge style)
  2. fetch remote target branch and checkout new branch from remote branch
    ...

Others are the same as you.

Or `tea pr backport <pr index> <remote target branch>`? 1. fetch source PR merged commitid via API(According to different merge style) 2. fetch remote target branch and checkout new branch from remote branch ... Others are the same as you.
Owner

This is my hack script to create a backport

#!/bin/sh
PR="$1"
SHA="$2"
VERSION="$3"

if [ -z "$SHA" ]; then
    SHA=$(gh api /repos/go-gitea/gitea/pulls/$PR -q '.merge_commit_sha')
fi

if [ -z "$VERSION" ]; then
    VERSION="v1.14"
fi

echo git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION
git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION
git cherry-pick $SHA && git commit --amend && git push zeripath backport-$PR-$VERSION && xdg-open https://github.com/go-gitea/gitea/compare/release/"$VERSION"...zeripath:backport-$PR-$VERSION

It could be considerably improved by adding status in to the .git/ directory etc.

It should be possible to resume by checking the remote origin and current name for the current branch - if the branch is of the right format - backport-$PR-$VERSION then we check the remote - if the remote is still origin/release/$VERSION then we know we're at the point of pushing.

... and so on ...

This is my hack script to create a backport ```sh #!/bin/sh PR="$1" SHA="$2" VERSION="$3" if [ -z "$SHA" ]; then SHA=$(gh api /repos/go-gitea/gitea/pulls/$PR -q '.merge_commit_sha') fi if [ -z "$VERSION" ]; then VERSION="v1.14" fi echo git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION git cherry-pick $SHA && git commit --amend && git push zeripath backport-$PR-$VERSION && xdg-open https://github.com/go-gitea/gitea/compare/release/"$VERSION"...zeripath:backport-$PR-$VERSION ``` It could be considerably improved by adding status in to the `.git/` directory etc. It should be possible to resume by checking the remote origin and current name for the current branch - if the branch is of the right format - `backport-$PR-$VERSION` then we check the remote - if the remote is still origin/release/$VERSION then we know we're at the point of pushing. ... and so on ...
Owner

I can't claim it's the cleanest code, but you could take a look at cherry.

It basically shows you a list of upstream commits and lets you choose one to cherry-pick, then it pushes to a branch for you.

A small caveat, it only currently works with squash commits, because it only cherry-picks a single commit.

I can't claim it's the cleanest code, but you could take a look at [cherry](https://gitea.com/jolheiser/cherry). It basically shows you a list of upstream commits and lets you choose one to cherry-pick, then it pushes to a branch for you. A small caveat, it only currently works with squash commits, because it only cherry-picks a single commit.
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/tea#355
No description provided.