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

cz check range sometimes failed in GitLab CI #593

Open
SsuperL opened this issue Sep 21, 2022 · 25 comments
Open

cz check range sometimes failed in GitLab CI #593

SsuperL opened this issue Sep 21, 2022 · 25 comments

Comments

@SsuperL
Copy link

SsuperL commented Sep 21, 2022

Description

Runcz check --range origin/master..HEAD to check commits in CI occasionally fails.
And it worked after I retried the job.But sometimes it didn't work after retrying multiple times.
I couldn't find out the reason ,

Steps to reproduce

lint:
retry: 1
script:
- cz version
- cz check --rev-range origin/master..HEAD

Current behavior

cz check --rev-range origin/master..HEAD failed. Outputs attached below:

  fatal: ambiguous argument 'master..HEAD': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

Desired behavior

cz check --rev-range can run successfully in gitlab CI.

Screenshots

image

Environment

commitizen version: 2.34.0
python version: 3.7.5
operating system: Linux

@Lee-W
Copy link
Member

Lee-W commented Sep 22, 2022

Is it possible that the git repo doesn't setup remote 🤔

@SsuperL
Copy link
Author

SsuperL commented Sep 23, 2022

I run command git remote -v in the CI , and it shows that the remote has been setup.

@SsuperL
Copy link
Author

SsuperL commented Sep 23, 2022

image

@Lee-W
Copy link
Member

Lee-W commented Sep 23, 2022

Hmmm... As I'm not able to reproduce it, I don't have any clue on how we could fix it. But we can keep it open till you or someone encounter this issue again with more detail

@SsuperL
Copy link
Author

SsuperL commented Sep 25, 2022

Actually,this issue has come up again.

@SsuperL
Copy link
Author

SsuperL commented Sep 26, 2022

image
And when I merged the branch into master,it said that there is no commit found range origin/master..HEAD.

@Lee-W
Copy link
Member

Lee-W commented Sep 26, 2022

Do you mean after merging back to the master branch? If that's the case, your HEAD will on on master so the result seem to be expected.

@SsuperL
Copy link
Author

SsuperL commented Sep 27, 2022

Do you mean after merging back to the master branch? If that's the case, your HEAD will on on master so the result seem to be expected.

yes. Or can it skip check when there's no commit rather than make the job failed?

image

@Lee-W
Copy link
Member

Lee-W commented Oct 3, 2022

@SsuperL Please try cz --no-raise 3 check --rev-range master... it's output the message with a zero return code

https://commitizen-tools.github.io/commitizen/bump/#easy-way

@SsuperL
Copy link
Author

SsuperL commented Oct 9, 2022

cz --no-raise 3 check --rev-range master..

I'll try it.Thank you!

@Lujeni
Copy link

Lujeni commented Oct 19, 2022

@SsuperL did you try to git fetch before your command ? its seems GitLab CI dont fetch every branch

@SsuperL
Copy link
Author

SsuperL commented Oct 24, 2022

@SsuperL did you try to git fetch before your command ? its seems GitLab CI dont fetch every branch
No, but it only appeared on some machines. And the command git branch -r shows branch origin/master exists.

@SsuperL
Copy link
Author

SsuperL commented Nov 29, 2022

image

@Lee-W
Copy link
Member

Lee-W commented Nov 29, 2022

do you have remote origin and branch master?

@SsuperL
Copy link
Author

SsuperL commented Dec 1, 2022

do you have remote origin and branch master?

yes.

@Lee-W
Copy link
Member

Lee-W commented Dec 3, 2022

What would be the output of git log origin/master..? Can it generate output as expected?

@SsuperL
Copy link
Author

SsuperL commented Dec 5, 2022

What would be the output of git log origin/master..? Can it generate output as expected?

Oh,it didn't show anything of git log origin/master. Maybe there's no git fetch on some CI machines. I try git fetch origin and it works. Thanks for your help!

@Lee-W
Copy link
Member

Lee-W commented Dec 19, 2022

@SsuperL One of the stuff I can think of is shallow clone. Maybe you could take a look at this direction as well :)

@SsuperL
Copy link
Author

SsuperL commented Dec 20, 2022

@SsuperL One of the stuff I can think of is shallow clone. Maybe you could take a look at this direction as well :)

Okay, I'll check it out.

@baggiponte
Copy link

Hi, I am having the same issue outside of CI. When I git push with the pre-push pre-commit hook, I get the following:

fatal: ambiguous argument 'origin/HEAD..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Whereas if I skip the verification everything works fine.

Unfortunately the repo is private and I can't share the url, but the configs are:

default_install_hook_types:
  - pre-commit
  - pre-push
default_language_version:
  python: python3.9
repos:
  - repo: https://github.com/commitizen-tools/commitizen
    rev: v2.42.1
    hooks:
      - id: commitizen-branch
        stages: [ push ]

And the hook (which should not matter) is:

#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON=/Users/lucabaggi/.local/share/pipx/venvs/pre-commit/bin/python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-push)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi

@SsuperL
Copy link
Author

SsuperL commented Mar 23, 2023

Hi, I am having the same issue outside of CI. When I git push with the pre-push pre-commit hook, I get the following:

fatal: ambiguous argument 'origin/HEAD..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Whereas if I skip the verification everything works fine.

Unfortunately the repo is private and I can't share the url, but the configs are:

default_install_hook_types:
  - pre-commit
  - pre-push
default_language_version:
  python: python3.9
repos:
  - repo: https://github.com/commitizen-tools/commitizen
    rev: v2.42.1
    hooks:
      - id: commitizen-branch
        stages: [ push ]

And the hook (which should not matter) is:

#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON=/Users/lucabaggi/.local/share/pipx/venvs/pre-commit/bin/python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-push)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi

Have you tried git fetch ? That works for me.

@baggiponte
Copy link

Have you tried git fetch ? That works for me.

Does not for me... Perhaps it can mess up if I have git push --force previously?

@baggiponte
Copy link

Hello, if I run cz check --rev-range origin/main..HEAD it works. I noticed that the pre-commit hook has --rev-range origin/HEAD..HEAD which is an invalid ref. Perhaps when the repo has multiple branches the reference becomes invalid? Will try to make a reprex soon.

rpatterson added a commit to rpatterson/project-structure that referenced this issue Mar 29, 2023
@johanmynhardt
Copy link

johanmynhardt commented Dec 21, 2023

The following fixed it for me:

git remote set-head origin -a

Eventually found a semi-good explanation at: https://learnku.com/articles/71493

(My issue is actually when I'm trying to run git push with the pre-push hook enabled, which then gives a similar error on ambiguity.)

@AdrianDC
Copy link
Contributor

Checking older or related issues to access the tool's status.

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

No branches or pull requests

6 participants