mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +02:00
Issue #131 awesomely now respect remote tracking branch info for git pull
This commit is contained in:
parent
79d65e739a
commit
7034eb76fa
8 changed files with 227 additions and 96 deletions
198
build/bundle.js
198
build/bundle.js
|
@ -8305,8 +8305,8 @@ GitEngine.prototype.fetch = function(options) {
|
|||
|
||||
GitEngine.prototype.pull = function(options) {
|
||||
options = options || {};
|
||||
var localBranch = this.refs['master'];
|
||||
var remoteBranch = this.refs['o/master'];
|
||||
var localBranch = this.getOneBeforeCommit('HEAD');
|
||||
var remoteBranch = this.refs[options.source];
|
||||
|
||||
// no matter what fetch
|
||||
var pendingFetch = this.fetch({
|
||||
|
@ -8369,13 +8369,8 @@ GitEngine.prototype.pullFinishWithMerge = function(
|
|||
var chain = pendingFetch.chain;
|
||||
var deferred = pendingFetch.deferred;
|
||||
|
||||
// TODO -- hax hax. need to loop all branches
|
||||
// first lets check if we even need to merge (TODO -- expand this)
|
||||
var currentLocation = 'master';
|
||||
var targetSource = 'o/master';
|
||||
|
||||
chain = chain.then(_.bind(function() {
|
||||
if (this.mergeCheck(targetSource, currentLocation)) {
|
||||
if (this.mergeCheck(remoteBranch, localBranch)) {
|
||||
this.command.set('error', new CommandResult({
|
||||
msg: intl.str('git-result-uptodate')
|
||||
}));
|
||||
|
@ -8411,7 +8406,7 @@ GitEngine.prototype.pullFinishWithMerge = function(
|
|||
return this.animationFactory.getDelayedPromise(700);
|
||||
}, this));
|
||||
chain = chain.then(_.bind(function() {
|
||||
var newCommit = this.merge('o/master');
|
||||
var newCommit = this.merge(remoteBranch);
|
||||
if (!newCommit) {
|
||||
// it is a fast forward
|
||||
return this.animationFactory.playRefreshAnimation(this.gitVisuals);
|
||||
|
@ -10774,6 +10769,29 @@ var crappyUnescape = function(str) {
|
|||
return str.replace(/'/g, "'").replace(///g, "/");
|
||||
};
|
||||
|
||||
var ensureBranchIsRemoteTracking = function(engine, branchName) {
|
||||
branchName = crappyUnescape(branchName);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
var branch = engine.resolveID(branchName);
|
||||
if (branch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
|
||||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
||||
});
|
||||
}
|
||||
return tracking;
|
||||
};
|
||||
|
||||
var commandConfig = {
|
||||
commit: {
|
||||
sc: /^(gc|git ci)($|\s)/,
|
||||
|
@ -10874,12 +10892,51 @@ var commandConfig = {
|
|||
});
|
||||
}
|
||||
|
||||
// here is the deal -- git pull is pretty complex with
|
||||
// the arguments it wants. Either you can:
|
||||
// A) specify the remote branch you want to
|
||||
// merge & fetch, in which case it completely
|
||||
// ignores the properties of branch you are on, or
|
||||
//
|
||||
// B) specify no args, in which case it figures out
|
||||
// the branch to fetch from the remote tracking
|
||||
// and merges those in.
|
||||
|
||||
// so lets switch on A/B here
|
||||
|
||||
var commandOptions = command.getOptionsMap();
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.pull({
|
||||
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'
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
var tracking;
|
||||
if (generalArgs[1]) {
|
||||
tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.source = tracking;
|
||||
} else {
|
||||
// cant be detached
|
||||
if (engine.getDetachedHead()) {
|
||||
throw new GitError({
|
||||
msg: intl.todo('Git pull can not be executed in detached HEAD mode!')
|
||||
});
|
||||
}
|
||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
||||
tracking = ensureBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
options.source = tracking;
|
||||
}
|
||||
|
||||
engine.pull(options);
|
||||
}
|
||||
},
|
||||
|
||||
fakeTeamwork: {
|
||||
|
@ -10959,25 +11016,7 @@ var commandConfig = {
|
|||
}
|
||||
|
||||
if (generalArgs[1]) {
|
||||
var branchName = crappyUnescape(generalArgs[1]);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
var branch = engine.resolveID(branchName);
|
||||
if (branch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
|
||||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
||||
});
|
||||
}
|
||||
var tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.branches = [engine.refs[tracking]];
|
||||
}
|
||||
|
||||
|
@ -25325,6 +25364,29 @@ var crappyUnescape = function(str) {
|
|||
return str.replace(/'/g, "'").replace(///g, "/");
|
||||
};
|
||||
|
||||
var ensureBranchIsRemoteTracking = function(engine, branchName) {
|
||||
branchName = crappyUnescape(branchName);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
var branch = engine.resolveID(branchName);
|
||||
if (branch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
|
||||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
||||
});
|
||||
}
|
||||
return tracking;
|
||||
};
|
||||
|
||||
var commandConfig = {
|
||||
commit: {
|
||||
sc: /^(gc|git ci)($|\s)/,
|
||||
|
@ -25425,12 +25487,51 @@ var commandConfig = {
|
|||
});
|
||||
}
|
||||
|
||||
// here is the deal -- git pull is pretty complex with
|
||||
// the arguments it wants. Either you can:
|
||||
// A) specify the remote branch you want to
|
||||
// merge & fetch, in which case it completely
|
||||
// ignores the properties of branch you are on, or
|
||||
//
|
||||
// B) specify no args, in which case it figures out
|
||||
// the branch to fetch from the remote tracking
|
||||
// and merges those in.
|
||||
|
||||
// so lets switch on A/B here
|
||||
|
||||
var commandOptions = command.getOptionsMap();
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.pull({
|
||||
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'
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
var tracking;
|
||||
if (generalArgs[1]) {
|
||||
tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.source = tracking;
|
||||
} else {
|
||||
// cant be detached
|
||||
if (engine.getDetachedHead()) {
|
||||
throw new GitError({
|
||||
msg: intl.todo('Git pull can not be executed in detached HEAD mode!')
|
||||
});
|
||||
}
|
||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
||||
tracking = ensureBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
options.source = tracking;
|
||||
}
|
||||
|
||||
engine.pull(options);
|
||||
}
|
||||
},
|
||||
|
||||
fakeTeamwork: {
|
||||
|
@ -25510,25 +25611,7 @@ var commandConfig = {
|
|||
}
|
||||
|
||||
if (generalArgs[1]) {
|
||||
var branchName = crappyUnescape(generalArgs[1]);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
var branch = engine.resolveID(branchName);
|
||||
if (branch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
|
||||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
||||
});
|
||||
}
|
||||
var tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.branches = [engine.refs[tracking]];
|
||||
}
|
||||
|
||||
|
@ -27161,8 +27244,8 @@ GitEngine.prototype.fetch = function(options) {
|
|||
|
||||
GitEngine.prototype.pull = function(options) {
|
||||
options = options || {};
|
||||
var localBranch = this.refs['master'];
|
||||
var remoteBranch = this.refs['o/master'];
|
||||
var localBranch = this.getOneBeforeCommit('HEAD');
|
||||
var remoteBranch = this.refs[options.source];
|
||||
|
||||
// no matter what fetch
|
||||
var pendingFetch = this.fetch({
|
||||
|
@ -27225,13 +27308,8 @@ GitEngine.prototype.pullFinishWithMerge = function(
|
|||
var chain = pendingFetch.chain;
|
||||
var deferred = pendingFetch.deferred;
|
||||
|
||||
// TODO -- hax hax. need to loop all branches
|
||||
// first lets check if we even need to merge (TODO -- expand this)
|
||||
var currentLocation = 'master';
|
||||
var targetSource = 'o/master';
|
||||
|
||||
chain = chain.then(_.bind(function() {
|
||||
if (this.mergeCheck(targetSource, currentLocation)) {
|
||||
if (this.mergeCheck(remoteBranch, localBranch)) {
|
||||
this.command.set('error', new CommandResult({
|
||||
msg: intl.str('git-result-uptodate')
|
||||
}));
|
||||
|
@ -27267,7 +27345,7 @@ GitEngine.prototype.pullFinishWithMerge = function(
|
|||
return this.animationFactory.getDelayedPromise(700);
|
||||
}, this));
|
||||
chain = chain.then(_.bind(function() {
|
||||
var newCommit = this.merge('o/master');
|
||||
var newCommit = this.merge(remoteBranch);
|
||||
if (!newCommit) {
|
||||
// it is a fast forward
|
||||
return this.animationFactory.playRefreshAnimation(this.gitVisuals);
|
||||
|
|
1
build/bundle.min.0b3ef8c2.js
Normal file
1
build/bundle.min.0b3ef8c2.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
build/bundle.min.js
vendored
2
build/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -445,7 +445,7 @@
|
|||
For a much easier time perusing the source, see the individual files at:
|
||||
https://github.com/pcottle/learnGitBranching
|
||||
-->
|
||||
<script src="build/bundle.min.9efac7f0.js"></script>
|
||||
<script src="build/bundle.min.0b3ef8c2.js"></script>
|
||||
|
||||
<!-- The advantage of github pages: super-easy, simple, slick static hostic.
|
||||
The downside? No raw logs to parse for analytics, so I have to include
|
||||
|
|
|
@ -85,5 +85,19 @@ describe('Git Remotes', function() {
|
|||
'{"branches":{"master":{"target":"C2","id":"master"},"o/master":{"target":"C1","id":"o/master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"master","id":"HEAD"}}}'
|
||||
);
|
||||
});
|
||||
|
||||
it('pulls from different remote tracking branches nad merges', function() {
|
||||
expectTreeAsync(
|
||||
'git branch side; git clone; git fakeTeamwork side;git commit; git pull origin side;git pull;git fakeTeamwork master;git pull',
|
||||
'{"branches":{"master":{"target":"C6","id":"master"},"side":{"target":"C1","id":"side"},"o/master":{"target":"C5","id":"o/master"},"o/side":{"target":"C2","id":"o/side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C3":{"parents":["C1"],"id":"C3"},"C2":{"parents":["C1"],"id":"C2"},"C4":{"parents":["C2","C3"],"id":"C4"},"C5":{"parents":["C1"],"id":"C5"},"C6":{"parents":["C4","C5"],"id":"C6"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C5","id":"master"},"side":{"target":"C2","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C5":{"parents":["C1"],"id":"C5"}},"HEAD":{"target":"master","id":"HEAD"}}}'
|
||||
);
|
||||
});
|
||||
|
||||
it('pulls with rebase from different remote tracking', function() {
|
||||
expectTreeAsync(
|
||||
'git branch side; git clone; git fakeTeamwork side;git commit; git pull origin side --rebase',
|
||||
'%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C3%27%22%2C%22id%22%3A%22master%22%7D%2C%22side%22%3A%7B%22target%22%3A%22C1%22%2C%22id%22%3A%22side%22%7D%2C%22o/master%22%3A%7B%22target%22%3A%22C1%22%2C%22id%22%3A%22o/master%22%7D%2C%22o/side%22%3A%7B%22target%22%3A%22C2%22%2C%22id%22%3A%22o/side%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C3%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C3%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%2C%22C3%27%22%3A%7B%22parents%22%3A%5B%22C2%22%5D%2C%22id%22%3A%22C3%27%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22master%22%2C%22id%22%3A%22HEAD%22%7D%2C%22originTree%22%3A%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C1%22%2C%22id%22%3A%22master%22%7D%2C%22side%22%3A%7B%22target%22%3A%22C2%22%2C%22id%22%3A%22side%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22side%22%2C%22id%22%3A%22HEAD%22%7D%7D%7D'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -11,6 +11,29 @@ var crappyUnescape = function(str) {
|
|||
return str.replace(/'/g, "'").replace(///g, "/");
|
||||
};
|
||||
|
||||
var ensureBranchIsRemoteTracking = function(engine, branchName) {
|
||||
branchName = crappyUnescape(branchName);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
var branch = engine.resolveID(branchName);
|
||||
if (branch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
|
||||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
||||
});
|
||||
}
|
||||
return tracking;
|
||||
};
|
||||
|
||||
var commandConfig = {
|
||||
commit: {
|
||||
sc: /^(gc|git ci)($|\s)/,
|
||||
|
@ -111,12 +134,51 @@ var commandConfig = {
|
|||
});
|
||||
}
|
||||
|
||||
// here is the deal -- git pull is pretty complex with
|
||||
// the arguments it wants. Either you can:
|
||||
// A) specify the remote branch you want to
|
||||
// merge & fetch, in which case it completely
|
||||
// ignores the properties of branch you are on, or
|
||||
//
|
||||
// B) specify no args, in which case it figures out
|
||||
// the branch to fetch from the remote tracking
|
||||
// and merges those in.
|
||||
|
||||
// so lets switch on A/B here
|
||||
|
||||
var commandOptions = command.getOptionsMap();
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.pull({
|
||||
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'
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
var tracking;
|
||||
if (generalArgs[1]) {
|
||||
tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.source = tracking;
|
||||
} else {
|
||||
// cant be detached
|
||||
if (engine.getDetachedHead()) {
|
||||
throw new GitError({
|
||||
msg: intl.todo('Git pull can not be executed in detached HEAD mode!')
|
||||
});
|
||||
}
|
||||
var oneBefore = engine.getOneBeforeCommit('HEAD');
|
||||
tracking = ensureBranchIsRemoteTracking(engine, oneBefore.get('id'));
|
||||
options.source = tracking;
|
||||
}
|
||||
|
||||
engine.pull(options);
|
||||
}
|
||||
},
|
||||
|
||||
fakeTeamwork: {
|
||||
|
@ -196,25 +258,7 @@ var commandConfig = {
|
|||
}
|
||||
|
||||
if (generalArgs[1]) {
|
||||
var branchName = crappyUnescape(generalArgs[1]);
|
||||
if (!engine.refs[branchName]) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
var branch = engine.resolveID(branchName);
|
||||
if (branch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a branch!')
|
||||
});
|
||||
}
|
||||
|
||||
var tracking = branch.getRemoteTrackingBranchID();
|
||||
if (!tracking) {
|
||||
throw new GitError({
|
||||
msg: intl.todo(branchName + ' is not a remote tracking branch!')
|
||||
});
|
||||
}
|
||||
var tracking = ensureBranchIsRemoteTracking(engine, generalArgs[1]);
|
||||
options.branches = [engine.refs[tracking]];
|
||||
}
|
||||
|
||||
|
|
|
@ -1079,8 +1079,8 @@ GitEngine.prototype.fetch = function(options) {
|
|||
|
||||
GitEngine.prototype.pull = function(options) {
|
||||
options = options || {};
|
||||
var localBranch = this.refs['master'];
|
||||
var remoteBranch = this.refs['o/master'];
|
||||
var localBranch = this.getOneBeforeCommit('HEAD');
|
||||
var remoteBranch = this.refs[options.source];
|
||||
|
||||
// no matter what fetch
|
||||
var pendingFetch = this.fetch({
|
||||
|
@ -1143,13 +1143,8 @@ GitEngine.prototype.pullFinishWithMerge = function(
|
|||
var chain = pendingFetch.chain;
|
||||
var deferred = pendingFetch.deferred;
|
||||
|
||||
// TODO -- hax hax. need to loop all branches
|
||||
// first lets check if we even need to merge (TODO -- expand this)
|
||||
var currentLocation = 'master';
|
||||
var targetSource = 'o/master';
|
||||
|
||||
chain = chain.then(_.bind(function() {
|
||||
if (this.mergeCheck(targetSource, currentLocation)) {
|
||||
if (this.mergeCheck(remoteBranch, localBranch)) {
|
||||
this.command.set('error', new CommandResult({
|
||||
msg: intl.str('git-result-uptodate')
|
||||
}));
|
||||
|
@ -1185,7 +1180,7 @@ GitEngine.prototype.pullFinishWithMerge = function(
|
|||
return this.animationFactory.getDelayedPromise(700);
|
||||
}, this));
|
||||
chain = chain.then(_.bind(function() {
|
||||
var newCommit = this.merge('o/master');
|
||||
var newCommit = this.merge(remoteBranch);
|
||||
if (!newCommit) {
|
||||
// it is a fast forward
|
||||
return this.animationFactory.playRefreshAnimation(this.gitVisuals);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue