Skip to content

Commit 11ce02c

Browse files
committed
put is_current_branch field back; fixed all jest tests
1 parent ca0f6cd commit 11ce02c

File tree

9 files changed

+41
-5
lines changed

9 files changed

+41
-5
lines changed

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
"sourceMap": "inline",
23
presets: [
34
[
45
'@babel/preset-env',

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var tsConfig = require ('./tsconfig.json');
33
var tsOptions = tsConfig["compilerOptions"];
44
// Need as the test folder is not visible from the src folder
55
tsOptions["rootDir"] = null;
6+
tsOptions["inlineSourceMap"] = true;
67

78
module.exports = {
89
automock: false,

jupyterlab_git/git.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,18 @@ def branch_heads(self, current_path):
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+
401403
branch = {
404+
"is_current_branch": is_current_branch,
402405
"is_remote_branch": False,
403406
"name": name,
404407
"upstream": upstream_name if upstream_name else None,
405408
"top_commit": commit_sha,
406409
"tag": None,
407410
}
408411
results.append(branch)
409-
if is_current_branch.strip():
412+
if is_current_branch:
410413
current_branch = branch
411414

412415
# Remote branch is seleted use 'git branch -a' as fallback machanism
@@ -415,6 +418,7 @@ def branch_heads(self, current_path):
415418
# when the remote branch is seleted, VS Code git does the same thing.
416419
if not current_branch and self.get_current_branch(current_path) == "HEAD":
417420
branch = {
421+
"is_current_branch": True,
418422
"is_remote_branch": False,
419423
"name": self._get_detached_head_name(current_path),
420424
"upstream": None,
@@ -458,6 +462,7 @@ def branch_remotes(self, current_path):
458462
for name,commit_sha in (line.split('\t') for line in output.decode("utf-8").splitlines()):
459463
# Format reference : https://git-scm.com/docs/git-for-each-ref#_field_names
460464
results.append({
465+
"is_current_branch": False,
461466
"is_remote_branch": True,
462467
"name": name,
463468
"upstream": None,

jupyterlab_git/tests/test_branch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,34 +423,39 @@ def test_branch_success(mock_subproc_popen):
423423
'code': 0,
424424
'branches': [
425425
{
426+
'is_current_branch': True,
426427
'is_remote_branch': False,
427428
'name': 'feature-foo',
428429
'upstream': 'origin/feature-foo',
429430
'top_commit': 'abcdefghijklmnopqrstuvwxyz01234567890123',
430431
'tag': None,
431432
},
432433
{
434+
'is_current_branch': False,
433435
'is_remote_branch': False,
434436
'name': 'master',
435437
'upstream': 'origin/master',
436438
'top_commit': 'abcdefghijklmnopqrstuvwxyz01234567890123',
437439
'tag': None,
438440
},
439441
{
442+
'is_current_branch': False,
440443
'is_remote_branch': False,
441444
'name': 'feature-bar',
442445
'upstream': None,
443446
'top_commit': '01234567899999abcdefghijklmnopqrstuvwxyz',
444447
'tag': None
445448
},
446449
{
450+
'is_current_branch': False,
447451
'is_remote_branch': True,
448452
'name': 'origin/feature-foo',
449453
'upstream': None,
450454
'top_commit': 'abcdefghijklmnopqrstuvwxyz01234567890123',
451455
'tag': None,
452456
},
453457
{
458+
'is_current_branch': False,
454459
'is_remote_branch': True,
455460
'name': 'origin/master',
456461
'upstream': None,
@@ -459,6 +464,7 @@ def test_branch_success(mock_subproc_popen):
459464
}
460465
],
461466
'current_branch': {
467+
'is_current_branch': True,
462468
'is_remote_branch': False,
463469
'name': 'feature-foo',
464470
'upstream': 'origin/feature-foo',
@@ -563,20 +569,23 @@ def test_branch_success_detached_head(mock_subproc_popen):
563569
'code': 0,
564570
'branches': [
565571
{
572+
'is_current_branch': False,
566573
'is_remote_branch': False,
567574
'name': 'master',
568575
'upstream': 'origin/master',
569576
'top_commit': 'abcdefghijklmnopqrstuvwxyz01234567890123',
570577
'tag': None,
571578
},
572579
{
580+
'is_current_branch': True,
573581
'is_remote_branch': False,
574582
'name': '(HEAD detached at origin/feature-foo)',
575583
'upstream': None,
576584
'top_commit': None,
577585
'tag': None,
578586
},
579587
{
588+
'is_current_branch': False,
580589
'is_remote_branch': True,
581590
'name': 'origin/feature-foo',
582591
'upstream': None,
@@ -585,6 +594,7 @@ def test_branch_success_detached_head(mock_subproc_popen):
585594
}
586595
],
587596
'current_branch': {
597+
'is_current_branch': True,
588598
'is_remote_branch': False,
589599
'name': '(HEAD detached at origin/feature-foo)',
590600
'upstream': None,

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.name === this.props.model.currentBranch.name && (
91+
{branch.is_current_branch && (
9292
<span className={classes(branchStyle, workingBranchStyle)}>
9393
working
9494
</span>

src/model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,10 @@ export class GitExtension implements IGitExtension, IDisposable {
454454
this._branches = response.branches;
455455
this._currentBranch = response.current_branch;
456456

457-
// set up the marker obj for this particular repo/branch
458-
this._setMarker(this.pathRepository, this._currentBranch.name);
457+
if (this._currentBranch) {
458+
// set up the marker obj for the current (valid) repo/branch combination
459+
this._setMarker(this.pathRepository, this._currentBranch.name);
460+
}
459461
} else {
460462
this._branches = [];
461463
this._currentBranch = null;

src/tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ export namespace Git {
313313
* Branch description interface
314314
*/
315315
export interface IBranch {
316+
is_current_branch: boolean;
316317
is_remote_branch: boolean;
317318
name: string;
318319
upstream: string;

tests/GitExtension.spec.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ describe('IGitExtension', () => {
2121
jest.restoreAllMocks();
2222

2323
mockResponses = {
24+
'/git/branch': {
25+
body: request =>
26+
JSON.stringify({
27+
code: 0,
28+
branches: [],
29+
current_branch: null
30+
})
31+
},
2432
'/git/show_top_level': {
2533
body: request =>
2634
JSON.stringify({
@@ -33,6 +41,13 @@ describe('IGitExtension', () => {
3341
JSON.stringify({
3442
server_root: fakeRoot
3543
})
44+
},
45+
'/git/status': {
46+
body: () =>
47+
JSON.stringify({
48+
code: 0,
49+
files: []
50+
})
3651
}
3752
};
3853

tests/test-components/FileList.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ describe('FileList', () => {
1515
renderMime: null,
1616
stagedFiles: [],
1717
unstagedFiles: [],
18-
untrackedFiles: []
18+
untrackedFiles: [],
19+
settings: null
1920
};
2021

2122
describe('#commitAllStagedFiles()', () => {

0 commit comments

Comments
 (0)