From 6aedf1f8e85ccd690b7f69fe88c858a19465e853 Mon Sep 17 00:00:00 2001 From: "do.hoangnam9x" Date: Sat, 9 Nov 2019 22:14:59 +0700 Subject: [PATCH 1/4] Update delete confirm dialog --- .../repositories/repositories.component.ts | 24 +++++----- src/app/services/features/git.service.ts | 4 +- .../yes-no-decision.component.html | 19 +++++++- .../yes-no-decision.component.scss | 19 ++++++++ .../yes-no-decision.component.ts | 12 ++++- .../branch-options.component.html | 8 +++- .../branch-options.component.ts | 45 +++++++++++++++++-- .../branch-item/branch-item.component.ts | 3 +- .../DATA/repositories/repositories.service.ts | 13 +++++- .../repository-branches.service.ts | 12 +++++ src/app/shared/utilities/utilityHelper.ts | 14 +++++- 11 files changed, 147 insertions(+), 26 deletions(-) diff --git a/src/app/features/repositories/repositories.component.ts b/src/app/features/repositories/repositories.component.ts index ac7c97d..89193df 100644 --- a/src/app/features/repositories/repositories.component.ts +++ b/src/app/features/repositories/repositories.component.ts @@ -1,9 +1,8 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { interval, of, Subject } from 'rxjs'; import { RepositoriesMenuService } from '../../shared/state/UI/repositories-menu'; -import { debounceTime, distinctUntilChanged, switchMap, takeUntil, takeWhile } from 'rxjs/operators'; +import { debounceTime, distinctUntilChanged, switchMap, takeUntil, takeWhile, tap } from 'rxjs/operators'; import { RepositoriesService, Repository } from '../../shared/state/DATA/repositories'; -import { fromPromise } from 'rxjs/internal-compatibility'; import { StatusSummary } from '../../shared/model/statusSummary.model'; import { FileWatchesService } from '../../shared/state/system/File-Watches'; import { RepositoryBranchesService, RepositoryBranchSummary } from '../../shared/state/DATA/repository-branches'; @@ -138,8 +137,9 @@ export class RepositoriesComponent implements OnInit, OnDestroy { // } return of(null); }), - switchMap(() => fromPromise(this.repositoryBranchesService.load(this.repository))), - switchMap(() => this.observingBranchStatus()) + tap(() => this.repositoryBranchesService.load(this.repository)), + switchMap(() => this.observingBranchStatus()), + distinctUntilChanged(), ) .subscribe( (status: StatusSummary) => { @@ -155,13 +155,17 @@ export class RepositoriesComponent implements OnInit, OnDestroy { * Observing branch status */ private watchingBranch() { - this.repositoryBranchesService.select() - .subscribe( - listBranch => { + this.repositoryBranchesService + .select() + .pipe( + switchMap(listBranch => { this.branches = listBranch; - this.activeBranch = listBranch.find(branch => { - return branch.current; - }); + return this.repositoryBranchesService.selectActive(); + }) + ) + .subscribe( + activeBranch => { + this.activeBranch = activeBranch; } ); } diff --git a/src/app/services/features/git.service.ts b/src/app/services/features/git.service.ts index a9a81c8..357a280 100644 --- a/src/app/services/features/git.service.ts +++ b/src/app/services/features/git.service.ts @@ -89,7 +89,7 @@ export class GitService { const branchesOutPut: RepositoryBranchSummary[] = []; if (branchRemoteRaw.all.length > branchLocalRaw.all.length) { - // In case there is no local-only branch. + // In case there are remote branches. Object.keys(branchRemoteRaw.branches).forEach(branchRemoteInstance => { const slidedSlash = branchRemoteInstance.split('/'); const trackingOn = branchTracking.find(track => track.name === slidedSlash[0]); @@ -114,7 +114,7 @@ export class GitService { } }); } else { - // In case there are local-only branch. + // In case there are local-only branches. Object.keys(branchLocalRaw.branches).forEach(branchLocalInstance => { let trackingOn = null; const existRemoteLocal = branchRemoteRaw.all.find(nameRemoteBranch => { diff --git a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html index 354121d..fdca229 100644 --- a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html +++ b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html @@ -1 +1,18 @@ -

yes-no-decision works!

+

+ {{emittedDataFromView.title}} +

+

+ {{emittedDataFromView.body}} +

+
+ + +
diff --git a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss index e69de29..553bff8 100644 --- a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss +++ b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss @@ -0,0 +1,19 @@ +@import "src/styles/theme"; + +:host { + display: flex; + flex-direction: column; + + > *:not(:nth-last-child) { + margin-bottom: 0.75rem; + } +} + +.decision { + display: flex; + justify-content: flex-end; + + > *:not(:last-child) { + margin-right: 0.5rem; + } +} diff --git a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.ts b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.ts index 2cb6a3c..4be1f9e 100644 --- a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.ts +++ b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.ts @@ -1,4 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { YesNoDialogModel } from '../../../../model/yesNoDialog.model'; @Component({ selector: 'gitme-yes-no-decision', @@ -7,10 +9,16 @@ import { Component, OnInit } from '@angular/core'; }) export class YesNoDecisionComponent implements OnInit { - constructor() { + constructor( + @Inject(MAT_DIALOG_DATA) public emittedDataFromView: YesNoDialogModel, + public dialogRef: MatDialogRef, + ) { } ngOnInit() { } + closeDialog(val: boolean) { + this.dialogRef.close(val); + } } diff --git a/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.html b/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.html index 4a1ec2d..8ca0b83 100644 --- a/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.html +++ b/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.html @@ -1,11 +1,15 @@ -
+
Delete branch +
+ The action cannot be undone
-
+
Rename branch +
+ The action cannot be undone
diff --git a/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.ts b/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.ts index e660651..172874b 100644 --- a/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.ts +++ b/src/app/shared/components/branch/_dialogs/branch-options/branch-options.component.ts @@ -1,7 +1,10 @@ import { Component, Inject, OnInit } from '@angular/core'; -import { MAT_BOTTOM_SHEET_DATA, MatBottomSheetRef } from '@angular/material'; -import { RepositoryBranchSummary } from '../../../../state/DATA/repository-branches'; +import { MAT_BOTTOM_SHEET_DATA, MatBottomSheetRef, MatDialog } from '@angular/material'; +import { RepositoryBranchesService, RepositoryBranchSummary } from '../../../../state/DATA/repository-branches'; import { StatusSummary } from '../../../../model/statusSummary.model'; +import { Repository } from '../../../../state/DATA/repositories'; +import { YesNoDecisionComponent } from '../../../UI/dialogs/yes-no-decision/yes-no-decision.component'; +import { YesNoDialogModel } from '../../../../model/yesNoDialog.model'; @Component({ selector: 'gitme-branch-options', @@ -14,12 +17,46 @@ export class BranchOptionsComponent implements OnInit { private _bottomSheetRef: MatBottomSheetRef, @Inject(MAT_BOTTOM_SHEET_DATA) public data: { branch: RepositoryBranchSummary - status: StatusSummary - } + status: StatusSummary, + repository: Repository + }, + private matDialog: MatDialog, + private repositoryBranchService: RepositoryBranchesService ) { } ngOnInit() { } + renameBranch() { + + } + + deleteBranch() { + if (this.data.status.ahead > 0) { + // warn about the delete + const data: YesNoDialogModel = { + title: 'Delete branch', + body: `There are ${ this.data.status.ahead } commit${ this.data.status.ahead > 1 ? 's' : '' } that was not pushed to remote. + Delete this branch will also delete the changes. Do you want to proceed?`, + data: null, + decision: { + noText: 'Cancel', + yesText: 'Delete' + } + }; + this.matDialog.open(YesNoDecisionComponent, { + width: '380px', + height: 'auto', + data: data, + panelClass: 'bg-primary-black-mat-dialog', + }).afterClosed().subscribe((isDelete: boolean) => { + if (isDelete) { + this.repositoryBranchService.deleteBranch(this.data.repository, this.data.branch); + } + }); + } else { + this.repositoryBranchService.deleteBranch(this.data.repository, this.data.branch); + } + } } diff --git a/src/app/shared/components/branch/branch-item/branch-item.component.ts b/src/app/shared/components/branch/branch-item/branch-item.component.ts index b09cfc5..aa831a1 100644 --- a/src/app/shared/components/branch/branch-item/branch-item.component.ts +++ b/src/app/shared/components/branch/branch-item/branch-item.component.ts @@ -58,7 +58,8 @@ export class BranchItemComponent implements OnInit { onRightClick() { const dataPassing = { - branch: this.branchSummary + branch: this.branchSummary, + repository: this.repository }; if (this.branchSummary.current) { Object.assign(dataPassing, { status: this.status }); diff --git a/src/app/shared/state/DATA/repositories/repositories.service.ts b/src/app/shared/state/DATA/repositories/repositories.service.ts index 37fb21b..cc1475e 100644 --- a/src/app/shared/state/DATA/repositories/repositories.service.ts +++ b/src/app/shared/state/DATA/repositories/repositories.service.ts @@ -17,6 +17,7 @@ import { FileStatusSummary } from '../../../model/FileStatusSummary'; import * as moment from 'moment'; import { DataService } from '../../../../services/features/data.service'; import { SystemResponse } from '../../../model/system.response'; +import { compareArray } from '../../../utilities/utilityHelper'; @Injectable({ providedIn: 'root' }) export class RepositoriesService { @@ -83,7 +84,16 @@ export class RepositoriesService { for (const idRepository of repositoryFile) { const repos = await this.dataService.getRepositoriesConfigData(idRepository); if (!!repos && !!repos.repository) { - repositories.push(repos.repository); + if (this.fileService.isDirectoryExist(repos.repository.directory)) { + const repository: Repository = { ...repos.repository } as Repository; + const updatedBranch = await this.gitService.getBranchInfo(repository.directory, repository.branches); + // update local file + if (compareArray(updatedBranch, repository.branches)) { + await this.dataService.updateRepositoryData(repository, true); + } + repository.branches = updatedBranch; + repositories.push(repository); + } } } @@ -266,7 +276,6 @@ export class RepositoriesService { * Fetching data * @param repository * @param branch - * @param load * @param option */ fetch(repository: Repository, branch: RepositoryBranchSummary, option?: { [git: string]: string }) { diff --git a/src/app/shared/state/DATA/repository-branches/repository-branches.service.ts b/src/app/shared/state/DATA/repository-branches/repository-branches.service.ts index 9b821cb..7ffd95d 100644 --- a/src/app/shared/state/DATA/repository-branches/repository-branches.service.ts +++ b/src/app/shared/state/DATA/repository-branches/repository-branches.service.ts @@ -87,12 +87,24 @@ export class RepositoryBranchesService { ).pipe(map(_ => true)); } + /** + * TODO: check message and re-stash + * @param repository + * @param message + */ stashChanges(repository: Repository, message?: string) { return fromPromise( this.gitService.addStash(repository, message) ); } + deleteBranch(repository: Repository, branch: RepositoryBranchSummary) { + // $ git push -d <---- Delete remotely + // $ git branch -d <---- Delete locally + console.log(branch); + console.log(repository); + } + set(listBranch: RepositoryBranchSummary[]) { listBranch.sort( (branchA, branchB) => { diff --git a/src/app/shared/utilities/utilityHelper.ts b/src/app/shared/utilities/utilityHelper.ts index fafe547..0140fb2 100644 --- a/src/app/shared/utilities/utilityHelper.ts +++ b/src/app/shared/utilities/utilityHelper.ts @@ -47,9 +47,19 @@ export function distinctChanges( newValues: Array, conditions: Predicate[] ): boolean { - if (conditions.every(cond => cond(oldValues, newValues))) { - return false; + return !conditions.every(cond => cond(oldValues, newValues)); +} + +export function compareArray(arr1, arr2) { + + // Check if the arrays are the same length + if (arr1.length !== arr2.length) { return false; } + + // Check if all items exist and are in the same order + for (let i = 0; i < arr1.length; i++) { + if (arr1[i] !== arr2[i]) { return false; } } + // Otherwise, return true return true; } From e5ab75a42fe410f3030d538c69effe60162c2b76 Mon Sep 17 00:00:00 2001 From: "do.hoangnam9x" Date: Sat, 9 Nov 2019 23:10:19 +0700 Subject: [PATCH 2/4] minor css changes --- .../yes-no-decision/yes-no-decision.component.html | 6 +++--- .../yes-no-decision/yes-no-decision.component.scss | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html index fdca229..cd7d81f 100644 --- a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html +++ b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.html @@ -1,7 +1,7 @@ -

+

{{emittedDataFromView.title}} -

-

+ +

{{emittedDataFromView.body}}

diff --git a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss index 553bff8..4998de7 100644 --- a/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss +++ b/src/app/shared/components/UI/dialogs/yes-no-decision/yes-no-decision.component.scss @@ -3,10 +3,6 @@ :host { display: flex; flex-direction: column; - - > *:not(:nth-last-child) { - margin-bottom: 0.75rem; - } } .decision { @@ -17,3 +13,7 @@ margin-right: 0.5rem; } } + +.body { + font-size: 0.8rem; +} From 872341f6e06c7c44ef130a9363b25225df06643a Mon Sep 17 00:00:00 2001 From: "do.hoangnam9x" Date: Sun, 10 Nov 2019 21:40:12 +0700 Subject: [PATCH 3/4] Update branch menu * Fix branch list issues (change logic) * Add rename feature --- .../repositories/repositories.component.html | 6 +- .../repositories/repositories.component.ts | 2 +- src/app/services/features/git.service.ts | 249 ++++++++++-------- .../branch/ShareBranchComponents.module.ts | 2 +- .../branch-merge/branch-merge.component.html | 1 + .../branch-merge/branch-merge.component.scss | 0 .../branch-merge.component.spec.ts | 25 ++ .../branch-merge/branch-merge.component.ts | 15 ++ .../branch-new-option.component.html | 20 +- .../branch-options.component.html | 8 + .../branch-options.component.ts | 121 +++++++-- .../branch-rename.component.html | 77 ++++++ .../branch-rename.component.scss | 34 +++ .../branch-rename.component.spec.ts | 25 ++ .../branch-rename/branch-rename.component.ts | 94 +++++++ .../branch-item/branch-item.component.ts | 25 +- .../list-branches/list-branches.component.ts | 8 +- src/app/shared/model/yesNoDialog.model.ts | 4 +- src/app/shared/modules/dialogs.module.ts | 6 +- .../DATA/repositories/repositories.service.ts | 18 +- .../repository-branches.service.ts | 94 ++++++- src/app/shared/utilities/utilityHelper.ts | 82 +++++- src/index.html | 2 +- 23 files changed, 746 insertions(+), 172 deletions(-) create mode 100644 src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.html create mode 100644 src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.scss create mode 100644 src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.spec.ts create mode 100644 src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.ts create mode 100644 src/app/shared/components/branch/_dialogs/branch-rename/branch-rename.component.html create mode 100644 src/app/shared/components/branch/_dialogs/branch-rename/branch-rename.component.scss create mode 100644 src/app/shared/components/branch/_dialogs/branch-rename/branch-rename.component.spec.ts create mode 100644 src/app/shared/components/branch/_dialogs/branch-rename/branch-rename.component.ts diff --git a/src/app/features/repositories/repositories.component.html b/src/app/features/repositories/repositories.component.html index 467b9ca..a0c54be 100644 --- a/src/app/features/repositories/repositories.component.html +++ b/src/app/features/repositories/repositories.component.html @@ -33,9 +33,9 @@ Current Branch
- - {{activeBranch?.name}} - + + {{activeBranch?.name}} +
diff --git a/src/app/features/repositories/repositories.component.ts b/src/app/features/repositories/repositories.component.ts index 3626276..aa4d0ec 100644 --- a/src/app/features/repositories/repositories.component.ts +++ b/src/app/features/repositories/repositories.component.ts @@ -93,7 +93,7 @@ export class RepositoriesComponent implements OnInit, OnDestroy { takeUntil(this.componentDestroyed), takeWhile(() => this.isViewChangeTo === 'changes'), switchMap(() => { - console.log('running') + console.log('running'); if (!!this.repository && !!this.activeBranch) { return this.repositoriesService.fetch( { ...this.repository } as Repository, diff --git a/src/app/services/features/git.service.ts b/src/app/services/features/git.service.ts index 357a280..5741f3b 100644 --- a/src/app/services/features/git.service.ts +++ b/src/app/services/features/git.service.ts @@ -78,102 +78,96 @@ export class GitService { * @param oldBranches Retrieve from repository configs */ async getBranchInfo(directory: string, oldBranches: RepositoryBranchSummary[] = []): Promise { - const branchRemoteRaw = await this.gitInstance(directory).branch(['-r']); - const branchLocalRaw = await this.gitInstance(directory).branch([]); + const branchRemoteRaw = await this.branch(directory, '-r', '-vv'); + const branchLocalRaw = await this.branch(directory, '-vv'); const branchTracking = await this.getBranchTracking(directory); if (!branchTracking) { - return null; + return []; } - const branchesOutPut: RepositoryBranchSummary[] = []; - if (branchRemoteRaw.all.length > branchLocalRaw.all.length) { - // In case there are remote branches. - Object.keys(branchRemoteRaw.branches).forEach(branchRemoteInstance => { - const slidedSlash = branchRemoteInstance.split('/'); - const trackingOn = branchTracking.find(track => track.name === slidedSlash[0]); - const extractedNameRemote = slidedSlash.slice(1).join('/'); // remove origin/ - const existInstanceLocal = branchLocalRaw.all.find(nameLocalBranch => nameLocalBranch === extractedNameRemote); - if (!!existInstanceLocal && existInstanceLocal.length > 0) { - const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( - branchRemoteRaw.branches[branchRemoteInstance], - existInstanceLocal, - branchLocalRaw.branches[existInstanceLocal].current, - null, trackingOn, true, true - ); - branchesOutPut.push(branchItem); - } else { - const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( - branchRemoteRaw.branches[branchRemoteInstance], - branchRemoteInstance, - branchRemoteRaw.branches[branchRemoteInstance].current, - null, trackingOn, true, false - ); - branchesOutPut.push(branchItem); - } - }); - } else { - // In case there are local-only branches. - Object.keys(branchLocalRaw.branches).forEach(branchLocalInstance => { - let trackingOn = null; - const existRemoteLocal = branchRemoteRaw.all.find(nameRemoteBranch => { - const slidedSlash = nameRemoteBranch.split('/'); - trackingOn = branchTracking.find(track => track.name === slidedSlash[0]); - const extractedNameRemote = slidedSlash.slice(1).join('/'); // remove origin/ - return branchLocalInstance === extractedNameRemote; - }); - if (!!existRemoteLocal && existRemoteLocal.length > 0) { - const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( - branchRemoteRaw.branches[existRemoteLocal], - branchLocalInstance, - branchLocalRaw.branches[branchLocalInstance].current, - null, trackingOn, true, true - ); - branchesOutPut.push(branchItem); - } else { - const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( - branchRemoteRaw.branches[existRemoteLocal], - branchLocalInstance, - branchLocalRaw.branches[branchLocalInstance].current, - null, trackingOn, false, true - ); - branchesOutPut.push(branchItem); - } - }); - } + // result from remote first + // after that, looping all local and check for local-only branch and status. + Object.keys(branchRemoteRaw.branches).forEach(branchRemoteName => { + // contain [, , etc] + // tracker normally will be origin + const slidedSlash = branchRemoteName.split('/'); + const trackingOn = branchTracking.find(track => track.name === slidedSlash[0]); + // get the true name of the branch be hind tracker + const branchName = slidedSlash.slice(1).join('/'); + // If exist local, copy the current and change the local/remote status + const existInstanceLocal = branchLocalRaw.all.find( + nameLocalBranch => nameLocalBranch === branchName + ); + if (!!existInstanceLocal) { + const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( + branchRemoteRaw.branches[branchRemoteName], + branchName, + branchLocalRaw.branches[existInstanceLocal].current, + null, trackingOn, true, true + ); + branchesOutPut.push(branchItem); + } else { + const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( + branchRemoteRaw.branches[branchRemoteName], + branchName, + branchRemoteRaw.branches[branchRemoteName].current, + null, trackingOn, true, false + ); + branchesOutPut.push(branchItem); + } + }); - // update from oldBranch - if (branchesOutPut.length > oldBranches.length) { - branchesOutPut.forEach((branch, index, selfArr) => { - const findFromOld = this.findBranchFromListBranch(branch, oldBranches); + // Looping all local array to find "local only" + Object.keys(branchLocalRaw.branches).forEach(branchLocalName => { + const existedValue = branchesOutPut.find(br => br.name === branchLocalName); + /** + * Branch local only will not in remotes + */ + if (!existedValue) { + const branchItem: RepositoryBranchSummary = GitService.repositoryBranchBuilder( + branchLocalRaw.branches[branchLocalName], + branchLocalName, + branchLocalRaw.branches[branchLocalName].current, + null, null, false, true + ); + branchesOutPut.push(branchItem); + } + }); - if (findFromOld) { - selfArr[index].id = findFromOld.id; - selfArr[index].last_update = findFromOld.last_update; - selfArr[index].options = findFromOld.options; - } else { - selfArr[index].id = this.securityService.randomID; - selfArr[index].last_update = null; - selfArr[index].options = null; - } - }); - } else { - oldBranches.forEach((branch, index, selfArr) => { - const findFromNew = this.findBranchFromListBranch(branch, branchesOutPut); + // update other information from oldBranch + branchesOutPut.forEach((branch, index, self) => { + const existed = oldBranches.find(ob => ob.name === branch.name); + if (existed) { + branchesOutPut[index].id = existed.id; + branchesOutPut[index].last_update = existed.last_update; + branchesOutPut[index].options = existed.options; + } else { + branchesOutPut[index].id = this.securityService.randomID; + branchesOutPut[index].last_update = null; + branchesOutPut[index].options = null; + } + }); - if (findFromNew) { - findFromNew.id = selfArr[index].id; - findFromNew.last_update = selfArr[index].last_update; - findFromNew.options = selfArr[index].options; - } else { - // do nothing, will be removed as both local and remote cannot be found - // This can be due to branch removed, renamed, etc. - } - }); + console.log(branchesOutPut); + return branchesOutPut; + } + + isRemoteBranch(branchName: string) { + const regRemotes = /^(remotes\/\w+\/).+/; + if (regRemotes.exec(branchName)) { + const extractBySlash = branchName.split('/'); + return { + isRemote: true, + trackOn: extractBySlash + }; } + } - return branchesOutPut; + branch(directory: string, ...options: string[]) { + return this.gitInstance(directory) + .branch(options); } async cloneTo(cloneURL: string, directory: string, credentials?: Account) { @@ -232,6 +226,12 @@ export class GitService { } async fetchInfo(repository: Repository, credentials: Account, branch: RepositoryBranchSummary) { + if (!branch.tracking) { + return { + fetchData: null, + repository + }; + } // retrieve the directory for gitInstance to execute const { directory } = repository; let urlRemote = branch.tracking.fetch; @@ -276,25 +276,39 @@ export class GitService { /** * TODO: checking git issue for more info. - * @param repository - * @param branchURL - * @param credentials + * @param directory + * @param branchName + * @param remoteType * @param options */ - push(repository: Repository, branchURL: string, credentials: Account, options?: { [o: string]: string }) { - const urlRemote = this.utilities.addCredentialsToRemote(branchURL, credentials); - // this.gitInstance(repository.directory).raw( - // [ - // // `${urlRemote}` - // 'push', - // `--repo=${ urlRemote }`, - // '--all' - // ] - // ).then(r => console.log(r)); - return this.gitInstance(repository.directory).push().then(() => { - console.log('push complete'); - return true; - }); + push(directory, branchName, remoteType = 'origin', options?: { [key: string]: null | string | any }) { + return this.gitInstance(directory).push( + remoteType, + branchName, + options + ); + } + + /** + * For pushing new branch to remote + * @param directory + * @param branchName + * @param remoteType + * @param options + */ + pushUpStream(directory: string, branchName: string, remoteType = 'origin', options?: { [key: string]: null | string | any }) { + const defaultOptions = { + '-u': null // Upstream + }; + if (options && Object.keys(options).length > 0) { + Object.assign(defaultOptions, options); + } + return this.gitInstance(directory) + .push( + remoteType, + branchName, + defaultOptions + ); } /** @@ -315,6 +329,25 @@ export class GitService { return instanceGit.commit(message, fileList, option); } + /** + * Status: Done + * @param repository + * @param branchName + * @param credentials + */ + async switchBranch(repository: Repository, branchName: string, credentials?: Account) { + if (!this.isGitProject(repository.directory)) { + return false; + } + + return await this.gitInstance(repository.directory).checkout(branchName) + .then(resolve => true) + .catch(err => { + console.log(err); + return false; + }); + } + async revert(repository: Repository, files: string[]) { if (files.length === 0) { // reset hard @@ -356,18 +389,6 @@ export class GitService { ]); } - async switchBranch(repository: Repository, branch: RepositoryBranchSummary, credentials?: Account) { - if (!this.isGitProject(repository.directory)) { - return false; - } - - return await this.gitInstance(repository.directory).checkout(branch.name) - .then(resolve => true) - .catch(err => { - console.log(err); - return false; - }); - } async isFileIgnored(repository: Repository, ...filePath: string[]) { return this.gitInstance(repository.directory) diff --git a/src/app/shared/components/branch/ShareBranchComponents.module.ts b/src/app/shared/components/branch/ShareBranchComponents.module.ts index 5ad46d3..506fcaf 100644 --- a/src/app/shared/components/branch/ShareBranchComponents.module.ts +++ b/src/app/shared/components/branch/ShareBranchComponents.module.ts @@ -13,7 +13,7 @@ const declareComps = [ @NgModule({ declarations: [ - ...declareComps, + ...declareComps ], exports: [ ...declareComps diff --git a/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.html b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.html new file mode 100644 index 0000000..71c9d9f --- /dev/null +++ b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.html @@ -0,0 +1 @@ +

branch-merge works!

diff --git a/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.scss b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.spec.ts b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.spec.ts new file mode 100644 index 0000000..1fdb83e --- /dev/null +++ b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BranchMergeComponent } from './branch-merge.component'; + +describe('BranchMergeComponent', () => { + let component: BranchMergeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BranchMergeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BranchMergeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.ts b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.ts new file mode 100644 index 0000000..1ed23de --- /dev/null +++ b/src/app/shared/components/branch/_dialogs/branch-merge/branch-merge.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-branch-merge', + templateUrl: './branch-merge.component.html', + styleUrls: ['./branch-merge.component.scss'] +}) +export class BranchMergeComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/shared/components/branch/_dialogs/branch-new/branch-new-option/branch-new-option.component.html b/src/app/shared/components/branch/_dialogs/branch-new/branch-new-option/branch-new-option.component.html index 2235cae..8125e96 100644 --- a/src/app/shared/components/branch/_dialogs/branch-new/branch-new-option/branch-new-option.component.html +++ b/src/app/shared/components/branch/_dialogs/branch-new/branch-new-option/branch-new-option.component.html @@ -28,7 +28,7 @@
Checkout from
-