Skip to content

Commit bc44235

Browse files
committed
rerigged marker objs to work transparently through the git model
1 parent 1e58fd4 commit bc44235

File tree

8 files changed

+146
-103
lines changed

8 files changed

+146
-103
lines changed

jupyterlab_git/git.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def branch(self, current_path):
377377
return remotes
378378

379379
# all's good; concatenate results and return
380-
return {"code": 0, "branches": heads["branches"] + remotes["branches"]}
380+
return {"code": 0, "branches": heads["branches"] + remotes["branches"], "current_branch": heads["current_branch"]}
381381

382382
def branch_heads(self, current_path):
383383
"""
@@ -393,37 +393,39 @@ def branch_heads(self, current_path):
393393
)
394394
output, error = p.communicate()
395395
if p.returncode == 0:
396-
current_branch_seen = False
396+
current_branch = None
397397
results = []
398398
try:
399399
for name,commit_sha,upstream_name,is_current_branch in (line.split('\t') for line in output.decode("utf-8").splitlines()):
400400
# Format reference : https://git-scm.com/docs/git-for-each-ref#_field_names
401-
is_current_branch = bool(is_current_branch.strip())
402-
current_branch_seen |= is_current_branch
403-
404-
results.append({
405-
"is_current_branch": is_current_branch,
401+
branch = {
406402
"is_remote_branch": False,
407403
"name": name,
408404
"upstream": upstream_name if upstream_name else None,
409405
"top_commit": commit_sha,
410406
"tag": None,
411-
})
407+
}
408+
results.append(branch)
409+
if is_current_branch.strip():
410+
current_branch = branch
412411

413412
# Remote branch is seleted use 'git branch -a' as fallback machanism
414413
# to get add detached head on remote branch to preserve older functionality
415414
# TODO : Revisit this to checkout new local branch with same name as remote
416415
# when the remote branch is seleted, VS Code git does the same thing.
417-
if not current_branch_seen and self.get_current_branch(current_path) == "HEAD":
418-
results.append({
419-
"is_current_branch": True,
416+
if not current_branch and self.get_current_branch(current_path) == "HEAD":
417+
branch = {
420418
"is_remote_branch": False,
421419
"name": self._get_detached_head_name(current_path),
422420
"upstream": None,
423421
"top_commit": None,
424422
"tag": None,
425-
})
426-
return {"code": p.returncode, "branches": results}
423+
}
424+
results.append(branch)
425+
current_branch = branch
426+
427+
return {"code": p.returncode, "branches": results, "current_branch": current_branch}
428+
427429
except Exception as downstream_error:
428430
return {
429431
"code": -1,
@@ -456,7 +458,6 @@ def branch_remotes(self, current_path):
456458
for name,commit_sha in (line.split('\t') for line in output.decode("utf-8").splitlines()):
457459
# Format reference : https://git-scm.com/docs/git-for-each-ref#_field_names
458460
results.append({
459-
"is_current_branch": False,
460461
"is_remote_branch": True,
461462
"name": name,
462463
"upstream": None,

src/components/FileItemSimple.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Dialog, showDialog } from '@jupyterlab/apputils';
22
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
33
import * as React from 'react';
44
import { classes } from 'typestyle';
5-
import { BranchMarker, GitExtension } from '../model';
5+
import { GitExtension } from '../model';
66
import {
77
fileButtonStyle,
88
fileGitButtonStyle,
@@ -24,8 +24,8 @@ import { ISpecialRef } from './diff/model';
2424

2525
export interface IGitMarkBoxProps {
2626
fname: string;
27+
model: GitExtension;
2728
stage: string;
28-
marker: BranchMarker;
2929
}
3030

3131
export class GitMarkBox extends React.Component<IGitMarkBoxProps> {
@@ -36,23 +36,26 @@ export class GitMarkBox extends React.Component<IGitMarkBoxProps> {
3636
}
3737

3838
protected _onClick(event: React.ChangeEvent<HTMLInputElement>) {
39-
// toggle will force an update of GitPanel
40-
this.props.marker.toggle(this.props.fname);
39+
// toggle will emit a markChanged signal
40+
this.props.model.toggleMark(this.props.fname);
4141

42-
// needed if not a descendent of a GitPanel
42+
// needed if markChanged doesn't force an update of a parent
4343
this.forceUpdate();
4444
}
4545

4646
render() {
4747
// idempotent, will only run once per file
48-
this.props.marker.add(this.props.fname, this.props.stage !== 'untracked');
48+
this.props.model.addMark(
49+
this.props.fname,
50+
this.props.stage !== 'untracked'
51+
);
4952

5053
return (
5154
<input
5255
name="gitMark"
5356
className={gitMarkBoxStyle}
5457
type="checkbox"
55-
checked={this.props.marker.get(this.props.fname)}
58+
checked={this.props.model.getMark(this.props.fname)}
5659
onChange={this._onClick}
5760
/>
5861
);
@@ -62,7 +65,6 @@ export class GitMarkBox extends React.Component<IGitMarkBoxProps> {
6265
export interface IFileItemSimpleProps {
6366
file: Git.IStatusFileResult;
6467
stage: string;
65-
marker: BranchMarker;
6668
model: GitExtension;
6769
discardFile: (file: string) => Promise<void>;
6870
renderMime: IRenderMimeRegistry;
@@ -111,7 +113,7 @@ export class FileItemSimple extends React.Component<IFileItemSimpleProps> {
111113
<GitMarkBox
112114
fname={this.props.file.to}
113115
stage={this.props.stage}
114-
marker={this.props.marker}
116+
model={this.props.model}
115117
/>
116118
<span
117119
className={classes(

src/components/FileList.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
44
import { JSONObject } from '@phosphor/coreutils';
55
import { Menu } from '@phosphor/widgets';
66
import * as React from 'react';
7-
import { BranchMarker, GitExtension } from '../model';
7+
import { GitExtension } from '../model';
88
import {
99
moveFileDownButtonSelectedStyle,
1010
moveFileDownButtonStyle,
@@ -56,7 +56,6 @@ export interface IFileListProps {
5656
stagedFiles: Git.IStatusFileResult[];
5757
unstagedFiles: Git.IStatusFileResult[];
5858
untrackedFiles: Git.IStatusFileResult[];
59-
marker: BranchMarker;
6059
model: GitExtension;
6160
renderMime: IRenderMimeRegistry;
6261
settings: ISettingRegistry.ISettings;
@@ -413,7 +412,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
413412

414413
get markedFiles() {
415414
return this.allFilesExcludingUnmodified.filter(file =>
416-
this.props.marker.get(file.to)
415+
this.props.model.getMark(file.to)
417416
);
418417
}
419418

@@ -518,7 +517,6 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
518517
<GitStageSimple
519518
heading={'Changed'}
520519
files={this.allFilesExcludingUnmodified}
521-
marker={this.props.marker}
522520
model={this.props.model}
523521
discardAllFiles={this.discardAllChanges}
524522
discardFile={this.discardChanges}

src/components/GitPanel.tsx

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,13 @@ export class GitPanel extends React.Component<
8282
}
8383

8484
refreshBranch = async () => {
85-
// Get current and upstream git branch
86-
if (this.props.model.pathRepository !== null) {
87-
const branchData = await this.props.model.branch();
88-
let currentBranch = 'master';
89-
let upstreamBranch = '';
90-
if (branchData.code === 0) {
91-
let allBranches = branchData.branches;
92-
for (let i = 0; i < allBranches.length; i++) {
93-
if (allBranches[i].is_current_branch) {
94-
currentBranch = allBranches[i].name;
95-
upstreamBranch = allBranches[i].upstream;
96-
break;
97-
}
98-
}
99-
}
85+
const { currentBranch } = this.props.model;
10086

101-
this.props.model.getMarker(
102-
this.props.model.pathRepository,
103-
currentBranch
104-
);
105-
106-
this.setState({
107-
branches: branchData.branches,
108-
currentBranch: currentBranch,
109-
upstreamBranch: upstreamBranch
110-
});
111-
}
87+
this.setState({
88+
branches: this.props.model.branches,
89+
currentBranch: currentBranch ? currentBranch.name : 'master',
90+
upstreamBranch: currentBranch ? currentBranch.upstream : ''
91+
});
11292
};
11393

11494
refreshHistory = async () => {
@@ -209,10 +189,6 @@ export class GitPanel extends React.Component<
209189
stagedFiles={this.state.stagedFiles}
210190
unstagedFiles={this.state.unstagedFiles}
211191
untrackedFiles={this.state.untrackedFiles}
212-
marker={this.props.model.getMarker(
213-
this.props.model.pathRepository,
214-
this.state.currentBranch
215-
)}
216192
model={this.props.model}
217193
renderMime={this.props.renderMime}
218194
settings={this.props.settings}

src/components/GitStageSimple.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Dialog, showDialog } from '@jupyterlab/apputils';
22
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
33
import * as React from 'react';
44
import { classes } from 'typestyle';
5-
import { BranchMarker, GitExtension } from '../model';
5+
import { GitExtension } from '../model';
66
import {
77
changeStageButtonStyle,
88
discardFileButtonStyle,
@@ -17,7 +17,6 @@ import { decodeStage } from '../utils';
1717
export interface IGitStageSimpleProps {
1818
heading: string;
1919
files: Git.IStatusFileResult[];
20-
marker: BranchMarker;
2120
model: GitExtension;
2221
discardAllFiles: () => Promise<void>;
2322
discardFile: (file: string) => Promise<void>;
@@ -83,7 +82,6 @@ export class GitStageSimple extends React.Component<IGitStageSimpleProps> {
8382
key={fileIndex}
8483
file={file}
8584
stage={decodeStage(file.x, file.y)}
86-
marker={this.props.marker}
8785
model={this.props.model}
8886
discardFile={this.props.discardFile}
8987
renderMime={this.props.renderMime}

src/components/PastCommitNode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class PastCommitNode extends React.Component<
8888
<div className={branchesStyle}>
8989
{this.getBranchesForCommit().map((branch, id) => (
9090
<React.Fragment key={id}>
91-
{branch.is_current_branch && (
91+
{branch.name === this.props.model.currentBranch.name && (
9292
<span className={classes(branchStyle, workingBranchStyle)}>
9393
working
9494
</span>

0 commit comments

Comments
 (0)