pygitops icon indicating copy to clipboard operation
pygitops copied to clipboard

Feature Request: Forcibly Update Existing Branch

Open jhpierce opened this issue 4 years ago • 2 comments

Use Case

Since this library will mostly be used by automated systems, it would be useful if it could cleanly handle the case of wiping and pushing new changes to an existing branch.

One way to do that in git is:

  1. pull down the latest version of main
  2. checkout the given feature branch
  3. git reset --hard origin/main
  4. allow the user to make code changes
  5. commit the changes
  6. force push the contents to remote

Potential interface:

with force_push_to_feature_branch(branch_name):
    # Make code changes

This could raise exceptions if:

  1. There were no code changes
  2. The branch name given didn't exist

On exit, the context manager would abandon any uncommitted changes, and checkout main, leaving the repo in a clean state.

jhpierce avatar Mar 18 '22 01:03 jhpierce

If we want to make the changes on the default branch, then forcibly push them to another branch after, then we can:

git branch -f feature_branch <default_branch>

This way, we don't need to know the branch name before the code changes are made. Taken from this SO post

jhpierce avatar Apr 08 '22 11:04 jhpierce

The wiping part has been implemented via #249

colinodell avatar Jul 28 '22 13:07 colinodell