mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +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() {
|
||||
// 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.refs[this.rootCommit.get('id')] = this.rootCommit;
|
||||
|
||||
var master = this.makeBranch('master', this.rootCommit);
|
||||
this.HEAD = new Ref({
|
||||
id: 'HEAD',
|
||||
|
@ -285,11 +283,24 @@ GitEngine.prototype.logBranches = function() {
|
|||
});
|
||||
};
|
||||
|
||||
GitEngine.prototype.makeCommit = function(parents, id) {
|
||||
var commit = new Commit({
|
||||
GitEngine.prototype.makeCommit = function(parents, id, options) {
|
||||
// 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,
|
||||
id: id
|
||||
});
|
||||
},
|
||||
options || {}
|
||||
));
|
||||
|
||||
this.refs[commit.get('id')] = commit;
|
||||
this.commitCollection.add(commit);
|
||||
return commit;
|
||||
|
@ -1290,8 +1301,9 @@ var Commit = Backbone.Model.extend({
|
|||
|
||||
validateAtInit: function() {
|
||||
if (!this.get('id')) {
|
||||
this.set('id', uniqueId('C'));
|
||||
throw new Error('Need ID!!');
|
||||
}
|
||||
|
||||
if (!this.get('createTime')) {
|
||||
this.set('createTime', new Date().toString());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue