mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 00:40:07 +02:00
collision issue
This commit is contained in:
parent
30e8885a0f
commit
85de7c5a04
1 changed files with 21 additions and 9 deletions
26
src/git.js
26
src/git.js
|
@ -26,11 +26,9 @@ function GitEngine(options) {
|
||||||
|
|
||||||
GitEngine.prototype.init = function() {
|
GitEngine.prototype.init = function() {
|
||||||
// make an initial commit and a master branch
|
// make an initial commit and a master branch
|
||||||
this.rootCommit = new Commit({rootCommit: true});
|
this.rootCommit = this.makeCommit(null, null, {rootCommit: true});
|
||||||
this.commitCollection.add(this.rootCommit);
|
this.commitCollection.add(this.rootCommit);
|
||||||
|
|
||||||
this.refs[this.rootCommit.get('id')] = this.rootCommit;
|
|
||||||
|
|
||||||
var master = this.makeBranch('master', this.rootCommit);
|
var master = this.makeBranch('master', this.rootCommit);
|
||||||
this.HEAD = new Ref({
|
this.HEAD = new Ref({
|
||||||
id: 'HEAD',
|
id: 'HEAD',
|
||||||
|
@ -285,11 +283,24 @@ GitEngine.prototype.logBranches = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.makeCommit = function(parents, id) {
|
GitEngine.prototype.makeCommit = function(parents, id, options) {
|
||||||
var commit = new Commit({
|
// ok we need to actually manually create commit IDs now because
|
||||||
|
// people like nikita (thanks for finding this!) could
|
||||||
|
// make branches named C2 before creating the commit C2
|
||||||
|
if (!id) {
|
||||||
|
id = uniqueId('C');
|
||||||
|
while (this.refs[id]) {
|
||||||
|
id = uniqueId('C');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var commit = new Commit(_.extend({
|
||||||
parents: parents,
|
parents: parents,
|
||||||
id: id
|
id: id
|
||||||
});
|
},
|
||||||
|
options || {}
|
||||||
|
));
|
||||||
|
|
||||||
this.refs[commit.get('id')] = commit;
|
this.refs[commit.get('id')] = commit;
|
||||||
this.commitCollection.add(commit);
|
this.commitCollection.add(commit);
|
||||||
return commit;
|
return commit;
|
||||||
|
@ -1290,8 +1301,9 @@ var Commit = Backbone.Model.extend({
|
||||||
|
|
||||||
validateAtInit: function() {
|
validateAtInit: function() {
|
||||||
if (!this.get('id')) {
|
if (!this.get('id')) {
|
||||||
this.set('id', uniqueId('C'));
|
throw new Error('Need ID!!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.get('createTime')) {
|
if (!this.get('createTime')) {
|
||||||
this.set('createTime', new Date().toString());
|
this.set('createTime', new Date().toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue