git-php icon indicating copy to clipboard operation
git-php copied to clipboard

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

Open flopana opened this issue 3 years ago • 19 comments

In Commit 5e82d5479da5f16d37a915de4ec55e1ac78de733 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 avatar Apr 22 '22 14:04 flopana

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.

flopana avatar Apr 22 '22 14:04 flopana

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

janpecha avatar Apr 24 '22 12:04 janpecha

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

flopana avatar Apr 24 '22 17:04 flopana

The update has worked perfectly. Thank You!

flopana avatar Apr 25 '22 08:04 flopana

@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

LeoColomb avatar Apr 26 '22 20:04 LeoColomb

@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

flopana avatar Apr 26 '22 20:04 flopana

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

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

janpecha avatar Apr 27 '22 07:04 janpecha

@janpecha I don't pull anything on my side. See my usage here: https://github.com/roots/wordpress-packager/blob/2f1e7ed756bad215c5f1a1c71ca89c59185fb06e/src/Target.php#L68-L82

LeoColomb avatar Apr 27 '22 10:04 LeoColomb

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

janpecha avatar Apr 27 '22 11:04 janpecha

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

https://github.com/czproject/git-php/blob/8a84f699216eb3aae5ee6e05bcd9fb79c9351355/src/GitRepository.php#L474-L485

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?

LeoColomb avatar Apr 27 '22 11:04 LeoColomb

I just changed PHPDoc for this methods - https://github.com/czproject/git-php/commit/24f4e51cc536a723b7838686284d1c21c6de088b#diff-a6f1a39ec7e0b5e21136926e7fa3b9700988e97d15b860a2f6d48a655e2de571. It accepts string[] too.

janpecha avatar Apr 27 '22 12:04 janpecha

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

LeoColomb avatar Apr 27 '22 13:04 LeoColomb

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

zerkms avatar Apr 28 '22 22:04 zerkms

@zerkms Hi, what do you mean?

janpecha avatar Apr 29 '22 06:04 janpecha

~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 avatar Apr 30 '22 05:04 zerkms

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.

zerkms avatar Apr 30 '22 05:04 zerkms

Since 4.0.3 I'm having a problem with the push command. Looks like in https://github.com/czproject/git-php/commit/5e82d5479da5f16d37a915de4ec55e1ac78de733 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

xaviapa avatar May 12 '22 16:05 xaviapa

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

janpecha avatar May 13 '22 05:05 janpecha

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?

xaviapa avatar May 13 '22 07:05 xaviapa

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

mrsad avatar Oct 03 '22 02:10 mrsad