Skip to content

Commit

Permalink
Merge pull request #1120 from Magador/feat/remote-fakeTeamwork-merge
Browse files Browse the repository at this point in the history
feat: command to simulate Merge/Pull Request
  • Loading branch information
pcottle authored Dec 16, 2023
2 parents 99bc0ca + acffcc1 commit 9f82317
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 5 deletions.
78 changes: 77 additions & 1 deletion __tests__/remote.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions src/js/git/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,47 @@ var commandConfig = {
}
},

mergeMR: {
regex: /^git +merge[MP]R($|\s)/,
options: ['--delete-after-merge'],
execute: function(engine, command) {
var generalArgs = command.getGeneralArgs();
var commandOptions = command.getOptionsMap();
if (!engine.hasOrigin()) {
throw new GitError({
msg: intl.str('git-error-origin-required'),
});
}

command.validateArgBounds(generalArgs, 2, 2);

var fromBranch = validateOriginBranchName(engine, generalArgs[0]);
var intoBranch = validateOriginBranchName(engine, generalArgs[1]);

var origin = engine.origin;

origin.checkout(intoBranch);
var mergeCommit = origin.merge(fromBranch, { noFF: true });

origin.animationFactory.genCommitBirthAnimation(
origin.animationQueue,
mergeCommit,
origin.gitVisuals
);

if (!!commandOptions['--delete-after-merge']) {
origin.validateAndDeleteBranch(fromBranch);
}

origin.checkout('main');

origin.animationFactory.playRefreshAnimationAndFinish(
origin.gitVisuals,
origin.animationQueue
);
}
},

revlist: {
dontCountForGolf: true,
displayName: 'rev-list',
Expand Down
15 changes: 11 additions & 4 deletions src/js/git/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9f82317

Please sign in to comment.