forked from desktop/desktop
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request desktop#11549 from desktop/cherry-pick-git-no-conf…
…ict-resolution Cherry pick git no confict resolution
- Loading branch information
Showing
5 changed files
with
389 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Repository } from '../../models/repository' | ||
import { git, IGitResult } from './core' | ||
|
||
/** The app-specific results from attempting to cherry pick commits*/ | ||
export enum CherryPickResult { | ||
/** | ||
* Git completed the cherry pick without reporting any errors, and the caller can | ||
* signal success to the user. | ||
*/ | ||
CompletedWithoutError = 'CompletedWithoutError', | ||
|
||
/** | ||
* An unexpected error as part of the cherry pick flow was caught and handled. | ||
* | ||
* Check the logs to find the relevant Git details. | ||
*/ | ||
Error = 'Error', | ||
} | ||
|
||
/** | ||
* A stub function to initiate cherry picking in the app. | ||
* | ||
* @param revisionRange - this could be a single commit sha or could be a range | ||
* of commits like sha1..sha2 or inclusively sha1^..sha2 | ||
*/ | ||
export async function cherryPick( | ||
repository: Repository, | ||
revisionRange: string | ||
): Promise<CherryPickResult> { | ||
const result = await git( | ||
['cherry-pick', revisionRange], | ||
repository.path, | ||
'cherry pick' | ||
) | ||
|
||
return parseCherryPickResult(result) | ||
} | ||
|
||
function parseCherryPickResult(result: IGitResult): CherryPickResult { | ||
if (result.exitCode === 0) { | ||
return CherryPickResult.CompletedWithoutError | ||
} | ||
|
||
// TODO: handle known exceptions | ||
|
||
throw new Error(`Unhandled result found: '${JSON.stringify(result)}'`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Repository } from '../../src/models/repository' | ||
import { setupEmptyRepositoryDefaultMain } from './repositories' | ||
import { makeCommit, switchTo, createBranch } from './repository-scaffolding' | ||
|
||
/** | ||
* Creates a test repository to be used for testing cherry pick behaviour with: | ||
* - one commit on default branch, | ||
* - one commit on `featureBranchName` to cherry pick | ||
* - creates `targetBranchName` off of default branch | ||
*/ | ||
export async function createRepository( | ||
featureBranchName: string, | ||
targetBranchName: string | ||
): Promise<Repository> { | ||
const repository = await setupEmptyRepositoryDefaultMain() | ||
|
||
const firstCommit = { | ||
commitMessage: 'First!', | ||
entries: [ | ||
{ | ||
path: 'README.md', | ||
contents: '# HELLO WORLD! \n', | ||
}, | ||
], | ||
} | ||
await makeCommit(repository, firstCommit) | ||
|
||
await createBranch(repository, featureBranchName, 'HEAD') | ||
await createBranch(repository, targetBranchName, 'HEAD') | ||
|
||
await switchTo(repository, featureBranchName) | ||
const featureBranchCommit = { | ||
commitMessage: 'Cherry Picked Feature!', | ||
entries: [ | ||
{ | ||
path: 'THING.md', | ||
contents: '# HELLO WORLD! \nTHINGS GO HERE\n', | ||
}, | ||
], | ||
} | ||
await makeCommit(repository, featureBranchCommit) | ||
|
||
await switchTo(repository, targetBranchName) | ||
return repository | ||
} |
Oops, something went wrong.