Skip to content

Commit 0af9a2f

Browse files
author
Michelle Tilley
committed
Allow committing from detached head
1 parent 7ea6852 commit 0af9a2f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

js/historyview.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ define(['d3'], function () {
494494
this._renderMergePointers();
495495
this._renderIdLabels();
496496
this._resizeSvg();
497-
this.checkout(this.currentBranch);
497+
this.currentBranch && this.checkout(this.currentBranch);
498498
},
499499

500500
_renderCircles: function () {
@@ -856,19 +856,23 @@ define(['d3'], function () {
856856

857857
commit.message = message;
858858
if (!commit.parent) {
859-
if (!this.currentBranch) {
860-
throw new Error('Not a good idea to make commits while in a detached HEAD state.');
861-
}
862-
863-
commit.parent = this.getCommit(this.currentBranch).id;
859+
commit.parent = this.getCommit('HEAD').id;
864860
}
865861

866862
this.commitData.push(commit);
867-
this.moveTag(this.currentBranch, commit.id);
863+
if (this.currentBranch) {
864+
this.moveTag(this.currentBranch, commit.id);
865+
}
868866

869867
this.renderCommits();
870868

871-
this.checkout(this.currentBranch);
869+
if (this.currentBranch) {
870+
console.log('branch', this.currentBranch)
871+
this.checkout(this.currentBranch);
872+
} else {
873+
console.log('commit', commit.id)
874+
this.checkout(commit.id)
875+
}
872876
return this;
873877
},
874878

@@ -928,6 +932,7 @@ define(['d3'], function () {
928932
},
929933

930934
checkout: function (ref) {
935+
console.log("checking out", ref)
931936
var commit = this.getCommit(ref);
932937

933938
if (!commit) {

0 commit comments

Comments
 (0)