Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

--end-of-options is not supported on git 2.35.1 and 2.25.1 #77

Closed
flopana opened this issue Apr 22, 2022 · 20 comments
Closed

--end-of-options is not supported on git 2.35.1 and 2.25.1 #77

flopana opened this issue Apr 22, 2022 · 20 comments
Assignees
Labels

Comments

@flopana
Copy link

flopana commented Apr 22, 2022

In Commit 5e82d54 you have added the option --end-of-options to every command.
In theory this should just work and also the documentation 2.35.1 and 2.25.1 mention this option.

But on both versions specifically the latest for ubuntu 20.04 and 2.35.1 as it's used on Ubuntu 20.04 in github actions always fail for me with the --end-of-options option enabled.

user@machine:~/testrepo$ git checkout --end-of-options test
error: pathspec '--end-of-options' did not match any file(s) known to git
error: pathspec 'test' did not match any file(s) known to git

user@machine:~/testrepo$ git checkout test
Switched to branch 'test'

user@machine:~/testrepo$ git --version
git version 2.25.1

The above is from my server running ubuntu 20.04 with latest version of git, the exact same behaviour happens in github actions for me.

Edit: fixed wrong link

@flopana
Copy link
Author

flopana commented Apr 22, 2022

Whats even weirder is that your pipeline also runs on ubuntu-latest but here it seems to work.

For now i've reverted back to v4.0.2 of git-php.
My usecase does indeed includes user input but it's only used by admins of the system an not regular users, so not running the --end-of-options option is no problem for me.

@janpecha janpecha self-assigned this Apr 24, 2022
@janpecha janpecha added the bug label Apr 24, 2022
@janpecha
Copy link
Contributor

Hi, thanks for report! I tried fix it in version 4.0.4. Please try if it solves issue.

@flopana
Copy link
Author

flopana commented Apr 24, 2022

Thank you very much. Will try it tomorrow morning at work

@flopana
Copy link
Author

flopana commented Apr 25, 2022

The update has worked perfectly. Thank You!

@LeoColomb
Copy link

@janpecha It works for the checkout, but isn't the issue the same for all the other commands as well?
As example, a git push done in a GitHub Action run: https://github.com/composer-wordpress/.github/runs/6180460214?check_suite_focus=true#step:8:21

@flopana
Copy link
Author

flopana commented Apr 26, 2022

@janpecha It works for the checkout, but isn't the issue the same for all the other commands as well? As example, a git push done in a GitHub Action run: https://github.com/composer-wordpress/.github/runs/6180460214?check_suite_focus=true#step:8:21

Yep for me too. Wanted to report it but github had massive problems that day and i simply forgot.

The --end-of-options option doesn't seem to work for me anywhere.
Currently my pipelines fails with git pull branch_name --end-of-options origin

@janpecha janpecha reopened this Apr 27, 2022
@janpecha
Copy link
Contributor

@flopana @LeoColomb Hi, how you call pull() method? Try use

$repo->pull(['origin', 'branch_name']);

@LeoColomb
Copy link

LeoColomb commented Apr 27, 2022

@janpecha
Copy link
Contributor

@LeoColomb sorry, I overlooked it :) try $this->gitRepo->push(['origin', "refs/tags/{$version}"]);

@LeoColomb
Copy link

@janpecha Ok, yes, I see what you mean.
Just one concern, this is passing array to an argument expected to be string.

/**
* Push changes to a remote
* @param string|NULL $remote
* @param array<mixed>|NULL $params
* @return static
* @throws GitException
*/
public function push($remote = NULL, array $params = NULL)
{
$this->run('push', $params, '--end-of-options', $remote);
return $this;
}

So I guess, it would be "better" to actually do:

$this->gitRepo->push("origin refs/tags/{$version}");

Not a big fan, but should work, right?

@janpecha
Copy link
Contributor

I just changed PHPDoc for this methods - 24f4e51#diff-a6f1a39ec7e0b5e21136926e7fa3b9700988e97d15b860a2f6d48a655e2de571. It accepts string[] too.

@LeoColomb
Copy link

All good, the suggested change fixes the runs, and it actually makes sense.
Thanks @janpecha!

@zerkms
Copy link

zerkms commented Apr 28, 2022

Btw it's still some entries in the Git class too: https://github.com/czproject/git-php/blob/24f4e51cc536a723b7838686284d1c21c6de088b/src/Git.php

@janpecha
Copy link
Contributor

@zerkms Hi, what do you mean?

@zerkms
Copy link

zerkms commented Apr 30, 2022

Sorry, I meant that $git->cloneRepository(...) still fails with error: unknown option 'end-of-options' too when used like this:

return (new Git())->cloneRepository($url, $path, ['--recurse-submodules']);

@zerkms
Copy link

zerkms commented Apr 30, 2022

UPD: oh I understand now, I run it in a container with a quite old git (2.17), that's why it fails. My apologies.

@xaviapa
Copy link

xaviapa commented May 12, 2022

Since 4.0.3 I'm having a problem with the push command.
Looks like in 5e82d54 you swapped from
$this->run('push', $remote, $params);
to
$this->run('push', $params, '--end-of-options', $remote);

This results in the following command which return an error as the "remote" (origin) should be placed after the GIT command (push):

git push '<branch_name>' -u --end-of-options origin

fatal: '<branch_name>' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

If you run the command with the right order you have no problem:

git push origin '<branch_name>' -u --end-of-options

Everything up-to-date

@janpecha
Copy link
Contributor

Hello, how you call push() method? Try use $repo->push(['origin', 'branch-name], ['-u']);

@xaviapa
Copy link

xaviapa commented May 13, 2022

Yes, can do what you say or also $repo->push(null, ['origin', $branch, '-u']); and it works, but I understand this is a hack as the method signature is public function push($remote = NULL, array $options = NULL).

Previously I was using it like this $repo->push('origin', [$branch, '-u']);. Maybe I was not using it properly and the branch is intended to go in the $remote parameter instead of the $options as you propose?

@mrsad
Copy link

mrsad commented Oct 3, 2022

Created PR to check git version and remove --end-of-options option for git < 2.24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants