Skip to content

Commit

Permalink
ScmAmendComponent fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Nigel Westbury <nigelipse@miegel.org>
  • Loading branch information
westbury authored and vinokurig committed May 21, 2019
1 parent 3b29323 commit 3bed733
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
7 changes: 3 additions & 4 deletions packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,11 @@ export class GitAmendSupport implements ScmAmendSupport {

constructor(protected readonly repository: Repository, protected readonly git: Git) { }

public async getIntialAmendingCommits(storedState: string, lastHead: string): Promise<ScmCommit[]> {
const { amendingHeadCommitSha } = JSON.parse(storedState);
public async getInitialAmendingCommits(amendingHeadCommitSha: string, latestCommitSha: string): Promise<ScmCommit[]> {
const commits = await this.git.log(
this.repository,
{
range: { toRevision: amendingHeadCommitSha, fromRevision: lastHead },
range: { toRevision: amendingHeadCommitSha, fromRevision: latestCommitSha },
maxCount: 50
}
);
Expand All @@ -998,7 +997,7 @@ export class GitAmendSupport implements ScmAmendSupport {
}

public async getLastCommit(): Promise<ScmCommit | undefined> {
const commits = await this.git.log(this.repository, { maxCount: 1, shortSha: true });
const commits = await this.git.log(this.repository, { maxCount: 1 });
if (commits.length > 0) {
return this.createScmCommit(commits[0]);
}
Expand Down
21 changes: 10 additions & 11 deletions packages/scm/src/browser/scm-amend-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,23 @@ export class ScmAmendComponent extends React.Component<ScmAmendComponentProps, S
if (this.state.lastCommit && nextCommit) {
const direction: 'up' | 'down' = this.transitionHint === 'amend' ? 'up' : 'down';
const transitionData = { direction, previousLastCommit: this.state.lastCommit };
const amendingCommits = this.state.amendingCommits.concat([]);
const amendingCommits = this.state.amendingCommits.concat([]); // copy the array
switch (this.transitionHint) {
case 'amend':
if (this.state.lastCommit) {
amendingCommits.push(this.state.lastCommit);
if (this.state.amendingCommits.length === 1) {
const storageKey = this.getStorageKey();
const serializedState = JSON.stringify({
amendingHeadCommitSha: this.state.amendingCommits[0].commit.id,
latestCommitSha: nextCommit.commit.id
});
this.props.storageService.setData<string | undefined>(storageKey, serializedState);
}

const storageKey = this.getStorageKey();
const serializedState = JSON.stringify({
amendingHeadCommitSha: amendingCommits[0].commit.id,
latestCommitSha: nextCommit.commit.id
});
this.props.storageService.setData<string | undefined>(storageKey, serializedState);
}
break;
case 'unamend':
amendingCommits.pop();
if (this.state.amendingCommits.length === 0) {
if (amendingCommits.length === 0) {
const storageKey = this.getStorageKey();
this.props.storageService.setData<string | undefined>(storageKey, undefined);
}
Expand Down Expand Up @@ -190,7 +189,7 @@ export class ScmAmendComponent extends React.Component<ScmAmendComponentProps, S
// head commit after the last 'amend'.
return [];
}
const commits = await this.props.scmAmendSupport.getIntialAmendingCommits(amendingHeadCommitSha, lastCommit.id);
const commits = await this.props.scmAmendSupport.getInitialAmendingCommits(amendingHeadCommitSha, lastCommit.id);

const amendingCommitPromises = commits.map(async commit => {
const avatar = await this.props.avatarService.getAvatar(commit.authorEmail);
Expand Down
2 changes: 1 addition & 1 deletion packages/scm/src/browser/scm-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface ScmCommit {
}

export interface ScmAmendSupport {
getIntialAmendingCommits(storedState: string, lastHead: string): Promise<ScmCommit[]>
getInitialAmendingCommits(amendingHeadCommitSha: string, latestCommitSha: string): Promise<ScmCommit[]>
getMessage(commit: string): Promise<string>;
reset(commit: string): Promise<void>;
getLastCommit(): Promise<ScmCommit | undefined>;
Expand Down

0 comments on commit 3bed733

Please sign in to comment.