peter-evans / rebase

A GitHub action to rebase pull requests in a repository
MIT License
45 stars 19 forks source link

Rebase the last one in branch chain to make `update-refs` great again #152

Open vasilich6107 opened 4 weeks ago

vasilich6107 commented 4 weeks ago

Hi.

Sometimes there is a need to create a chain of branches like

While rebasing branch1 all other branches will be full of conflicts due to obvious reason.

There is an --update-refs flag for git which works only if the branch being rebased is the last one.

So having some boolean flag like rebase-last(just an example) in conjunction with rebase-options: --update-refs could be a game changer.

To get last branch of the chain there is

git branch --contains branch1 | tail -n 1
vasilich6107 commented 4 weeks ago

@peter-evans I have some pseudo code, it would be nice if you could check.

Technically if the flag is true we could hook somewhere before here https://github.com/peter-evans/rebase/blob/main/dist/index.js#L640

let headRef = pull.headRef;
if(flag_is_true) {
  core.startGroup(`Resolving the bottom most branch chained from '${headRef}'.`);
  headRef = yield this.git.exec(['branch', `--contains`, headRef, '|', 'tail', '-n', '1']);
  core.info(`Resolved ref is '${headRef}'.`);
  core.endGroup();
}

in order to replace the closest to main - branch1 to the furthest from main - branch4

and then code continues as previously

// Fetch
core.startGroup(`Fetching head ref '${headRef}'.`);
yield this.git.fetch([headRef], remoteName);

does it make sense for you?