majkinetor / au

Chocolatey Automatic Package Updater Module
GNU General Public License v2.0
227 stars 71 forks source link

Git plugin: create branch if it does not exist #247

Closed easybe closed 3 years ago

easybe commented 3 years ago

Note that if a local branch with the same name already exist, it will be reset to the current HEAD.

majkinetor commented 3 years ago

Why would we need flag for this ? Can't you just create a branch if it doesn't exist by default ?

easybe commented 3 years ago

Yes, I guess that could work for me.

However,

https://github.com/majkinetor/au/blob/cb04813aa1a5e6dffed4d762ef487f8affe86c47/AU/Plugins/Git.ps1#L56

is also a problem for me. IMHO a git pull does not really make sense here, as we have uncommitted changes at this point which might lead to an error. Or am I missing something here?

Is it an option to change the current behavior?

majkinetor commented 3 years ago

That is for collaborative environment where somebody else might push to that branch in the middle of the CI pipeline. It ensures there are no conflicts on push.

majkinetor commented 3 years ago

That is also not a problem, you could ignore error on it or (better) do it for existing branches only.

easybe commented 3 years ago

OK, I updated the PR.

Note that if a local branch with the same name already exist, it will be reset to the current HEAD.

I hope that is OK.

majkinetor commented 3 years ago

You miss -q everywhere. Without it CI may fail.

easybe commented 3 years ago

You miss -q everywhere. Without it CI may fail.

I would prefer it that way, but OK, I can add it.

easybe commented 3 years ago

Done

majkinetor commented 3 years ago

I would prefer it too, but CI fails because git writes to stderr if q is not present.

majkinetor commented 3 years ago

So with this change, you can basically make persistence commits visible in separate branch and not pollute your master branch with bot commits ? Its enough for me to set some arbitrary non existent branch like -Branch updatebot ?

I remember some people asked for it a long time ago.

easybe commented 3 years ago

Yes, exactly. I create PRs from these branches.

majkinetor commented 3 years ago

So, are you done and checked if it works in real AU update ? This plugin is used by everybody.

easybe commented 3 years ago

Yes, I am done.

It works in my set up which is based on https://github.com/majkinetor/au-packages-template/blob/master/update_all.ps1.

Not sure how to test it more.

majkinetor commented 3 years ago

Ah, wait... It won't work like this I think. If packages are on master and you are pulling updatebot you will get nothing. So you need to get master and switch to another branch after that if I am not mistaken. So there need to be 2 branches as parameters - SourceBranch and DestinationBranch

easybe commented 3 years ago

For me it works because:

For my case "pull" does not make sense...

easybe commented 3 years ago

If you specify master as the branch, nothing should have changed.

majkinetor commented 3 years ago

It was there as a safety because time passes since CI pulls the master and AU finishes and your changes are "saved". If anybody commits during that time you can't push on the same branch any more. Contrary to that, pull immediately before commit makes that highly unlikely.

Now it works for you because of your specific setup. It may not work for people who use the same branch for source and destination and have more active users.

So,

  1. CI checks out the latest master
  2. CI script runs init
  3. CI scripts runs AU
  4. AU runs for some time
  5. Somebody commits on master <========= THIS
  6. AU finishes
  7. AU tries to push to master and fails.
majkinetor commented 3 years ago

In case Branch is different then master, then I agree, pull is probably not needed UNLESS again somebody commits to it, like you have multiple AU scripts for some reason operating for redundancy.

majkinetor commented 3 years ago

Other problem is that you don't need to have CI - you can perfectly have Git plugin working without any CI whatsoever, then it needs to pull master if AU runs from 2 locations .

majkinetor commented 3 years ago

So maybe to be sure, we should have 2 params, SourceBranch aka Branch as before (param alias) and DestinationBranch. If you use CI and you are lone developer you could probably just use DestinationBranch and CI will do the rest.

easybe commented 3 years ago

I really don't see any problem here. As I said,

If you specify master as the branch, nothing should have changed.

because a git pull is still performed.

If you use a different branch, worst case would be that you have a merge conflict when merging the branch. Then you could e.g. re-run or rebase.

easybe commented 3 years ago

If you have two AU scripts pushing to the same branch, the slower one will pull the newly created branch.

easybe commented 3 years ago

I like this solution because the changes are very minimal 🤷‍♂️

majkinetor commented 3 years ago

It works on my repo, branch name updates

Not sure why it triggered new build ASAP after bot commit on AppVeyor ... need to look into it.