Skip to content

Commit 7762dd4

Browse files
committed
Merge pull request #36 from Sfeir/master
Adding -m option to git commit
2 parents 16931b5 + 1ffc853 commit 7762dd4

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

css/explaingit.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,18 @@ circle.commit.branchless {
210210
text.id-label {
211211
text-anchor: middle;
212212
font-family: Courier New;
213+
font-weight: bolder;
213214
fill: #666;
214215
font-size: 10px;
215216
}
216217

218+
text.message-label {
219+
text-anchor: middle;
220+
font-family: Courier New;
221+
fill: #666;
222+
font-size: 10px;
223+
}
224+
217225
g.branch-tag > rect {
218226
fill: #FFCC66;
219227
stroke: #CC9900;

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ <h2>Specific Examples</h2>
547547
name: 'Zen',
548548
height: '100%',
549549
commitData: [
550-
{id: 'e137e9b', tags: ['master']}
550+
{id: 'e137e9b', tags: ['master'], message: 'first commit'}
551551
],
552552
initialMessage:
553553
'Have fun.'

js/controlbox.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,22 @@ define(['d3'], function () {
143143
this._scrollToBottom();
144144
},
145145

146-
commit: function () {
147-
this.historyView.commit();
146+
commit: function (args) {
147+
if (args.length >= 2) {
148+
var arg = args.shift();
149+
150+
switch (arg) {
151+
case '-m':
152+
var message = args.join(" ");
153+
this.historyView.commit({},message);
154+
break;
155+
default:
156+
this.historyView.commit();
157+
break;
158+
}
159+
} else {
160+
this.historyView.commit();
161+
}
148162
},
149163

150164
branch: function (args) {

js/historyview.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ define(['d3'], function () {
194194
});
195195
};
196196

197-
fixIdPosition = function (selection, view) {
197+
fixIdPosition = function (selection, view, delta) {
198198
selection.attr('x', function (d) {
199199
return d.cx;
200200
}).attr('y', function (d) {
201-
return d.cy + view.commitRadius + 14;
201+
return d.cy + view.commitRadius + delta;
202202
});
203203
};
204204

@@ -215,7 +215,7 @@ define(['d3'], function () {
215215
if (commitCY < (view.baseLine)) {
216216
return commitCY - 45 - (tagIndex * 25);
217217
} else {
218-
return commitCY + 40 + (tagIndex * 25);
218+
return commitCY + 50 + (tagIndex * 25);
219219
}
220220
};
221221

@@ -578,21 +578,26 @@ define(['d3'], function () {
578578
},
579579

580580
_renderIdLabels: function () {
581+
this._renderText('id-label', function (d) { return d.id + '..'; }, 14);
582+
this._renderText('message-label', function (d) { return d.message; }, 24);
583+
},
584+
585+
_renderText: function(className, getText, delta) {
581586
var view = this,
582-
existingLabels,
583-
newLabels;
587+
existingTexts,
588+
newtexts;
584589

585-
existingLabels = this.commitBox.selectAll('text.id-label')
590+
existingTexts = this.commitBox.selectAll('text.' + className)
586591
.data(this.commitData, function (d) { return d.id; })
587-
.text(function (d) { return d.id + '..'; });
592+
.text(getText);
588593

589-
existingLabels.transition().call(fixIdPosition, view);
594+
existingTexts.transition().call(fixIdPosition, view, delta);
590595

591-
newLabels = existingLabels.enter()
596+
newtexts = existingTexts.enter()
592597
.insert('svg:text', ':first-child')
593-
.classed('id-label', true)
594-
.text(function (d) { return d.id + '..'; })
595-
.call(fixIdPosition, view);
598+
.classed(className, true)
599+
.text(getText)
600+
.call(fixIdPosition, view, delta);
596601
},
597602

598603
_parseTagData: function () {
@@ -802,12 +807,13 @@ define(['d3'], function () {
802807
return inTree;
803808
},
804809

805-
commit: function (commit) {
810+
commit: function (commit, message) {
806811
commit = commit || {};
807812

808813
!commit.id && (commit.id = HistoryView.generateId());
809814
!commit.tags && (commit.tags = []);
810815

816+
commit.message = message;
811817
if (!commit.parent) {
812818
if (!this.currentBranch) {
813819
throw new Error('Not a good idea to make commits while in a detached HEAD state.');
@@ -980,6 +986,7 @@ define(['d3'], function () {
980986
currentCommit = this.getCommit('HEAD'),
981987
isCommonAncestor,
982988
rebaseTreeLoc,
989+
rebaseMessage,
983990
toRebase = [], rebasedCommit,
984991
remainingHusk;
985992

@@ -1000,7 +1007,7 @@ define(['d3'], function () {
10001007
return 'Fast-Forward';
10011008
}
10021009

1003-
rebaseTreeLoc = rebaseTarget.id
1010+
rebaseTreeLoc = rebaseTarget.id;
10041011

10051012
while (!isCommonAncestor) {
10061013
toRebase.unshift(currentCommit);
@@ -1010,10 +1017,12 @@ define(['d3'], function () {
10101017

10111018
for (var i = 0; i < toRebase.length; i++) {
10121019
rebasedCommit = toRebase[i];
1020+
rebaseMessage = rebasedCommit.message;
10131021

10141022
remainingHusk = {
10151023
id: rebasedCommit.id,
10161024
parent: rebasedCommit.parent,
1025+
message: rebasedCommit.message,
10171026
tags: []
10181027
};
10191028

@@ -1029,6 +1038,7 @@ define(['d3'], function () {
10291038
rebasedCommit.parent = rebaseTreeLoc;
10301039
rebaseTreeLoc = HistoryView.generateId()
10311040
rebasedCommit.id = rebaseTreeLoc;
1041+
rebasedCommit.message = rebaseMessage;
10321042
rebasedCommit.tags.length = 0;
10331043
rebasedCommit.rebased = true;
10341044
}

0 commit comments

Comments
 (0)