feat: command to simulate Merge/Pull Request

- Adds `git merge(M|P)R <source_branch> <target_branch> [--delete-after-merge]` command
to simulate a Merge/Pull Request being merged into the target branch
- The optional flag `--delete-after-merge` will remove the merged branch on the origin tree
  - The local remote branch remains as it is Git default behavior, even after `git fetch`
(it would require `git fetch --prune` support to automatically prune remote tracking branches)
- You can push a branch with a deleted remote tracking branch on origin, the ref will just update.

Resolves #1057
This commit is contained in:
Lucie Lenglet 2023-12-15 19:32:47 +01:00
parent 99bc0ca8c5
commit acffcc1616
3 changed files with 128 additions and 4 deletions

View file

@ -453,10 +453,17 @@ GitEngine.prototype.findCommonAncestorWithRemote = function(originTarget) {
};
GitEngine.prototype.makeBranchOnOriginAndTrack = function(branchName, target) {
var remoteBranch = this.makeBranch(
ORIGIN_PREFIX + branchName,
this.getCommitFromRef(target)
);
var remoteBranch = this.refs[ORIGIN_PREFIX + branchName];
// If the remote branch exists but the branch on origin was deleted, updates its target location
if (remoteBranch) {
this.setTargetLocation(remoteBranch, target);
} else {
remoteBranch = this.makeBranch(
ORIGIN_PREFIX + branchName,
this.getCommitFromRef(target)
);
}
if (this.refs[branchName]) { // not all remote branches have tracking ones
this.setLocalToTrackRemote(this.refs[branchName], remoteBranch);