Issue with .raw method and git cherry-pick
See original GitHub issueHi, I found this solution in an old closed issue:
There isn’t currently development on supporting cherry-pick
, but you can use the library’s raw
method to still run your command at the moment:
const git = require('simple-git');
git().raw(['cherry-pick', '--strategy=recursive', '-X', 'theirs', sha], function (err, data) {
err && console.error(err);
err || console.log(data);
});
_Originally posted by @steveukx in https://github.com/steveukx/git-js/issues/270#issuecomment-390886146_
Unfortunately, I’m having issues with this approach (working in typescript). My compiler throws this error:
src/main.ts:206:7 - error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type 'string[]' is not assignable to parameter of type 'string'.
206 ['cherry-pick', commitHash],
~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/simple-git/typings/simple-git.d.ts:470:4
470 raw(a: string, b: string, callback?: types.SimpleGitTaskCallback<string>): Response<string>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The last overload is declared here.
Found 1 error.
This is my code (all the presumably necessary bits), changed it a little bit, but even the same code you suggested above throws the same error:
import fsSync from 'fs';
import simpleGit, { SimpleGit, SimpleGitOptions } from 'simple-git';
const gitOptions: SimpleGitOptions = {
baseDir: `${process.cwd()}/docs`,
binary: 'git',
maxConcurrentProcesses: 6,
config: []
};
const git = gitSetup(gitOptions);
function gitSetup (options: SimpleGitOptions): SimpleGit {
if (!fsSync.existsSync('./docs/.git')) {
fsSync.mkdirSync('./docs', { recursive: true });
}
return simpleGit(options);
}
// ...
async function publish (filePath: string): Promise<void> {
// get commit hash
const commitHash = (await git.log({ file: `./docs/${filePath}` })).latest.hash;
// publish
console.log('Publishing ...');
const status = await git
.checkout('publish-test')
.pull()
.raw(
['cherry-pick', commitHash],
(err, data) => {
if (err) {
console.error(err);
} else {
console.log(data);
}
}
)
.push('origin', 'publish-test');
console.log(status);
console.log('Publishing completed.');
}
I even found this overload in the simple-git.d.ts, I wonder why this doesn’t work out:
raw(commands: string | string[] | types.TaskOptions, callback?: types.SimpleGitTaskCallback<string>): Response<string>;
Can you help with this issue?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Git Cherry-Picking: Handling urgent hotfixes | Git Workflows
Java/Spring courses & guideshttps://www.marcobehler.com▻ Newsletterhttps://bit.ly/2K0Ao4F▻ YouTube subhttps://bit.ly/2lVExgmWhat are you ...
Read more >Cannot cherry-pick commit changing not-existing file
My understanding is that a commit represents a full snapshot of working directory. So cherry-picking a commit containing file that currently ...
Read more >Cherry-pick changes - GitLab Docs
In Git, cherry-picking is taking a single commit from one branch and adding it as the latest commit on another branch. The rest...
Read more >git-cherry-pick Documentation - Git
If a commit being cherry picked duplicates a commit already in the current history, it will become empty. By default these redundant commits...
Read more >Git Cherry Pick | Atlassian Git Tutorial
Git cherry -pick is a useful tool when merging several branches together but not always a best practice. Learn when, how and where...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, you should now be able to upgrade to 2.43.0 to use your existing code without the need to explicitly set types.
If you have any other problems, please do open a new issue. Thanks.
Hi, thank you for all the additional detail on this.
There is a problem with the callback types - I’m using an interface with multiple call signatures rather than a union type of function types, so
Parameters<SimpleGitTaskCallback<string>>
currently always comes back as just[Error]
rather than[null, string] | [Error]
.I will arrange a fix for this, but in the meantime you can unblock yourself by explicitly adding types to your code, eg: