mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 17:00:04 +02:00
Issue #129 pushing to different remote branches
This commit is contained in:
parent
7034eb76fa
commit
bfd8483d90
8 changed files with 165 additions and 114 deletions
|
@ -11,7 +11,17 @@ var crappyUnescape = function(str) {
|
|||
return str.replace(/'/g, "'").replace(///g, "/");
|
||||
};
|
||||
|
||||
var ensureBranchIsRemoteTracking = function(engine, branchName) {
|
||||
var assertOriginSpecified = function(generalArgs) {
|
||||
if (generalArgs[0] !== 'origin') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(
|
||||
generalArgs[0] + ' is not a remote in your repository! try origin'
|
||||
)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var assertBranchIsRemoteTracking = function(engine, branchName) {
|
||||
branchName = crappyUnescape(branchName);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
|
@ -147,37 +157,28 @@ var commandConfig = {
|
|||
// so lets switch on A/B here
|
||||
|
||||
var commandOptions = command.getOptionsMap();
|
||||
var options = {
|
||||
isRebase: commandOptions['--rebase']
|
||||
};
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.twoArgsImpliedOrigin(generalArgs);
|
||||
|
||||
if (generalArgs[0] !== 'origin') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(
|
||||
generalArgs[0] + ' is not a remote in your repository! try origin'
|
||||
)
|
||||
});
|
||||
}
|
||||
assertOriginSpecified(generalArgs);
|
||||
|
||||
var tracking;
|
||||
if (generalArgs[1]) {
|
||||
tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.source = tracking;
|
||||
tracking = assertBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
} else {
|
||||
// cant be detached
|
||||
if (engine.getDetachedHead()) {
|
||||
throw new GitError({
|
||||
msg: intl.todo('Git pull can not be executed in detached HEAD mode!')
|
||||
msg: intl.todo('Git pull can not be executed in detached HEAD mode if no remote branch specified!')
|
||||
});
|
||||
}
|
||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
||||
tracking = ensureBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
options.source = tracking;
|
||||
tracking = assertBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
}
|
||||
|
||||
engine.pull(options);
|
||||
engine.pull({
|
||||
source: tracking,
|
||||
isRebase: commandOptions['--rebase']
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -249,16 +250,10 @@ var commandConfig = {
|
|||
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.twoArgsImpliedOrigin(generalArgs);
|
||||
if (generalArgs[0] !== 'origin') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(
|
||||
generalArgs[0] + ' is not a remote in your repository! try origin'
|
||||
)
|
||||
});
|
||||
}
|
||||
assertOriginSpecified(generalArgs);
|
||||
|
||||
if (generalArgs[1]) {
|
||||
var tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
var tracking = assertBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.branches = [engine.refs[tracking]];
|
||||
}
|
||||
|
||||
|
@ -541,8 +536,26 @@ var commandConfig = {
|
|||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.push();
|
||||
|
||||
var options = {};
|
||||
// git push is pretty complex in terms of
|
||||
// the arguments it wants as well -- see
|
||||
// git pull for a more detailed description.
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.twoArgsImpliedOrigin(generalArgs);
|
||||
assertOriginSpecified(generalArgs);
|
||||
|
||||
var tracking;
|
||||
if (generalArgs[1]) {
|
||||
tracking = assertBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
} else {
|
||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
||||
tracking = assertBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
}
|
||||
|
||||
engine.push({
|
||||
destination: tracking
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -861,14 +861,15 @@ GitEngine.prototype.descendSortDepth = function(objects) {
|
|||
|
||||
GitEngine.prototype.push = function(options) {
|
||||
options = options || {};
|
||||
var localBranch = this.refs['master'];
|
||||
var remoteBranch = this.origin.refs['master'];
|
||||
var localBranch = this.getOneBeforeCommit('HEAD');
|
||||
var remoteBranch = this.refs[options.destination];
|
||||
var branchOnRemote = this.origin.refs[remoteBranch.getBaseID()];
|
||||
|
||||
// first check if this is even allowed by checking the sync between
|
||||
this.checkUpstreamOfSource(
|
||||
this,
|
||||
this.origin,
|
||||
remoteBranch,
|
||||
branchOnRemote,
|
||||
localBranch,
|
||||
intl.str('git-error-origin-push-no-ff')
|
||||
);
|
||||
|
@ -876,7 +877,7 @@ GitEngine.prototype.push = function(options) {
|
|||
var commitsToMake = this.getTargetGraphDifference(
|
||||
this.origin,
|
||||
this,
|
||||
remoteBranch,
|
||||
branchOnRemote,
|
||||
localBranch
|
||||
);
|
||||
|
||||
|
@ -913,7 +914,7 @@ GitEngine.prototype.push = function(options) {
|
|||
chain = chain.then(_.bind(function() {
|
||||
return this.animationFactory.playHighlightPromiseAnimation(
|
||||
this.refs[commitJSON.id],
|
||||
remoteBranch
|
||||
branchOnRemote
|
||||
);
|
||||
}, this));
|
||||
|
||||
|
@ -928,7 +929,7 @@ GitEngine.prototype.push = function(options) {
|
|||
chain = chain.then(_.bind(function() {
|
||||
var localLocationID = localBranch.get('target').get('id');
|
||||
var remoteCommit = this.origin.refs[localLocationID];
|
||||
this.origin.setTargetLocation(remoteBranch, remoteCommit);
|
||||
this.origin.setTargetLocation(branchOnRemote, remoteCommit);
|
||||
// unhighlight local
|
||||
this.animationFactory.playRefreshAnimation(this.gitVisuals);
|
||||
return this.animationFactory.playRefreshAnimation(this.origin.gitVisuals);
|
||||
|
@ -937,9 +938,7 @@ GitEngine.prototype.push = function(options) {
|
|||
// HAX HAX update master and remote tracking for master
|
||||
chain = chain.then(_.bind(function() {
|
||||
var localCommit = this.getCommitFromRef(localBranch);
|
||||
var remoteBranchID = localBranch.getRemoteTrackingBranchID();
|
||||
// less hacks hax
|
||||
this.setTargetLocation(this.refs[remoteBranchID], localCommit);
|
||||
this.setTargetLocation(remoteBranch, localCommit);
|
||||
return this.animationFactory.playRefreshAnimation(this.gitVisuals);
|
||||
}, this));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue