Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocheckout on branch creation #752

Merged
merged 6 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
- Added support for cherry-pick conflict[#701](https://github.com/FredrikNoren/ungit/issues/701)
- Added wordwrap support for diffs [#721](https://github.com/FredrikNoren/ungit/issues/721)
- Support for Node6 [#745](https://github.com/FredrikNoren/ungit/pull/745/files)
- Added "autoCheckoutOnBranchCreate" option [#752](https://github.com/FredrikNoren/ungit/pull/752/files)

### Fixed
- Fix maxConcurrentGitOperations not limiting git processes [#707](https://github.com/FredrikNoren/ungit/issues/707)
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ module.exports = function(grunt) {
globals: {
'$': true,
'module': true,
'ungit': true
}
},
src: ['clicktests/**/*.js']
Expand Down
20 changes: 10 additions & 10 deletions clicktests/test.branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ suite.test('cherrypick success case', function(done) {
});
});

suite.test('Cherrypick self (causes error and creates ./git/CHERRY_PICK_HEAD but no conflicts)', function(done) {
helpers.click(page, '[data-ta-clickable="node-clickable-0"]')
helpers.waitForElementVisible(page, '[data-ta-action="cherry-pick"][data-ta-visible="true"]', function() {
helpers.click(page, '[data-ta-action="cherry-pick"][data-ta-visible="true"]');
helpers.waitForElementVisible(page, '[data-ta-container="git-error-container"]', function() {
if (helpers.elementVisible(page, '[data-ta-clickable="graph"]')) {
done();
} else {
done("Cheerypick self should cause error but should not get into merge state.")
}
suite.test('Auto checkout on branch creation.', function(done) {
// Set autoCheckoutOnBranchCreate=true on client side instead of restarting
// ungit with this option as this would be faster.
page.evaluate(function() {
ungit.config.autoCheckoutOnBranchCreate = true;
});

uiInteractions.createBranch(page, 'autoCheckout', function() {
helpers.waitForElementVisible(page, '[data-ta-name="autoCheckout"][data-ta-current="true"]', function() {
done();
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion components/graph/git-graph-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ GraphActions.CherryPick = function(graph, node) {
this.node = node;
this.visible = ko.computed(function() {
if (self.performProgressBar.running()) return true;
return self.graph.currentActionContext() == self.node
var context = self.graph.currentActionContext();
return context === self.node && self.graph.HEAD() && context.sha1 !== self.graph.HEAD().sha1
});
}
inherits(GraphActions.CherryPick, GraphActions.ActionBase);
Expand Down
9 changes: 5 additions & 4 deletions components/graph/git-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ GitNodeViewModel.prototype.showBranchingForm = function() {
GitNodeViewModel.prototype.createBranch = function() {
if (!this.canCreateRef()) return;
var self = this;
this.graph.server.postPromise('/branches', { path: this.graph.repoPath(), name: this.newBranchName(), startPoint: this.sha1 })
var command = ungit.config.autoCheckoutOnBranchCreate ? "/checkout" : "/branches";

this.graph.server.postPromise(command, { path: this.graph.repoPath(), name: this.newBranchName(), sha1: this.sha1 })
.then(function() {
var newRef = self.graph.getRef('refs/heads/' + self.newBranchName());
newRef.node(self);
self.graph.getRef('refs/heads/' + self.newBranchName()).node(self);
}).finally(function() {
self.branchingFormVisible(false);
self.newBranchName('');
Expand All @@ -166,7 +167,7 @@ GitNodeViewModel.prototype.createBranch = function() {
GitNodeViewModel.prototype.createTag = function() {
if (!this.canCreateRef()) return;
var self = this;
this.graph.server.postPromise('/tags', { path: this.graph.repoPath(), name: this.newBranchName(), startPoint: this.sha1 })
this.graph.server.postPromise('/tags', { path: this.graph.repoPath(), name: this.newBranchName(), sha1: this.sha1 })
.then(function() {
var newRef = self.graph.getRef('tag: refs/tags/' + self.newBranchName());
newRef.node(self);
Expand Down
4 changes: 2 additions & 2 deletions components/graph/git-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ RefViewModel.prototype.moveTo = function(target, callback) {
if (this.current()) {
this.server.post('/reset', { path: this.graph.repoPath(), to: target, mode: 'hard' }, callbackWithRefSet);
} else if (this.isTag) {
this.server.post('/tags', { path: this.graph.repoPath(), name: this.refName, startPoint: target, force: true }, callbackWithRefSet);
this.server.post('/tags', { path: this.graph.repoPath(), name: this.refName, sha1: target, force: true }, callbackWithRefSet);
} else {
this.server.post('/branches', { path: this.graph.repoPath(), name: this.refName, startPoint: target, force: true }, callbackWithRefSet);
this.server.post('/branches', { path: this.graph.repoPath(), name: this.refName, sha1: target, force: true }, callbackWithRefSet);
}
} else {
var pushReq = { path: this.graph.repoPath(), remote: this.remote, refSpec: target, remoteBranch: this.refName };
Expand Down
8 changes: 6 additions & 2 deletions source/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ const defaultConfig = {
disableDiscardMuteTime: 60 * 1000 * 5, // 5 mins

// Allowed number of retry for git "index.lock" conflict
lockConflictRetryCount: 3
lockConflictRetryCount: 3,

// Auto checkout the created branch on creation
autoCheckoutOnBranchCreate: false,
};

// Works for now but should be moved to bin/ungit
Expand Down Expand Up @@ -162,7 +165,8 @@ let argv = yargs
.describe('fileSeparator', 'OS dependent file separator')
.describe('disableDiscardWarning', 'disable warning popup at discard')
.describe('disableDiscardMuteTime', 'duration of discard warning dialog mute time should it be muted')
.describe('lockConflictRetryCount', 'Allowed number of retry for git "index.lock" conflict');
.describe('lockConflictRetryCount', 'Allowed number of retry for git "index.lock" conflict')
.describe('autoCheckoutOnBranchCreate', 'Auto checkout the created branch on creation');

// If not triggered by test, then do strict option check
if (argv.$0.indexOf('mocha') === -1) {
Expand Down
13 changes: 10 additions & 3 deletions source/git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ exports.registerApi = function(env) {
});

app.post(exports.pathPrefix + '/branches', ensureAuthenticated, ensurePathExists, function(req, res){
var commands = ['branch', (req.body.force ? '-f' : ''), req.body.name.trim(), (req.body.startPoint || 'HEAD').trim()];
var commands = ['branch', (req.body.force ? '-f' : ''), req.body.name.trim(), (req.body.sha1 || 'HEAD').trim()];

jsonResultOrFailProm(res, gitPromise(commands, req.body.path))
.finally(emitGitDirectoryChanged.bind(null, req.body.path));
Expand Down Expand Up @@ -312,7 +312,7 @@ exports.registerApi = function(env) {
});

app.post(exports.pathPrefix + '/tags', ensureAuthenticated, ensurePathExists, function(req, res){
var commands = ['tag', (req.body.force ? '-f' : ''), '-a', req.body.name.trim(), '-m', req.body.name.trim(), (req.body.startPoint || 'HEAD').trim()];
var commands = ['tag', (req.body.force ? '-f' : ''), '-a', req.body.name.trim(), '-m', req.body.name.trim(), (req.body.sha1 || 'HEAD').trim()];

jsonResultOrFailProm(res, gitPromise(commands, req.body.path))
.finally(emitGitDirectoryChanged.bind(null, req.body.path));
Expand All @@ -331,7 +331,14 @@ exports.registerApi = function(env) {
});

app.post(exports.pathPrefix + '/checkout', ensureAuthenticated, ensurePathExists, function(req, res) {
jsonResultOrFailProm(res, autoStashExecuteAndPop(['checkout', req.body.name.trim()], req.body.path))
var arg = null;
if (!!req.body.sha1) {
arg = ['checkout', '-b', req.body.name.trim(), req.body.sha1];
} else {
arg = ['checkout', req.body.name.trim()];
}

jsonResultOrFailProm(res, autoStashExecuteAndPop(arg, req.body.path))
.then(emitGitDirectoryChanged.bind(null, req.body.path))
.then(emitWorkingTreeChanged.bind(null, req.body.path));
});
Expand Down