mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +02:00
BOOM all tests pass, more progress on git fetch
This commit is contained in:
parent
b9ebaca62b
commit
f11f76bbe8
4 changed files with 20 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
|
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
|
||||||
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
|
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
|
||||||
|
|
||||||
var prompt = require('prompt');
|
prompt = require('prompt');
|
||||||
|
|
||||||
prompt.start();
|
prompt.start();
|
||||||
|
|
||||||
|
|
|
@ -226,5 +226,19 @@ describe('Git Remotes', function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('validates branch names when fetching', function() {
|
||||||
|
expectTreeAsync(
|
||||||
|
'git clone; git fakeTeamwork; git fetch master:HEAD; git fetch master:f<>',
|
||||||
|
'{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fetches only one remote if specified', function() {
|
||||||
|
expectTreeAsync(
|
||||||
|
'git clone;gc;git push origin master:banana;git fakeTeamwork banana;git fakeTeamwork master;git fetch origin banana',
|
||||||
|
'{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"o/banana":{"target":"C3","id":"o/banana","remoteTrackingBranchID":null},"banana":{"target":"C2","id":"banana","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C2"],"id":"C3"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C4","id":"master","remoteTrackingBranchID":null},"banana":{"target":"C3","id":"banana","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C2"],"id":"C3"},"C4":{"parents":["C1"],"id":"C4"}},"HEAD":{"target":"master","id":"HEAD"}}}'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -270,8 +270,6 @@ var commandConfig = {
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
destination = validateBranchName(engine, refspecParts[1]);
|
destination = validateBranchName(engine, refspecParts[1]);
|
||||||
|
|
||||||
// destination will be created by fetch, but check source
|
|
||||||
} else if (firstArg) {
|
} else if (firstArg) {
|
||||||
// here is the deal -- its JUST like git push. the first arg
|
// here is the deal -- its JUST like git push. the first arg
|
||||||
// is used as both the destination and the source, so we need
|
// is used as both the destination and the source, so we need
|
||||||
|
@ -279,8 +277,6 @@ var commandConfig = {
|
||||||
// the destination will be created locally
|
// the destination will be created locally
|
||||||
source = firstArg;
|
source = firstArg;
|
||||||
destination = firstArg;
|
destination = firstArg;
|
||||||
//var tracking = assertBranchIsRemoteTracking(engine, firstArg);
|
|
||||||
//options.branches = [engine.refs[tracking]];
|
|
||||||
}
|
}
|
||||||
if (source) { // empty string fails this check
|
if (source) { // empty string fails this check
|
||||||
assertIsRef(engine.origin, source);
|
assertIsRef(engine.origin, source);
|
||||||
|
|
|
@ -374,7 +374,7 @@ GitEngine.prototype.makeOrigin = function(treeString) {
|
||||||
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
|
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
|
||||||
var target = this.origin.refs[branchName].get('target');
|
var target = this.origin.refs[branchName].get('target');
|
||||||
var originTarget = this.findCommonAncestorWithRemote(
|
var originTarget = this.findCommonAncestorWithRemote(
|
||||||
target.get('id');
|
target.get('id')
|
||||||
);
|
);
|
||||||
return this.makeBranch(
|
return this.makeBranch(
|
||||||
ORIGIN_PREFIX + branchName,
|
ORIGIN_PREFIX + branchName,
|
||||||
|
@ -1037,7 +1037,7 @@ GitEngine.prototype.fetch = function(options) {
|
||||||
|
|
||||||
// ok this is just like git push -- if the destination does not exist,
|
// ok this is just like git push -- if the destination does not exist,
|
||||||
// we need to make it
|
// we need to make it
|
||||||
if (options.destination) {
|
if (options.destination && !this.refs[options.destination]) {
|
||||||
// its just like creating a branch, we will merge (if pulling) later
|
// its just like creating a branch, we will merge (if pulling) later
|
||||||
this.validateAndMakeBranch(
|
this.validateAndMakeBranch(
|
||||||
options.destination,
|
options.destination,
|
||||||
|
@ -1051,9 +1051,11 @@ GitEngine.prototype.fetch = function(options) {
|
||||||
if (options.source) {
|
if (options.source) {
|
||||||
// gah -- first we have to check that we even have a remote branch
|
// gah -- first we have to check that we even have a remote branch
|
||||||
// for this source (we know its on the remote based on validation)
|
// for this source (we know its on the remote based on validation)
|
||||||
if (!this.refs[ORIGIN_PREFX + options.source]) {
|
if (!this.refs[ORIGIN_PREFIX + options.source]) {
|
||||||
this.makeRemoteBranchForRemote(options.source);
|
this.makeRemoteBranchForRemote(options.source);
|
||||||
}
|
}
|
||||||
|
// now just specify branches to fetch based on this source
|
||||||
|
branchesToFetch = [this.refs[ORIGIN_PREFIX + options.source]];
|
||||||
} else {
|
} else {
|
||||||
branchesToFetch = this.branchCollection.filter(function(branch) {
|
branchesToFetch = this.branchCollection.filter(function(branch) {
|
||||||
return branch.getIsRemote();
|
return branch.getIsRemote();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue