Skip to content

Commit 3aa6b48

Browse files
committed
Finalize commit and push
1 parent d3aaefc commit 3aa6b48

File tree

5 files changed

+169
-68
lines changed

5 files changed

+169
-68
lines changed

schema/plugin.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
"description": "If true, use a simplified concept of staging. Only files with changes are shown (instead of showing staged/changed/untracked), and all files with changes will be automatically staged",
6060
"default": false
6161
},
62-
"useCommitAndPush": {
62+
"commitAndPush": {
6363
"type": "boolean",
64-
"title": "Combine commit and push in one button",
65-
"description": "If true, combine commit and push in one button.",
66-
"default": false
64+
"title": "Trigger push on commit",
65+
"description": "Whether to trigger or not a push for each commit.",
66+
"default": true
6767
}
6868
},
6969
"jupyter.lab.shortcuts": [

src/components/CommitBox.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
import { TranslationBundle } from '@jupyterlab/translation';
2+
import { CommandRegistry } from '@lumino/commands';
13
import * as React from 'react';
24
import TextareaAutosize from 'react-textarea-autosize';
35
import {
4-
commitFormClass,
5-
commitSummaryClass,
6+
commitButtonClass,
67
commitDescriptionClass,
7-
commitButtonClass
8+
commitFormClass,
9+
commitSummaryClass
810
} from '../style/CommitBox';
9-
import { TranslationBundle } from '@jupyterlab/translation';
10-
import { CommandRegistry } from '@lumino/commands';
1111
import { CommandIDs } from '../tokens';
12-
import { Git } from '../tokens';
1312

1413
/**
1514
* Interface describing component properties.
@@ -21,23 +20,20 @@ export interface ICommitBoxProps {
2120
commands: CommandRegistry;
2221

2322
/**
24-
* Current list of branches.
23+
* Boolean indicating whether files currently exist which have changes to commit.
2524
*/
26-
branches: Git.IBranch[];
25+
hasFiles: boolean;
2726

2827
/**
29-
* Boolean indicating whether to use simplified commit-and-push instead of commit button
28+
* Commit button label
3029
*/
31-
useCommitAndPush: boolean;
30+
label: string;
3231

33-
/**
34-
* Boolean indicating whether files currently exist which have changes to commit.
35-
*/
36-
hasFiles: boolean;
3732
/**
3833
* The application language translator.
3934
*/
4035
trans: TranslationBundle;
36+
4137
/**
4238
* Callback to invoke in order to commit changes.
4339
*
@@ -102,11 +98,7 @@ export class CommitBox extends React.Component<
10298
? this.props.trans.__('Disabled: No files are staged for commit')
10399
: !this.state.summary
104100
? this.props.trans.__('Disabled: No commit message summary')
105-
: !this.props.useCommitAndPush
106-
? this.props.trans.__('Commit')
107-
: !this.props.branches.some(branch => branch.is_remote_branch)
108-
? this.props.trans.__('Disabled: No remote repository defined')
109-
: this.props.trans.__('Commit and push');
101+
: this.props.label;
110102

111103
const shortcutHint = CommandRegistry.formatKeystroke(
112104
this._getSubmitKeystroke()
@@ -140,9 +132,7 @@ export class CommitBox extends React.Component<
140132
className={commitButtonClass}
141133
type="button"
142134
title={title}
143-
value={!this.props.useCommitAndPush
144-
? this.props.trans.__('Commit')
145-
: this.props.trans.__('Commit and push')}
135+
value={this.props.label}
146136
disabled={disabled}
147137
onClick={this._onCommitSubmit}
148138
/>
@@ -154,10 +144,7 @@ export class CommitBox extends React.Component<
154144
* Whether a commit can be performed (files are staged and summary is not empty).
155145
*/
156146
private _canCommit(): boolean {
157-
const canAlsoPush = this.props.useCommitAndPush
158-
? this.props.branches.some(branch => branch.is_remote_branch)
159-
: true;
160-
return !!(this.props.hasFiles && this.state.summary && canAlsoPush);
147+
return !!(this.props.hasFiles && this.state.summary);
161148
}
162149

163150
/**

src/components/GitPanel.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { showDialog } from '@jupyterlab/apputils';
22
import { PathExt } from '@jupyterlab/coreutils';
33
import { FileBrowserModel } from '@jupyterlab/filebrowser';
44
import { ISettingRegistry } from '@jupyterlab/settingregistry';
5+
import { TranslationBundle } from '@jupyterlab/translation';
56
import { CommandRegistry } from '@lumino/commands';
67
import { JSONObject } from '@lumino/coreutils';
78
import { Signal } from '@lumino/signaling';
89
import Tab from '@material-ui/core/Tab';
910
import Tabs from '@material-ui/core/Tabs';
10-
import { TranslationBundle } from '@jupyterlab/translation';
1111
import * as React from 'react';
1212
import { Logger } from '../logger';
1313
import { GitExtension } from '../model';
@@ -260,8 +260,11 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
260260
console.error(error);
261261
this.props.logger.log({ ...errorLog, error });
262262
}
263+
const hasRemote = this.props.model.branches.some(
264+
branch => branch.is_remote_branch
265+
);
263266
// If enabled commit and push, push here
264-
if (this.props.settings.composite['useCommitAndPush']) {
267+
if (this.props.settings.composite['commitAndPush'] && hasRemote) {
265268
await this.props.commands.execute(CommandIDs.gitPush);
266269
}
267270
};
@@ -371,6 +374,14 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
371374
* @returns React element
372375
*/
373376
private _renderChanges(): React.ReactElement {
377+
const hasRemote = this.props.model.branches.some(
378+
branch => branch.is_remote_branch
379+
);
380+
const commitAndPush =
381+
(this.props.settings.composite['commitAndPush'] as boolean) && hasRemote;
382+
const buttonLabel = commitAndPush
383+
? this.props.trans.__('Commit and Push')
384+
: this.props.trans.__('Commit');
374385
return (
375386
<React.Fragment>
376387
<FileList
@@ -382,21 +393,19 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
382393
/>
383394
{this.props.settings.composite['simpleStaging'] ? (
384395
<CommitBox
396+
commands={this.props.commands}
385397
hasFiles={this._markedFiles.length > 0}
386398
trans={this.props.trans}
387-
useCommitAndPush={this.props.settings.composite['useCommitAndPush'] as boolean}
399+
label={buttonLabel}
388400
onCommit={this.commitMarkedFiles}
389-
commands={this.props.commands}
390-
branches={this.state.branches}
391401
/>
392402
) : (
393403
<CommitBox
404+
commands={this.props.commands}
394405
hasFiles={this._hasStagedFile()}
395406
trans={this.props.trans}
396-
useCommitAndPush={this.props.settings.composite['useCommitAndPush'] as boolean}
407+
label={buttonLabel}
397408
onCommit={this.commitStagedFiles}
398-
commands={this.props.commands}
399-
branches={this.state.branches}
400409
/>
401410
)}
402411
</React.Fragment>

tests/test-components/CommitBox.spec.tsx

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import * as React from 'react';
2-
import 'jest';
3-
import { shallow } from 'enzyme';
4-
import { CommitBox} from '../../src/components/CommitBox';
5-
import { CommandRegistry } from '@lumino/commands';
61
import { nullTranslator } from '@jupyterlab/translation';
2+
import { CommandRegistry } from '@lumino/commands';
3+
import { shallow } from 'enzyme';
4+
import 'jest';
5+
import * as React from 'react';
6+
import { CommitBox } from '../../src/components/CommitBox';
77
import { CommandIDs } from '../../src/tokens';
88

99
describe('CommitBox', () => {
10-
11-
const defaultCommands = new CommandRegistry()
10+
const defaultCommands = new CommandRegistry();
1211
defaultCommands.addKeyBinding({
1312
keys: ['Accel Enter'],
1413
command: CommandIDs.gitSubmitCommand,
1514
selector: '.jp-git-CommitBox'
16-
})
15+
});
1716

1817
const trans = nullTranslator.load('jupyterlab-git');
1918

@@ -23,7 +22,8 @@ describe('CommitBox', () => {
2322
onCommit: async () => {},
2423
hasFiles: false,
2524
commands: defaultCommands,
26-
trans: trans
25+
trans: trans,
26+
label: 'Commit'
2727
});
2828
expect(box).toBeInstanceOf(CommitBox);
2929
});
@@ -33,7 +33,8 @@ describe('CommitBox', () => {
3333
onCommit: async () => {},
3434
hasFiles: false,
3535
commands: defaultCommands,
36-
trans: trans
36+
trans: trans,
37+
label: 'Commit'
3738
});
3839
expect(box.state.summary).toEqual('');
3940
});
@@ -43,7 +44,8 @@ describe('CommitBox', () => {
4344
onCommit: async () => {},
4445
hasFiles: false,
4546
commands: defaultCommands,
46-
trans: trans
47+
trans: trans,
48+
label: 'Commit'
4749
});
4850
expect(box.state.description).toEqual('');
4951
});
@@ -55,37 +57,44 @@ describe('CommitBox', () => {
5557
onCommit: async () => {},
5658
hasFiles: false,
5759
commands: defaultCommands,
58-
trans: trans
60+
trans: trans,
61+
label: 'Commit'
5962
};
6063
const component = shallow(<CommitBox {...props} />);
6164
const node = component.find('input[type="text"]').first();
62-
expect(node.prop('placeholder')).toEqual('Summary (Ctrl+Enter to commit)');
65+
expect(node.prop('placeholder')).toEqual(
66+
'Summary (Ctrl+Enter to commit)'
67+
);
6368
});
6469

6570
it('should adjust placeholder text for the commit message summary when keybinding changes', () => {
66-
const adjustedCommands = new CommandRegistry()
71+
const adjustedCommands = new CommandRegistry();
6772
adjustedCommands.addKeyBinding({
6873
keys: ['Shift Enter'],
6974
command: CommandIDs.gitSubmitCommand,
7075
selector: '.jp-git-CommitBox'
71-
})
76+
});
7277
const props = {
7378
onCommit: async () => {},
7479
hasFiles: false,
7580
commands: adjustedCommands,
76-
trans: trans
81+
trans: trans,
82+
label: 'Commit'
7783
};
7884
const component = shallow(<CommitBox {...props} />);
7985
const node = component.find('input[type="text"]').first();
80-
expect(node.prop('placeholder')).toEqual('Summary (Shift+Enter to commit)');
86+
expect(node.prop('placeholder')).toEqual(
87+
'Summary (Shift+Enter to commit)'
88+
);
8189
});
8290

8391
it('should set a `title` attribute on the input element to provide a commit message summary', () => {
8492
const props = {
8593
onCommit: async () => {},
8694
hasFiles: false,
8795
commands: defaultCommands,
88-
trans: trans
96+
trans: trans,
97+
label: 'Commit'
8998
};
9099
const component = shallow(<CommitBox {...props} />);
91100
const node = component.find('input[type="text"]').first();
@@ -97,7 +106,8 @@ describe('CommitBox', () => {
97106
onCommit: async () => {},
98107
hasFiles: false,
99108
commands: defaultCommands,
100-
trans: trans
109+
trans: trans,
110+
label: 'Commit'
101111
};
102112
const component = shallow(<CommitBox {...props} />);
103113
const node = component.find('TextareaAutosize').first();
@@ -109,7 +119,8 @@ describe('CommitBox', () => {
109119
onCommit: async () => {},
110120
hasFiles: false,
111121
commands: defaultCommands,
112-
trans: trans
122+
trans: trans,
123+
label: 'Commit'
113124
};
114125
const component = shallow(<CommitBox {...props} />);
115126
const node = component.find('TextareaAutosize').first();
@@ -121,7 +132,8 @@ describe('CommitBox', () => {
121132
onCommit: async () => {},
122133
hasFiles: false,
123134
commands: defaultCommands,
124-
trans: trans
135+
trans: trans,
136+
label: 'Commit'
125137
};
126138
const component = shallow(<CommitBox {...props} />);
127139
const node = component.find('input[type="button"]').first();
@@ -133,7 +145,8 @@ describe('CommitBox', () => {
133145
onCommit: async () => {},
134146
hasFiles: false,
135147
commands: defaultCommands,
136-
trans: trans
148+
trans: trans,
149+
label: 'Commit'
137150
};
138151
const component = shallow(<CommitBox {...props} />);
139152
const node = component.find('input[type="button"]').first();
@@ -145,7 +158,8 @@ describe('CommitBox', () => {
145158
onCommit: async () => {},
146159
hasFiles: false,
147160
commands: defaultCommands,
148-
trans: trans
161+
trans: trans,
162+
label: 'Commit'
149163
};
150164
const component = shallow(<CommitBox {...props} />);
151165
const node = component.find('input[type="button"]').first();
@@ -158,7 +172,8 @@ describe('CommitBox', () => {
158172
onCommit: async () => {},
159173
hasFiles: true,
160174
commands: defaultCommands,
161-
trans: trans
175+
trans: trans,
176+
label: 'Commit'
162177
};
163178
const component = shallow(<CommitBox {...props} />);
164179
const node = component.find('input[type="button"]').first();
@@ -171,7 +186,8 @@ describe('CommitBox', () => {
171186
onCommit: async () => {},
172187
hasFiles: true,
173188
commands: defaultCommands,
174-
trans: trans
189+
trans: trans,
190+
label: 'Commit'
175191
};
176192
const component = shallow(<CommitBox {...props} />);
177193
component.setState({

0 commit comments

Comments
 (0)