Skip to content

Commit 668de29

Browse files
committed
Manage the repository state correctly
1 parent 681e817 commit 668de29

6 files changed

Lines changed: 51 additions & 15 deletions

File tree

src/renderer/components/commit-list.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import * as Git from 'nodegit';
33
import { CommitItem } from './commit-item';
44
import { IndexItem } from './index-item';
55
import { InputDialogHandler } from './input-dialog';
6-
import { RepoWrapper } from '../helpers/repo-wrapper';
6+
import { RepoWrapper, RepoState } from '../helpers/repo-wrapper';
77
import { getBranchColor } from '../helpers/commit-graph';
88

99
const ITEM_HEIGHT = 28;
1010

1111
export interface CommitListProps {
1212
repo: RepoWrapper;
13+
repoState: RepoState;
1314
selectedCommit: Git.Commit | null;
1415
onCommitSelect: (commit: Git.Commit) => void;
1516
onIndexSelect: () => void;
@@ -140,7 +141,7 @@ export class CommitList extends React.PureComponent<CommitListProps, CommitListS
140141
// Select visible commits and add index if necessary
141142
const items: JSX.Element[] = [];
142143
if (this.state.start === -1) {
143-
items.push(<IndexItem state={this.props.repo.repo.state()} selected={this.props.selectedCommit === null}
144+
items.push(<IndexItem repoState={this.props.repoState} selected={this.props.selectedCommit === null}
144145
onIndexSelect={this.props.onIndexSelect}
145146
key='index' />);
146147
}

src/renderer/components/graph-viewer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { CommitList } from './commit-list';
55
import { Splitter } from './splitter';
66
import { ReferenceExplorer } from './reference-explorer'
77
import { InputDialogHandler } from './input-dialog';
8-
import { RepoWrapper } from "../helpers/repo-wrapper";
8+
import { RepoWrapper, RepoState } from "../helpers/repo-wrapper";
99

1010
export interface GraphViewerProps {
1111
repo: RepoWrapper;
12+
repoState: RepoState;
1213
selectedCommit: Git.Commit | null;
1314
onCommitSelect: (commit: Git.Commit) => void;
1415
onIndexSelect: () => void;

src/renderer/components/index-item.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
22
import * as Git from 'nodegit';
3+
import { RepoState } from '../helpers/repo-wrapper';
34

45
export interface IndexItemProps {
5-
state: number;
6+
repoState: RepoState;
67
selected: boolean;
78
onIndexSelect: () => void;
89
}
@@ -20,19 +21,17 @@ export class IndexItem extends React.PureComponent<IndexItemProps, {}> {
2021
render() {
2122
//console.log(this.props.state);
2223
let suffix = ''
23-
switch (this.props.state) {
24-
case Git.Repository.STATE.CHERRYPICK:
24+
switch (this.props.repoState) {
25+
case RepoState.Cherrypick:
2526
suffix = 'cherrypicking'
2627
break;
27-
case Git.Repository.STATE.MERGE:
28+
case RepoState.Merge:
2829
suffix = 'merging';
2930
break;
30-
case Git.Repository.STATE.REBASE:
31-
case Git.Repository.STATE.REBASE_INTERACTIVE:
32-
case Git.Repository.STATE.REBASE_MERGE:
31+
case RepoState.Rebase:
3332
suffix = 'rebasing';
3433
break;
35-
case Git.Repository.STATE.REVERT:
34+
case RepoState.Revert:
3635
suffix = 'reverting';
3736
break;
3837
}

src/renderer/components/index-viewer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from 'react';
22
import * as Git from 'nodegit';
33
import { PatchList } from './patch-list';
4-
import { RepoWrapper, PatchType } from '../helpers/repo-wrapper';
4+
import { RepoWrapper, PatchType, RepoState } from '../helpers/repo-wrapper';
55

66
export interface IndexViewerProps {
77
repo: RepoWrapper;
8+
repoState: RepoState;
89
selectedPatch: Git.ConvenientPatch | null;
910
onPatchSelect: (patch: Git.ConvenientPatch | null, type: PatchType) => void;
1011
}
@@ -215,7 +216,7 @@ export class IndexViewer extends React.PureComponent<IndexViewerProps, IndexView
215216
}
216217

217218
getSubmitButton() {
218-
if (this.props.repo.repo.isMerging()) {
219+
if (this.props.repoState === RepoState.Merge) {
219220
return (
220221
<>
221222
<button className='green-button'
@@ -279,7 +280,7 @@ export class IndexViewer extends React.PureComponent<IndexViewerProps, IndexView
279280
onSelectedPatchesChange={this.handleSelectedStagedPatchesChange} />
280281
<div className='section-header'>
281282
<p>Commit message</p>
282-
{this.props.repo.headCommit && !this.props.repo.repo.isMerging() ?
283+
{this.props.repo.headCommit && this.props.repoState !== RepoState.Merge ?
283284
<div className='amend-container'>
284285
<input type='checkbox' id='amend' name='amend' checked={this.state.amend} onChange={this.handleAmendChange} />
285286
<label htmlFor='amend'>Amend</label>

src/renderer/components/repo-dashboard.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Splitter } from './splitter';
1212
import { Toolbar } from './toolbar';
1313
import { LoadingScreen, LoadingState } from './loading-screen';
1414
import { InputDialogHandler } from './input-dialog';
15-
import { RepoWrapper, PatchType } from '../helpers/repo-wrapper';
15+
import { RepoWrapper, PatchType, RepoState } from '../helpers/repo-wrapper';
1616
import { CancellablePromise, makeCancellable } from '../helpers/make-cancellable';
1717

1818
export interface RepoDashboardProps {
@@ -25,6 +25,7 @@ export interface RepoDashboardProps {
2525
}
2626

2727
export interface RepoDashboardState {
28+
repoState: RepoState;
2829
loadingState: LoadingState;
2930
selectedCommit: Git.Commit | null;
3031
selectedPatch: Git.ConvenientPatch | null;
@@ -57,6 +58,7 @@ export class RepoDashboard extends React.PureComponent<RepoDashboardProps, RepoD
5758
this.exitPatchViewer = this.exitPatchViewer.bind(this);
5859
this.handleRightPanelResize = this.handleRightPanelResize.bind(this);
5960
this.state = {
61+
repoState: this.props.repo.getState(),
6062
loadingState: LoadingState.NotLoading,
6163
selectedCommit: null,
6264
selectedPatch: null,
@@ -188,6 +190,9 @@ export class RepoDashboard extends React.PureComponent<RepoDashboardProps, RepoD
188190

189191
async refreshIndex() {
190192
if (!this.state.selectedCommit && this.rightViewer.current) {
193+
this.setState({
194+
repoState: this.props.repo.getState()
195+
});
191196
const indexViewer = this.rightViewer.current as IndexViewer;
192197
await indexViewer.refresh();
193198
if (this.state.selectedPatch && this.state.patchType !== PatchType.Committed) {
@@ -233,6 +238,7 @@ export class RepoDashboard extends React.PureComponent<RepoDashboardProps, RepoD
233238
leftViewer = <LoadingScreen state={this.state.loadingState} />
234239
} else {
235240
leftViewer = <GraphViewer repo={this.props.repo}
241+
repoState={this.state.repoState}
236242
selectedCommit={this.state.selectedCommit}
237243
onCommitSelect={this.handleCommitSelect}
238244
onIndexSelect={this.handleIndexSelect}
@@ -251,6 +257,7 @@ export class RepoDashboard extends React.PureComponent<RepoDashboardProps, RepoD
251257
ref={this.rightViewer as React.RefObject<CommitViewer>} />
252258
} else {
253259
rightViewer = <IndexViewer repo={this.props.repo}
260+
repoState={this.state.repoState}
254261
selectedPatch={this.state.selectedPatch}
255262
onPatchSelect={this.handlePatchSelect}
256263
ref={this.rightViewer as React.RefObject<IndexViewer>} />

src/renderer/helpers/repo-wrapper.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export enum PatchType {
3333
Committed
3434
}
3535

36+
export enum RepoState {
37+
Cherrypick,
38+
Commit,
39+
Merge,
40+
Rebase,
41+
Revert
42+
}
43+
3644
export class Stash {
3745
index: number;
3846
commit: Git.Commit;
@@ -305,6 +313,25 @@ export class RepoWrapper {
305313
return await Git.Repository.open(path);
306314
}
307315

316+
// State
317+
318+
getState() {
319+
switch (this.repo.state()) {
320+
case Git.Repository.STATE.CHERRYPICK:
321+
return RepoState.Cherrypick;
322+
case Git.Repository.STATE.MERGE:
323+
return RepoState.Merge;
324+
case Git.Repository.STATE.REBASE:
325+
case Git.Repository.STATE.REBASE_INTERACTIVE:
326+
case Git.Repository.STATE.REBASE_MERGE:
327+
return RepoState.Rebase;
328+
case Git.Repository.STATE.REVERT:
329+
return RepoState.Revert;
330+
default:
331+
return RepoState.Commit;
332+
}
333+
}
334+
308335
// Head operations
309336

310337
async checkoutReference(reference: Git.Reference) {

0 commit comments

Comments
 (0)