diff --git a/spec/remote.spec.js b/spec/remote.spec.js index 0736b0df..a0cbbd83 100644 --- a/spec/remote.spec.js +++ b/spec/remote.spec.js @@ -304,5 +304,19 @@ describe('Git Remotes', function() { ); }); + it('doesnt let you fetch to master if you are checked out there', function() { + expectTreeAsync( + 'git clone; git push master:foo; git fakeTeamwork foo 2; git fetch origin foo^:blah; git fetch foo:master', + '{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"o/foo":{"target":"C1","id":"o/foo","remoteTrackingBranchID":null},"blah":{"target":"C2","id":"blah","remoteTrackingBranchID":null}},"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","remoteTrackingBranchID":null},"foo":{"target":"C3","id":"foo","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":"foo","id":"HEAD"}}}' + ); + }); + + it('doesnt let you delete branches that dont exist', function() { + expectTreeAsync( + 'git clone; git push :foo', + '{"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":"C1","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"master","id":"HEAD"}}}' + ); + }); + }); diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 5124e7a3..43246f16 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -685,6 +685,13 @@ var commandConfig = { var refspecParts = firstArg.split(':'); source = refspecParts[0]; destination = validateBranchName(engine, refspecParts[1]); + if (source === "" && !engine.origin.refs[options.destination]) { + throw new GitError({ + msg: intl.todo( + 'cannot delete branch ' + options.destination + ' which doesnt exist' + ) + }); + } } else { if (firstArg) { // we are using this arg as destination AND source. the dest branch diff --git a/src/js/git/index.js b/src/js/git/index.js index 9832421d..4c7cfb8f 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -1193,7 +1193,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { }, this); chain = chain.then(_.bind(function() { - // update all the destinations + // update all the destinations _.each(sourceDestPairs, function(pair) { var ours = this.refs[pair.destination]; var theirCommitID = this.origin.getCommitFromRef(pair.source).get('id'); diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index 8417969f..5cbf79a0 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -89,6 +89,10 @@ var LevelDropdownView = ContainedBase.extend({ if (id === this.JSON.selectedTab) { return; } + this.updateTabTo(id); + }, + + updateTabTo: function(id) { this.JSON.selectedTab = id; this.render(); if (this.selectedID) { @@ -119,7 +123,24 @@ var LevelDropdownView = ContainedBase.extend({ leftOrRight: function(delta) { this.deselectIconByID(this.selectedID); - this.selectedIndex = this.wrapIndex(this.selectedIndex + delta, this.getCurrentSequence()); + var index = this.selectedIndex + delta; + + var sequence = this.getCurrentSequence(); + var tabs = this.JSON.tabs; + // switch tabs now if needed / possible + if (index >= sequence.length && + this.getTabIndex() + 1 < tabs.length) { + this.switchToTabIndex(this.getTabIndex() + 1); + this.selectedIndex = 0; + } else if (index < 0 && + this.getTabIndex() - 1 >= 0) { + this.switchToTabIndex(this.getTabIndex() - 1); + this.selectedIndex = 0; + } else { + this.selectedIndex = this.wrapIndex( + this.selectedIndex + delta, this.getCurrentSequence() + ); + } this.updateSelectedIcon(); }, @@ -168,6 +189,18 @@ var LevelDropdownView = ContainedBase.extend({ this.selectedSequence = undefined; }, + getTabIndex: function() { + var ids = _.map(this.JSON.tabs, function(tab) { + return tab.id; + }); + return ids.indexOf(this.JSON.selectedTab); + }, + + switchToTabIndex: function(index) { + var tabID = this.JSON.tabs[index].id; + this.updateTabTo(tabID); + }, + wrapIndex: function(index, arr) { index = (index >= arr.length) ? 0 : index; index = (index < 0) ? arr.length - 1 : index;