mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (generalArgs[0] !== 'origin') {
|
||||
throw new GitError({
|
||||
|
@ -42,7 +50,9 @@ var assertBranchIsRemoteTracking = function(engine, branchName) {
|
|||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
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;
|
||||
|
@ -560,24 +570,32 @@ var commandConfig = {
|
|||
command.twoArgsImpliedOrigin(generalArgs);
|
||||
assertOriginSpecified(generalArgs);
|
||||
|
||||
var tracking;
|
||||
var destination;
|
||||
var source;
|
||||
var firstArg = generalArgs[1];
|
||||
if (firstArg) {
|
||||
if (isColonRefspec(firstArg)) {
|
||||
var refspecParts = firstArg.split(':');
|
||||
source = refspecParts[0];
|
||||
tracking = assertBranchIsRemoteTracking(engine, refspecParts[1]);
|
||||
destination = refspecParts[1];
|
||||
// TODO -- assert good branch name
|
||||
} else {
|
||||
tracking = assertBranchIsRemoteTracking(engine, firstArg);
|
||||
// we are using this org as both destination and source
|
||||
destination = firstArg;
|
||||
source = firstArg;
|
||||
}
|
||||
destination = validateAndAssertBranchName(engine, destination);
|
||||
} else {
|
||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
||||
tracking = assertBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
source = engine.getOneBeforeCommit('HEAD');
|
||||
destination = source;
|
||||
assertBranchIsRemoteTracking(source);
|
||||
}
|
||||
if (source) {
|
||||
assertIsRef(engine, source);
|
||||
}
|
||||
|
||||
engine.push({
|
||||
destination: tracking,
|
||||
destination: destination,
|
||||
source: source
|
||||
});
|
||||
}
|
||||
|
|
|
@ -366,15 +366,32 @@ GitEngine.prototype.makeOrigin = function(treeString) {
|
|||
}
|
||||
|
||||
// now we have something in common, lets make the tracking branch
|
||||
var originBranch = this.makeBranch(
|
||||
var remoteBranch = this.makeBranch(
|
||||
ORIGIN_PREFIX + branchName,
|
||||
this.getCommitFromRef(originTarget)
|
||||
);
|
||||
|
||||
this.setLocalToTrackRemote(this.refs[branchJSON.id], originBranch);
|
||||
this.setLocalToTrackRemote(this.refs[branchJSON.id], remoteBranch);
|
||||
}, 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) {
|
||||
localBranch.setRemoteTrackingBranchID(remoteBranch.get('id'));
|
||||
|
||||
|
@ -859,16 +876,28 @@ GitEngine.prototype.descendSortDepth = function(objects) {
|
|||
|
||||
GitEngine.prototype.push = function(options) {
|
||||
options = options || {};
|
||||
var remoteBranch = this.refs[options.destination];
|
||||
var branchOnRemote = this.origin.refs[remoteBranch.getBaseID()];
|
||||
|
||||
if (options.source === "") {
|
||||
// delete case
|
||||
this.pushDeleteRemoteBranch(remoteBranch, branchOnRemote);
|
||||
this.pushDeleteRemoteBranch(
|
||||
this.refs[ORIGIN_PREFIX + options.destination],
|
||||
this.origin.refs[options.destination]
|
||||
);
|
||||
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');
|
||||
|
||||
debugger;
|
||||
// first check if this is even allowed by checking the sync between
|
||||
this.checkUpstreamOfSource(
|
||||
this,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue