mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-26 07:58:34 +02:00
WIP bad
This commit is contained in:
parent
068b9b961e
commit
9bf99ebff3
2 changed files with 60 additions and 13 deletions
|
@ -15,6 +15,14 @@ function isColonRefspec(str) {
|
||||||
return str.indexOf(':') !== -1 && str.split(':').length === 2;
|
return str.indexOf(':') !== -1 && str.split(':').length === 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var assertIsRef = function(engine, ref) {
|
||||||
|
engine.resolveID(ref); // will throw giterror if cant resolve
|
||||||
|
};
|
||||||
|
|
||||||
|
var validateAndAssertBranchName = function(engine, name) {
|
||||||
|
return engine.validateBranchName(name);
|
||||||
|
};
|
||||||
|
|
||||||
var assertOriginSpecified = function(generalArgs) {
|
var assertOriginSpecified = function(generalArgs) {
|
||||||
if (generalArgs[0] !== 'origin') {
|
if (generalArgs[0] !== 'origin') {
|
||||||
throw new GitError({
|
throw new GitError({
|
||||||
|
@ -42,7 +50,9 @@ var assertBranchIsRemoteTracking = function(engine, branchName) {
|
||||||
var tracking = branch.getRemoteTrackingBranchID();
|
var tracking = branch.getRemoteTrackingBranchID();
|
||||||
if (!tracking) {
|
if (!tracking) {
|
||||||
throw new GitError({
|
throw new GitError({
|
||||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
msg: intl.todo(
|
||||||
|
branchName + ' is not a remote tracking branch! I dont know where to push'
|
||||||
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return tracking;
|
return tracking;
|
||||||
|
@ -560,24 +570,32 @@ var commandConfig = {
|
||||||
command.twoArgsImpliedOrigin(generalArgs);
|
command.twoArgsImpliedOrigin(generalArgs);
|
||||||
assertOriginSpecified(generalArgs);
|
assertOriginSpecified(generalArgs);
|
||||||
|
|
||||||
var tracking;
|
var destination;
|
||||||
var source;
|
var source;
|
||||||
var firstArg = generalArgs[1];
|
var firstArg = generalArgs[1];
|
||||||
if (firstArg) {
|
if (firstArg) {
|
||||||
if (isColonRefspec(firstArg)) {
|
if (isColonRefspec(firstArg)) {
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
tracking = assertBranchIsRemoteTracking(engine, refspecParts[1]);
|
destination = refspecParts[1];
|
||||||
|
// TODO -- assert good branch name
|
||||||
} else {
|
} else {
|
||||||
tracking = assertBranchIsRemoteTracking(engine, firstArg);
|
// we are using this org as both destination and source
|
||||||
|
destination = firstArg;
|
||||||
|
source = firstArg;
|
||||||
}
|
}
|
||||||
|
destination = validateAndAssertBranchName(engine, destination);
|
||||||
} else {
|
} else {
|
||||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
source = engine.getOneBeforeCommit('HEAD');
|
||||||
tracking = assertBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
destination = source;
|
||||||
|
assertBranchIsRemoteTracking(source);
|
||||||
|
}
|
||||||
|
if (source) {
|
||||||
|
assertIsRef(engine, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.push({
|
engine.push({
|
||||||
destination: tracking,
|
destination: destination,
|
||||||
source: source
|
source: source
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,15 +366,32 @@ GitEngine.prototype.makeOrigin = function(treeString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we have something in common, lets make the tracking branch
|
// now we have something in common, lets make the tracking branch
|
||||||
var originBranch = this.makeBranch(
|
var remoteBranch = this.makeBranch(
|
||||||
ORIGIN_PREFIX + branchName,
|
ORIGIN_PREFIX + branchName,
|
||||||
this.getCommitFromRef(originTarget)
|
this.getCommitFromRef(originTarget)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setLocalToTrackRemote(this.refs[branchJSON.id], originBranch);
|
this.setLocalToTrackRemote(this.refs[branchJSON.id], remoteBranch);
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GitEngine.prototype.makeBranchOnOriginAndTrack = function(branchName, target) {
|
||||||
|
var remoteBranch = this.makeBranch(
|
||||||
|
ORIGIN_PREFIX + branchName,
|
||||||
|
this.getCommitFromRef(target)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.refs[branchName]) { // not all remote branches have tracking ones
|
||||||
|
this.setLocalToTrackRemote(this.refs[branchName], remoteBranch);
|
||||||
|
}
|
||||||
|
|
||||||
|
var originTarget = this.origin.refs['master'].get('target');
|
||||||
|
this.origin.makeBranch(
|
||||||
|
branchName,
|
||||||
|
originTarget
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
GitEngine.prototype.setLocalToTrackRemote = function(localBranch, remoteBranch) {
|
GitEngine.prototype.setLocalToTrackRemote = function(localBranch, remoteBranch) {
|
||||||
localBranch.setRemoteTrackingBranchID(remoteBranch.get('id'));
|
localBranch.setRemoteTrackingBranchID(remoteBranch.get('id'));
|
||||||
|
|
||||||
|
@ -859,16 +876,28 @@ GitEngine.prototype.descendSortDepth = function(objects) {
|
||||||
|
|
||||||
GitEngine.prototype.push = function(options) {
|
GitEngine.prototype.push = function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var remoteBranch = this.refs[options.destination];
|
|
||||||
var branchOnRemote = this.origin.refs[remoteBranch.getBaseID()];
|
|
||||||
|
|
||||||
if (options.source === "") {
|
if (options.source === "") {
|
||||||
// delete case
|
// delete case
|
||||||
this.pushDeleteRemoteBranch(remoteBranch, branchOnRemote);
|
this.pushDeleteRemoteBranch(
|
||||||
|
this.refs[ORIGIN_PREFIX + options.destination],
|
||||||
|
this.origin.refs[options.destination]
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var remoteBranch = this.refs[options.source];
|
||||||
|
|
||||||
|
if (!this.origin.refs[options.destination]) {
|
||||||
|
this.makeBranchOnOriginAndTrack(
|
||||||
|
options.destination,
|
||||||
|
'HEAD'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
var branchOnRemote = this.origin.refs[options.source];
|
||||||
|
|
||||||
var sourceLocation = this.getOneBeforeCommit(options.source || 'HEAD');
|
var sourceLocation = this.getOneBeforeCommit(options.source || 'HEAD');
|
||||||
|
|
||||||
|
debugger;
|
||||||
// first check if this is even allowed by checking the sync between
|
// first check if this is even allowed by checking the sync between
|
||||||
this.checkUpstreamOfSource(
|
this.checkUpstreamOfSource(
|
||||||
this,
|
this,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue