Skip to content

Posible bug on .checkout(checkoutWhat [, options]) #873

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
blv-rodrigoerades opened this issue Dec 9, 2022 · 5 comments
Closed

Posible bug on .checkout(checkoutWhat [, options]) #873

blv-rodrigoerades opened this issue Dec 9, 2022 · 5 comments
Labels

Comments

@blv-rodrigoerades
Copy link

blv-rodrigoerades commented Dec 9, 2022

If I try to use a checkout passing a branch and an array of options like:

simpleGit().checkout('PAY-XXXXX' ,[ '-B'])

I got an error saying:

Error occurred in handler for 'event.cloneUpdateRepo': GitError: error: pathspec 'PAY-XXXXX' did not match any file(s) known to git
error: pathspec 'B' did not match any file(s) known to git

    at Object.action (..../node_modules/simple-git/dist/cjs/index.js:1261:25)
    at PluginStore.exec (...../simple-git/dist/cjs/index.js:1296:29)
    at /...../simple-git/dist/cjs/index.js:1661:43
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (...../node_modules/simple-git/dist/cjs/index.js:1659:16)
    at GitExecutorChain.<anonymous> (....../node_modules/simple-git/dist/cjs/index.js:1643:44)
    at Generator.next (<anonymous>)
    at fulfilled (......./node_modules/simple-git/dist/cjs/index.js:55:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5) {
  task: {
    commands: [ 'checkout', 'PAY-XXXXX', 'B' ],
    format: 'utf-8',
    parser: [Function: parser]
  }
}

It looks like we are trying to do:

git checkout PAY-XXXXX -B

but parameter should be set before the branch name like:

git checkout -B PAY-XXXXX

@Bill2015
Copy link

Bill2015 commented Dec 9, 2022

There is two equivalent way to checkout

simpleGit().checkout(['-b', 'PAY-XXXXX'])

simpleGit().raw('checkout', '-b', 'PAY-XXXXX')

You can also see this post #501 (comment) for more information.

@steveukx
Copy link
Owner

Hello, there are separate methods for checking out a branch. Please switch to either checkoutBranch or checkoutLocalBranch (depending on whether you want to also set up a remote tracking branch) instead of checkout:

simpleGit(). checkoutLocalBranch('PAY-XXXXX'); // git checkout -b PAY-XXXXX
simpleGit(). checkoutBranch('PAY-XXXXX', 'origin/PAY-XXXXX'); // git checkout -b PAY-XXXXX origin/PAY-XXXXX

Docs for this can be found at https://github.com/steveukx/git-js#git-checkout

@blv-rodrigoerades
Copy link
Author

@Bill2015, yea that's what I'm doing right now. (simpleGit().raw('checkout', '-B', 'PAY-XXXXX')) 👍
Because simpleGit().checkout(['-B', 'PAY-XXXXX']) will not work as stated before

@steveukx , thanks for the tip, I show it, but the thing is that I want to do a git checkout -B PAY-XXXXX, noticed that I'm using a capital -B, which it doesn't do the same as '-b'

@steveukx
Copy link
Owner

Ah thank you for the clarification on the -b / -B use.

I will have a look at switching the b modifier in use, but until that's available you can switch to using raw to completely customise the command:

simpleGit().raw('checkout', '-B', 'PAY-XXXXX');

@blv-rodrigoerades
Copy link
Author

Thanks @steveukx 👍. raw is the way for me to go now.

Just for clarification,.checkout(checkoutWhat [, options]) will never work if you use options since the output will add options after the branch name (and that will fail).

steveukx added a commit that referenced this issue Dec 15, 2022
…hen using `checkoutBranch` / `checkoutLocalBranch`.

Based on requirement detailed in #873
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants