Skip to content

Commit a756c3f

Browse files
committed
Add frontend support for branching from an arbitrary branch
1 parent 55b7da2 commit a756c3f

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

src/components/NewBranchDialog.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
closeButtonClass,
1717
contentWrapperClass,
1818
createButtonClass,
19+
listItemBoldTitleClass,
1920
listItemClass,
2021
listItemContentClass,
2122
listItemDescClass,
@@ -27,6 +28,13 @@ import {
2728
titleWrapperClass
2829
} from '../style/NewBranchDialog';
2930

31+
const BRANCH_DESC = {
32+
current:
33+
'The current branch. Pick this if you want to build on work done in this branch.',
34+
default:
35+
'The default branch. Pick this if you want to start fresh from the default branch.'
36+
};
37+
3038
/**
3139
* Interface describing component properties.
3240
*/
@@ -202,25 +210,33 @@ export class NewBranchDialog extends React.Component<
202210
* @returns fragment
203211
*/
204212
private _renderItem(branch: Git.IBranch, idx: number) {
213+
const isBase = branch.name === this.state.base;
214+
const isCurr = branch.name === this.state.current;
215+
216+
let isBold;
217+
let desc;
218+
if (isCurr) {
219+
isBold = true;
220+
desc = BRANCH_DESC['current'];
221+
}
205222
return (
206223
<ListItem
207224
button
208-
className={classes(
209-
listItemClass,
210-
branch.name === this.state.base ? activeListItemClass : null
211-
)}
225+
className={classes(listItemClass, isBase ? activeListItemClass : null)}
212226
key={idx}
213227
onClick={this._onBranchClickFactory(branch.name)}
214228
>
215229
<span className={classes(listItemIconClass, 'jp-Icon-16')} />
216230
<div className={listItemContentClass}>
217-
<p className={listItemTitleClass}>{branch.name}</p>
218-
{branch.name === this.state.current ? (
219-
<p className={listItemDescClass}>
220-
The current branch. Pick this if you want to build on work done in
221-
this branch.
222-
</p>
223-
) : null}
231+
<p
232+
className={classes(
233+
listItemTitleClass,
234+
isBold ? listItemBoldTitleClass : null
235+
)}
236+
>
237+
{branch.name}
238+
</p>
239+
{desc ? <p className={listItemDescClass}>{desc}</p> : null}
224240
</div>
225241
</ListItem>
226242
);

src/model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ export class GitExtension implements IGitExtension {
387387
checkout_branch: false,
388388
new_check: false,
389389
branchname: '',
390+
startpoint: '',
390391
checkout_all: true,
391392
filename: '',
392393
top_repo_path: path
@@ -397,6 +398,9 @@ export class GitExtension implements IGitExtension {
397398
body.branchname = options.branchname;
398399
body.checkout_branch = true;
399400
body.new_check = options.newBranch === true;
401+
if (options.newBranch) {
402+
body.startpoint = options.startpoint || this._currentBranch.name;
403+
}
400404
} else if (options.filename) {
401405
body.filename = options.filename;
402406
body.checkout_all = false;

src/style/NewBranchDialog.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ export const listItemIconClass = style({
136136
backgroundPosition: 'center'
137137
});
138138

139-
export const listItemTitleClass = style({
139+
export const listItemTitleClass = style({});
140+
141+
export const listItemBoldTitleClass = style({
140142
fontWeight: 700
141143
});
142144

src/tokens.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ export namespace Git {
319319
* Is it a new branch?
320320
*/
321321
newBranch?: boolean;
322+
/**
323+
* The commit (branch name, tag, or commit id) to which a new branch HEAD will point.
324+
*/
325+
startpoint?: string;
322326
/**
323327
* Filename
324328
*/

0 commit comments

Comments
 (0)