Skip to content

Commit 8fd53d1

Browse files
authored
Merge pull request #76 from guplem/gdp-show-branch-in-repo-list
Show current branch name in the repository list
2 parents 44a1967 + 7f465ce commit 8fd53d1

13 files changed

Lines changed: 132 additions & 7 deletions

File tree

app/src/lib/app-state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ export interface IAppState {
394394
/** Whether or not the user will see check marks indicating a line is included in the check in the diff */
395395
readonly showDiffCheckMarks: boolean
396396

397+
/** Whether or not to show the current branch name next to each repository in the repository list */
398+
readonly showBranchNameInRepoList: boolean
399+
397400
/**
398401
* Cached repo rulesets. Used to prevent repeatedly querying the same
399402
* rulesets to check their bypass status.

app/src/lib/stores/app-store.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ export const underlineLinksDefault = true
481481
export const showDiffCheckMarksDefault = true
482482
export const showDiffCheckMarksKey = 'diff-check-marks-visible'
483483

484+
export const showBranchNameInRepoListDefault = false
485+
export const showBranchNameInRepoListKey = 'show-branch-name-in-repo-list'
486+
484487
const commitMessageGenerationDisclaimerLastSeenKey =
485488
'commit-message-generation-disclaimer-last-seen'
486489

@@ -646,6 +649,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
646649

647650
private showDiffCheckMarks: boolean = showDiffCheckMarksDefault
648651

652+
private showBranchNameInRepoList: boolean = showBranchNameInRepoListDefault
653+
649654
private cachedRepoRulesets = new Map<number, IAPIRepoRuleset>()
650655

651656
private underlineLinks: boolean = underlineLinksDefault
@@ -1193,6 +1198,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
11931198
cachedRepoRulesets: this.cachedRepoRulesets,
11941199
underlineLinks: this.underlineLinks,
11951200
showDiffCheckMarks: this.showDiffCheckMarks,
1201+
showBranchNameInRepoList: this.showBranchNameInRepoList,
11961202
updateState: updateStore.state,
11971203
commitMessageGenerationDisclaimerLastSeen:
11981204
this.commitMessageGenerationDisclaimerLastSeen,
@@ -2596,6 +2602,11 @@ export class AppStore extends TypedBaseStore<IAppState> {
25962602
showDiffCheckMarksDefault
25972603
)
25982604

2605+
this.showBranchNameInRepoList = getBoolean(
2606+
showBranchNameInRepoListKey,
2607+
showBranchNameInRepoListDefault
2608+
)
2609+
25992610
this.commitMessageGenerationDisclaimerLastSeen =
26002611
getNumber(commitMessageGenerationDisclaimerLastSeenKey) ?? null
26012612

@@ -3991,6 +4002,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
39914002
lookup.set(repository.id, {
39924003
aheadBehind: status.branchAheadBehind || null,
39934004
changedFilesCount: status.workingDirectory.files.length,
4005+
branchName: status.currentBranch,
39944006
})
39954007
}
39964008
/**
@@ -4032,9 +4044,11 @@ export class AppStore extends TypedBaseStore<IAppState> {
40324044
const existing = lookup.get(repository.id)
40334045
lookup.set(repository.id, {
40344046
aheadBehind: aheadBehind,
4035-
// We don't need to update changedFilesCount here since it was already
4036-
// set when calling `updateSidebarIndicator()` with the status object.
4047+
// We don't need to update changedFilesCount or branchName here since
4048+
// they were already set when calling `updateSidebarIndicator()` with
4049+
// the status object.
40374050
changedFilesCount: existing?.changedFilesCount ?? 0,
4051+
branchName: existing?.branchName,
40384052
})
40394053
this.emitUpdate()
40404054
}
@@ -9120,6 +9134,14 @@ export class AppStore extends TypedBaseStore<IAppState> {
91209134
}
91219135
}
91229136

9137+
public _updateShowBranchNameInRepoList(showBranchNameInRepoList: boolean) {
9138+
if (showBranchNameInRepoList !== this.showBranchNameInRepoList) {
9139+
this.showBranchNameInRepoList = showBranchNameInRepoList
9140+
setBoolean(showBranchNameInRepoListKey, showBranchNameInRepoList)
9141+
this.emitUpdate()
9142+
}
9143+
}
9144+
91239145
public _updateFileListFilter(
91249146
repository: Repository,
91259147
filterUpdate: Partial<IFileListFilterState>

app/src/models/repository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ export interface ILocalRepositoryState {
220220
* The number of uncommitted changes currently in the repository.
221221
*/
222222
readonly changedFilesCount: number
223+
/**
224+
* The name of the currently checked out branch, or `undefined` if the
225+
* branch name is not available (e.g. detached HEAD).
226+
*/
227+
readonly branchName?: string
223228
}
224229

225230
/**

app/src/ui/app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ export class App extends React.Component<IAppProps, IAppState> {
16441644
onEditGlobalGitConfig={this.editGlobalGitConfig}
16451645
underlineLinks={this.state.underlineLinks}
16461646
showDiffCheckMarks={this.state.showDiffCheckMarks}
1647+
showBranchNameInRepoList={this.state.showBranchNameInRepoList}
16471648
/>
16481649
)
16491650
case PopupType.RepositorySettings: {
@@ -3027,6 +3028,7 @@ export class App extends React.Component<IAppProps, IAppState> {
30273028
externalEditorLabel={this.externalEditorLabel}
30283029
shellLabel={useCustomShell ? undefined : selectedShell}
30293030
dispatcher={this.props.dispatcher}
3031+
showBranchNameInRepoList={this.state.showBranchNameInRepoList}
30303032
/>
30313033
)
30323034
}

app/src/ui/dispatcher/dispatcher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,6 +4191,12 @@ export class Dispatcher {
41914191
return this.appStore._updateShowDiffCheckMarks(diffCheckMarks)
41924192
}
41934193

4194+
public setShowBranchNameInRepoList(showBranchNameInRepoList: boolean) {
4195+
return this.appStore._updateShowBranchNameInRepoList(
4196+
showBranchNameInRepoList
4197+
)
4198+
}
4199+
41944200
public testPruneBranches() {
41954201
return this.appStore._testPruneBranches()
41964202
}

app/src/ui/preferences/appearance.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface IAppearanceProps {
2424
readonly onShowRecentRepositoriesChanged: (show: boolean) => void
2525
readonly showWorktrees: boolean
2626
readonly onShowWorktreesChanged: (show: boolean) => void
27+
readonly showBranchNameInRepoList: boolean
28+
readonly onShowBranchNameInRepoListChanged: (value: boolean) => void
2729
}
2830

2931
interface IAppearanceState {
@@ -213,6 +215,12 @@ export class Appearance extends React.Component<
213215
)
214216
}
215217

218+
private onShowBranchNameInRepoListChanged = (
219+
event: React.FormEvent<HTMLInputElement>
220+
) => {
221+
this.props.onShowBranchNameInRepoListChanged(event.currentTarget.checked)
222+
}
223+
216224
private renderRepositoryList() {
217225
return (
218226
<div className="advanced-section">
@@ -227,6 +235,15 @@ export class Appearance extends React.Component<
227235
}
228236
onChange={this.onShowRecentRepositoriesChanged}
229237
/>
238+
<Checkbox
239+
label="Show current branch name next to repository name"
240+
value={
241+
this.props.showBranchNameInRepoList
242+
? CheckboxValue.On
243+
: CheckboxValue.Off
244+
}
245+
onChange={this.onShowBranchNameInRepoListChanged}
246+
/>
230247
</div>
231248
)
232249
}

app/src/ui/preferences/preferences.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ interface IPreferencesProps {
9393
readonly showRecentRepositories: boolean
9494
readonly showWorktrees: boolean
9595
readonly repositoryIndicatorsEnabled: boolean
96+
readonly showBranchNameInRepoList: boolean
9697
readonly hideWindowOnQuit: boolean
9798
readonly onEditGlobalGitConfig: () => void
9899
readonly underlineLinks: boolean
@@ -144,6 +145,7 @@ interface IPreferencesState {
144145
*/
145146
readonly existingLockFilePath?: string
146147
readonly repositoryIndicatorsEnabled: boolean
148+
readonly showBranchNameInRepoList: boolean
147149
readonly hideWindowOnQuit: boolean
148150

149151
readonly initiallySelectedTheme: ApplicationTheme
@@ -219,6 +221,7 @@ export class Preferences extends React.Component<
219221
showRecentRepositories: this.props.showRecentRepositories,
220222
showWorktrees: this.props.showWorktrees,
221223
repositoryIndicatorsEnabled: this.props.repositoryIndicatorsEnabled,
224+
showBranchNameInRepoList: this.props.showBranchNameInRepoList,
222225
hideWindowOnQuit: this.props.hideWindowOnQuit,
223226
initiallySelectedTheme: this.props.selectedTheme,
224227
initiallySelectedTabSize: this.props.selectedTabSize,
@@ -552,6 +555,10 @@ export class Preferences extends React.Component<
552555
}
553556
showWorktrees={this.state.showWorktrees}
554557
onShowWorktreesChanged={this.onShowWorktreesChanged}
558+
showBranchNameInRepoList={this.state.showBranchNameInRepoList}
559+
onShowBranchNameInRepoListChanged={
560+
this.onShowBranchNameInRepoListChanged
561+
}
555562
/>
556563
)
557564
break
@@ -797,6 +804,12 @@ export class Preferences extends React.Component<
797804
this.setState({ showDiffCheckMarks })
798805
}
799806

807+
private onShowBranchNameInRepoListChanged = (
808+
showBranchNameInRepoList: boolean
809+
) => {
810+
this.setState({ showBranchNameInRepoList })
811+
}
812+
800813
private onSelectedTabSizeChanged = (tabSize: number) => {
801814
this.props.dispatcher.setSelectedTabSize(tabSize)
802815
}
@@ -1002,6 +1015,8 @@ export class Preferences extends React.Component<
10021015

10031016
dispatcher.setDiffCheckMarksSetting(this.state.showDiffCheckMarks)
10041017

1018+
dispatcher.setShowBranchNameInRepoList(this.state.showBranchNameInRepoList)
1019+
10051020
this.props.onDismissed()
10061021
}
10071022

app/src/ui/repositories-list/group-repositories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface IRepositoryListItem extends IFilterListItem {
6161
readonly needsDisambiguation: boolean
6262
readonly aheadBehind: IAheadBehind | null
6363
readonly changedFilesCount: number
64+
readonly branchName?: string
6465
}
6566

6667
const recentRepositoriesThreshold = 7
@@ -182,6 +183,7 @@ const toSortedListItems = (
182183
((allNames.get(title) ?? 0) > 1 && group.kind === 'recent'),
183184
aheadBehind: repoState?.aheadBehind ?? null,
184185
changedFilesCount: repoState?.changedFilesCount ?? 0,
186+
branchName: repoState?.branchName,
185187
}
186188
})
187189
.sort(({ repository: x }, { repository: y }) =>

app/src/ui/repositories-list/repositories-list.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ interface IRepositoriesListProps {
7575
readonly filterText: string
7676

7777
readonly dispatcher: Dispatcher
78+
79+
/** Whether to show the branch name next to each repository */
80+
readonly showBranchNameInRepoList: boolean
7881
}
7982

8083
interface IRepositoriesListState {
@@ -165,6 +168,9 @@ export class RepositoriesList extends React.Component<
165168
matches={matches}
166169
aheadBehind={item.aheadBehind}
167170
changedFilesCount={item.changedFilesCount}
171+
branchName={
172+
this.props.showBranchNameInRepoList ? item.branchName : undefined
173+
}
168174
/>
169175
)
170176
}
@@ -193,6 +199,9 @@ export class RepositoriesList extends React.Component<
193199
item: IRepositoryListItem
194200
): JSX.Element | string | null => {
195201
const { repository, aheadBehind, changedFilesCount } = item
202+
const branchName = this.props.showBranchNameInRepoList
203+
? item.branchName
204+
: undefined
196205
const gitHubRepo =
197206
repository instanceof Repository ? repository.gitHubRepository : null
198207
const alias = repository instanceof Repository ? repository.alias : null
@@ -217,6 +226,12 @@ export class RepositoriesList extends React.Component<
217226
<div className="label">Path: </div>
218227
{repository.path}
219228
</div>
229+
{branchName && (
230+
<div>
231+
<div className="label">Branch: </div>
232+
{branchName}
233+
</div>
234+
)}
220235
{aheadBehindTooltip && (
221236
<div>
222237
<div className="label">

app/src/ui/repositories-list/repository-list-item.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ interface IRepositoryListItemProps {
2727

2828
/** Number of uncommitted changes */
2929
readonly changedFilesCount: number
30+
31+
/** The name of the current branch, if available */
32+
readonly branchName?: string
3033
}
3134

3235
/** A repository item. */
@@ -76,6 +79,13 @@ export class RepositoryListItem extends React.Component<
7679
/>
7780
</div>
7881

82+
{this.props.branchName && (
83+
<span className="branch-name">
84+
<Octicon className="branch-icon" symbol={octicons.gitBranch} />
85+
{this.props.branchName}
86+
</span>
87+
)}
88+
7989
{repository instanceof Repository &&
8090
renderRepoIndicators({
8191
aheadBehind: this.props.aheadBehind,
@@ -98,6 +108,7 @@ export class RepositoryListItem extends React.Component<
98108
{alias && <> ({alias})</>}
99109
</div>
100110
<div>{repo.path}</div>
111+
{this.props.branchName && <div>Branch: {this.props.branchName}</div>}
101112
</>
102113
)
103114
}
@@ -109,7 +120,8 @@ export class RepositoryListItem extends React.Component<
109120
) {
110121
return (
111122
nextProps.repository.id !== this.props.repository.id ||
112-
nextProps.matches !== this.props.matches
123+
nextProps.matches !== this.props.matches ||
124+
nextProps.branchName !== this.props.branchName
113125
)
114126
} else {
115127
return true

0 commit comments

Comments
 (0)