Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add merge squash action #1267

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
27 changes: 24 additions & 3 deletions components/graph/git-graph-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const MergeViewModel = HoverActions.MergeViewModel;
const ResetViewModel = HoverActions.ResetViewModel;
const PushViewModel = HoverActions.PushViewModel;
const SquashViewModel = HoverActions.SquashViewModel;
const MergeSquashViewModel = HoverActions.MergeSquashViewModel;

class ActionBase {
constructor(graph, text, style, icon) {
Expand All @@ -18,13 +19,13 @@ class ActionBase {
this.isRunning = ko.observable(false);
this.isHighlighted = ko.computed(() => !graph.hoverGraphAction() || graph.hoverGraphAction() == this);
this.text = text;
this.style = style;
this.style = ko.observable(style);
this.icon = icon;
this.cssClasses = ko.computed(() => {
if (!this.isHighlighted() || this.isRunning()) {
return `${this.style} dimmed`;
return `${this.style()} dimmed`;
} else {
return this.style;
return this.style();
}
});
}
Expand Down Expand Up @@ -168,6 +169,25 @@ class Merge extends ActionBase {
}
}

class MergeSquash extends Merge {
constructor(graph, node) {
super(graph, node)
this.text = "Merge Squash";
this.style("merge-squash");
}

createHoverGraphic() {
let from = this.graph.currentActionContext();
if (!from) return;
if (from instanceof RefViewModel) from = from.node();
return new MergeSquashViewModel(from, this.node);
}

perform() {
return this.server.postPromise('/squash', { path: this.graph.repoPath(), target: this.graph.currentActionContext().localRefName })
.catch((err) => { if (err.errorCode != 'merge-failed') this.server.unhandledRejection(err); });
}
}

class Push extends ActionBase {
constructor(graph, node) {
Expand Down Expand Up @@ -369,6 +389,7 @@ const GraphActions = {
Move: Move,
Rebase: Rebase,
Merge: Merge,
MergeSquash: MergeSquash,
Push: Push,
Reset: Reset,
Checkout: Checkout,
Expand Down
1 change: 1 addition & 0 deletions components/graph/git-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class GitNodeViewModel extends Animateable {
new GraphActions.Move(this.graph, this),
new GraphActions.Rebase(this.graph, this),
new GraphActions.Merge(this.graph, this),
new GraphActions.MergeSquash(this.graph, this),
new GraphActions.Push(this.graph, this),
new GraphActions.Reset(this.graph, this),
new GraphActions.Checkout(this.graph, this),
Expand Down
3 changes: 3 additions & 0 deletions components/graph/graph.less
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
&.merge {
background: rgba(208, 135, 212, 0.9);
}
&.merge-squash {
background: darken(rgba(208, 135, 212, 0.9), 20%);
}
&.checkout {
background: rgba(205, 219, 55, 0.9);
}
Expand Down
7 changes: 7 additions & 0 deletions components/graph/hover-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ class SquashViewModel extends HoverViewModel {
}
}
exports.SquashViewModel = SquashViewModel;

class MergeSquashViewModel extends SquashViewModel {
constructor(from, onto) {
super(from, onto);
}
}
exports.MergeSquashViewModel = MergeSquashViewModel;