Skip to content

Commit a07b870

Browse files
committed
Emit head changed when refreshing the branches
1 parent 4e3595c commit a07b870

File tree

2 files changed

+46
-72
lines changed

2 files changed

+46
-72
lines changed

src/model.ts

+45-70
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,15 @@ export class GitExtension implements IGitExtension {
314314
*/
315315
async allHistory(count = 25): Promise<Git.IAllHistory> {
316316
const path = await this._getPathRespository();
317-
const data = await this._taskHandler.execute<Git.IAllHistory>(
317+
return await this._taskHandler.execute<Git.IAllHistory>(
318318
'git:fetch:history',
319319
async () => {
320-
const d = await requestAPI<Git.IAllHistory>('all_history', 'POST', {
320+
return await requestAPI<Git.IAllHistory>('all_history', 'POST', {
321321
current_path: path,
322322
history_count: count
323323
});
324-
return d;
325324
}
326325
);
327-
return data;
328326
}
329327

330328
/**
@@ -419,18 +417,16 @@ export class GitExtension implements IGitExtension {
419417
url: string,
420418
auth?: Git.IAuth
421419
): Promise<Git.ICloneResult> {
422-
const data = this._taskHandler.execute<Git.ICloneResult>(
420+
return await this._taskHandler.execute<Git.ICloneResult>(
423421
'git:clone',
424422
async () => {
425-
const d = await requestAPI<Git.ICloneResult>('clone', 'POST', {
423+
return await requestAPI<Git.ICloneResult>('clone', 'POST', {
426424
current_path: path,
427425
clone_url: url,
428426
auth: auth as any
429427
});
430-
return d;
431428
}
432429
);
433-
return data;
434430
}
435431

436432
/**
@@ -467,7 +463,7 @@ export class GitExtension implements IGitExtension {
467463
*/
468464
async config(options?: JSONObject): Promise<JSONObject | void> {
469465
const path = await this._getPathRespository();
470-
const data = await this._taskHandler.execute<JSONObject | void>(
466+
return await this._taskHandler.execute<JSONObject | void>(
471467
'git:config:' + (options ? 'set' : 'get'),
472468
async () => {
473469
if (options) {
@@ -476,12 +472,10 @@ export class GitExtension implements IGitExtension {
476472
options
477473
});
478474
} else {
479-
const d = await requestAPI<JSONObject>('config', 'POST', { path });
480-
return d;
475+
return await requestAPI<JSONObject>('config', 'POST', { path });
481476
}
482477
}
483478
);
484-
return data;
485479
}
486480

487481
/**
@@ -511,15 +505,14 @@ export class GitExtension implements IGitExtension {
511505
const data = await this._taskHandler.execute<Git.ISingleCommitFilePathInfo>(
512506
'git:fetch:commit_log',
513507
async () => {
514-
const d = await requestAPI<Git.ISingleCommitFilePathInfo>(
508+
return await requestAPI<Git.ISingleCommitFilePathInfo>(
515509
'detailed_log',
516510
'POST',
517511
{
518512
selected_hash: hash,
519513
current_path: path
520514
}
521515
);
522-
return d;
523516
}
524517
);
525518

@@ -620,17 +613,15 @@ export class GitExtension implements IGitExtension {
620613
*/
621614
async log(count = 25): Promise<Git.ILogResult> {
622615
const path = await this._getPathRespository();
623-
const data = this._taskHandler.execute<Git.ILogResult>(
616+
return await this._taskHandler.execute<Git.ILogResult>(
624617
'git:fetch:log',
625618
async () => {
626-
const d = await requestAPI<Git.ILogResult>('log', 'POST', {
619+
return await requestAPI<Git.ILogResult>('log', 'POST', {
627620
current_path: path,
628621
history_count: count
629622
});
630-
return d;
631623
}
632624
);
633-
return data;
634625
}
635626

636627
/**
@@ -648,14 +639,13 @@ export class GitExtension implements IGitExtension {
648639
const data = this._taskHandler.execute<Git.IPushPullResult>(
649640
'git:pull',
650641
async () => {
651-
const d = await requestAPI<Git.IPushPullResult>('pull', 'POST', {
642+
return await requestAPI<Git.IPushPullResult>('pull', 'POST', {
652643
current_path: path,
653644
auth: auth as any,
654645
cancel_on_conflict:
655646
(this._settings?.composite['cancelPullMergeConflict'] as boolean) ||
656647
false
657648
});
658-
return d;
659649
}
660650
);
661651
this._headChanged.emit();
@@ -677,11 +667,10 @@ export class GitExtension implements IGitExtension {
677667
const data = this._taskHandler.execute<Git.IPushPullResult>(
678668
'git:push',
679669
async () => {
680-
const d = await requestAPI<Git.IPushPullResult>('push', 'POST', {
670+
return await requestAPI<Git.IPushPullResult>('push', 'POST', {
681671
current_path: path,
682672
auth: auth as any
683673
});
684-
return d;
685674
}
686675
);
687676
this._headChanged.emit();
@@ -710,19 +699,29 @@ export class GitExtension implements IGitExtension {
710699
const data = await this._taskHandler.execute<Git.IBranchResult>(
711700
'git:refresh:branches',
712701
async () => {
713-
const response = await this._branch();
714-
return response;
702+
return await this._branch();
715703
}
716704
);
705+
706+
const headChanged = this._currentBranch !== data.current_branch;
717707
this._branches = data.branches;
718708
this._currentBranch = data.current_branch;
719709
if (this._currentBranch) {
720710
// Set up the marker obj for the current (valid) repo/branch combination
721711
this._setMarker(this.pathRepository, this._currentBranch.name);
722712
}
713+
714+
if (headChanged) {
715+
this._headChanged.emit();
716+
}
723717
} catch (error) {
718+
const headChanged = this._currentBranch !== null;
724719
this._branches = [];
725720
this._currentBranch = null;
721+
if (headChanged) {
722+
this._headChanged.emit();
723+
}
724+
726725
if (!(error instanceof Git.NotInRepository)) {
727726
throw error;
728727
}
@@ -750,10 +749,9 @@ export class GitExtension implements IGitExtension {
750749
const data = await this._taskHandler.execute<Git.IStatusResult>(
751750
'git:refresh:status',
752751
async () => {
753-
const d = await requestAPI<Git.IStatusResult>('status', 'POST', {
752+
return await requestAPI<Git.IStatusResult>('status', 'POST', {
754753
current_path: path
755754
});
756-
return d;
757755
}
758756
);
759757

@@ -853,20 +851,14 @@ export class GitExtension implements IGitExtension {
853851
* @throws {ServerConnection.NetworkError} If the request cannot be made
854852
*/
855853
async showPrefix(path: string): Promise<Git.IShowPrefixResult> {
856-
const data = await this._taskHandler.execute<Git.IShowPrefixResult>(
854+
return await this._taskHandler.execute<Git.IShowPrefixResult>(
857855
'git:fetch:prefix_path',
858856
async () => {
859-
const d = await requestAPI<Git.IShowPrefixResult>(
860-
'show_prefix',
861-
'POST',
862-
{
863-
current_path: path
864-
}
865-
);
866-
return d;
857+
return await requestAPI<Git.IShowPrefixResult>('show_prefix', 'POST', {
858+
current_path: path
859+
});
867860
}
868861
);
869-
return data;
870862
}
871863

872864
/**
@@ -879,20 +871,18 @@ export class GitExtension implements IGitExtension {
879871
* @throws {ServerConnection.NetworkError} If the request cannot be made
880872
*/
881873
async showTopLevel(path: string): Promise<Git.IShowTopLevelResult> {
882-
const data = this._taskHandler.execute<Git.IShowTopLevelResult>(
874+
return await this._taskHandler.execute<Git.IShowTopLevelResult>(
883875
'git:fetch:top_level_path',
884876
async () => {
885-
const d = await requestAPI<Git.IShowTopLevelResult>(
877+
return await requestAPI<Git.IShowTopLevelResult>(
886878
'show_top_level',
887879
'POST',
888880
{
889881
current_path: path
890882
}
891883
);
892-
return d;
893884
}
894885
);
895-
return data;
896886
}
897887

898888
/**
@@ -906,16 +896,14 @@ export class GitExtension implements IGitExtension {
906896
*/
907897
async tags(): Promise<Git.ITagResult> {
908898
const path = await this._getPathRespository();
909-
const data = await this._taskHandler.execute<Git.ITagResult>(
899+
return await this._taskHandler.execute<Git.ITagResult>(
910900
'git:tag:list',
911901
async () => {
912-
const d = await requestAPI<Git.ITagResult>('tags', 'POST', {
902+
return await requestAPI<Git.ITagResult>('tags', 'POST', {
913903
current_path: path
914904
});
915-
return d;
916905
}
917906
);
918-
return data;
919907
}
920908

921909
/**
@@ -930,21 +918,15 @@ export class GitExtension implements IGitExtension {
930918
*/
931919
async checkoutTag(tag: string): Promise<Git.ICheckoutResult> {
932920
const path = await this._getPathRespository();
933-
const data = await this._taskHandler.execute<Git.ICheckoutResult>(
921+
return await this._taskHandler.execute<Git.ICheckoutResult>(
934922
'git:tag:checkout',
935923
async () => {
936-
const d = await requestAPI<Git.ICheckoutResult>(
937-
'tag_checkout',
938-
'POST',
939-
{
940-
current_path: path,
941-
tag_id: tag
942-
}
943-
);
944-
return d;
924+
return await requestAPI<Git.ICheckoutResult>('tag_checkout', 'POST', {
925+
current_path: path,
926+
tag_id: tag
927+
});
945928
}
946929
);
947-
return data;
948930
}
949931

950932
/**
@@ -1028,16 +1010,14 @@ export class GitExtension implements IGitExtension {
10281010
*/
10291011
protected async _branch(): Promise<Git.IBranchResult> {
10301012
const path = await this._getPathRespository();
1031-
const data = await this._taskHandler.execute<Git.IBranchResult>(
1013+
return await this._taskHandler.execute<Git.IBranchResult>(
10321014
'git:fetch:branches',
10331015
async () => {
1034-
const d = await requestAPI<Git.IBranchResult>('branch', 'POST', {
1016+
return await requestAPI<Git.IBranchResult>('branch', 'POST', {
10351017
current_path: path
10361018
});
1037-
return d;
10381019
}
10391020
);
1040-
return data;
10411021
}
10421022

10431023
/**
@@ -1060,17 +1040,12 @@ export class GitExtension implements IGitExtension {
10601040
remote?: string,
10611041
singleCommit?: string
10621042
): Promise<Git.IChangedFilesResult> {
1063-
const data = await requestAPI<Git.IChangedFilesResult>(
1064-
'changed_files',
1065-
'POST',
1066-
{
1067-
current_path: this.pathRepository,
1068-
base: base,
1069-
remote: remote,
1070-
single_commit: singleCommit
1071-
}
1072-
);
1073-
return data;
1043+
return await requestAPI<Git.IChangedFilesResult>('changed_files', 'POST', {
1044+
current_path: this.pathRepository,
1045+
base: base,
1046+
remote: remote,
1047+
single_commit: singleCommit
1048+
});
10741049
}
10751050

10761051
/**

src/taskhandler.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export class TaskHandler<T> {
6060
async execute<R>(name: string, callable: () => Promise<R>): Promise<R> {
6161
const taskID = this.add(name);
6262
try {
63-
const result = await callable();
64-
return result;
63+
return await callable();
6564
} finally {
6665
this.remove(taskID);
6766
}

0 commit comments

Comments
 (0)