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

pkgcheck.base.PkgcheckException: pkgcheck scan: error: failed running git: fatal: ambiguous argument 'origin..HEAD': unknown revision or path not in the working tree. #107

Closed
Flowdalic opened this issue Dec 6, 2022 · 10 comments
Assignees

Comments

@Flowdalic
Copy link
Contributor

Tried my first pkgdev push and it failed with

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pkgcheck/addons/git.py", line 341, in generate_restrictions
    p = subprocess.run(
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'diff-tree', '-r', '--name-only', '-z', 'origin..HEAD']' returned non-zero exit status 128.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.10/pkgdev", line 4, in <module>
    scripts.run(basename(__file__))
  File "/usr/lib/python3.10/site-packages/pkgdev/scripts/__init__.py", line 38, in run
    sys.exit(tool())
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/tool.py", line 79, in __call__
    ret = self.main()
  File "/usr/lib/python3.10/site-packages/pkgdev/cli.py", line 24, in main
    return super().main()
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/tool.py", line 185, in main
    self.handle_exec_exception(e)
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/tool.py", line 170, in main
    exitstatus = func(self.options, self.out, self.err)
  File "/usr/lib/python3.10/site-packages/pkgdev/scripts/pkgdev_push.py", line 49, in _push
    pipe = scan(options.scan_args)
  File "/usr/lib/python3.10/site-packages/pkgcheck/api.py", line 43, in scan
    options = pkgcheck.argparser.parse_args(base_args + ['scan'] + args)
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/arghparse.py", line 1211, in parse_args
    delayed(args, attr)
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/arghparse.py", line 381, in __call__
    self.invokable()
  File "/usr/lib/python3.10/site-packages/pkgcheck/addons/git.py", line 402, in __call__
    namespace.restrictions = self.generate_restrictions(parser, namespace, ref)
  File "/usr/lib/python3.10/site-packages/pkgcheck/addons/git.py", line 349, in generate_restrictions
    parser.error(f'failed running git: {error}')
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/arghparse.py", line 1235, in error
    self.exit(status, '%s: error: %s\n' % (self.prog, message))
  File "/usr/lib/python3.10/site-packages/pkgcheck/api.py", line 35, in parser_exit
    raise PkgcheckException(message.strip())
pkgcheck.base.PkgcheckException: pkgcheck scan: error: failed running git: fatal: ambiguous argument 'origin..HEAD': unknown revision or path not in the working tree.

Currently dealing with a cold, so I did not have the mental capacity to dig into this (but obviously I am fit enough to fill bug reports ;))

@arthurzam
Copy link
Member

First of all, I hope you feel better!

Please give the output of git remove -v in your environment.

Also, a good read is docs which explains some more things. Maybe you need to run git remote set-head origin master? Do note that origin should be the main remote, AKA git@git.gentoo.org/repo/gentoo.git)

@Flowdalic
Copy link
Contributor Author

$ git remote -v
github	https://github.com/gentoo/gentoo.git (fetch)
github	https://github.com/gentoo/gentoo.git (push)
github-gitmig	https://github.com/gentoo/gentoo-gitmig-20150809-draft.git (fetch)
github-gitmig	https://github.com/gentoo/gentoo-gitmig-20150809-draft.git (push)
github-sync-friendly	https://github.com/gentoo-mirror/gentoo.git (fetch)
github-sync-friendly	https://github.com/gentoo-mirror/gentoo.git (push)
historical	https://anongit.gentoo.org/git/repo/gentoo/historical.git (fetch)
historical	https://anongit.gentoo.org/git/repo/gentoo/historical.git (push)
historical-2	https://anongit.gentoo.org/git/archive/repo/gentoo-2.git (fetch)
historical-2	https://anongit.gentoo.org/git/archive/repo/gentoo-2.git (push)
historical-2-github	https://github.com/gentoo/gentoo-historical-2.git (fetch)
historical-2-github	https://github.com/gentoo/gentoo-historical-2.git (push)
my	git@github.com:Flowdalic/gentoo.git (fetch)
my	git@github.com:Flowdalic/gentoo.git (push)
official	git+ssh://git@git.gentoo.org/repo/gentoo.git (fetch)
official	git+ssh://git@git.gentoo.org/repo/gentoo.git (push)
origin	https://github.com/gentoo/gentoo.git (fetch)
origin	ssh://git@git.gentoo.org/repo/gentoo.git (push)

Maybe you need to run git remote set-head origin master?

I think that's already the case, as git push on master pushes to ssh://git@git.gentoo.org/repo/gentoo.git.

@arthurzam
Copy link
Member

Can you check which is the upstream remote for master? It can follow another remote
Also note that I think the correct address should be git+ssh://git@git.gentoo.org/repo/gentoo.git
I see origin has other values then official

@Flowdalic
Copy link
Contributor Author

$ git remote -vv
…
* master                                    ab0612bb2c6c [origin/master] app-emulation/xen: add 4.15.4

so master is tracking origin/master. I've set origins push URL to git+ssh://git@git.gentoo.org/repo/gentoo.git although I am skeptical that it makes any difference. And, in fact, I still get the error

I just noticed that the git command pkgdev constructs is

git diff-tree -r --name-only -z origin..HEAD

shouldn't it be

git diff-tree -r --name-only -z origin/master..HEAD

@ajakk
Copy link

ajakk commented Dec 8, 2022

With such a variety of remotes, I wonder if the cache is getting corrupted in a way similar to pkgcore/pkgcheck#321 where multiple repos of the same name break the cache?

@ajakk
Copy link

ajakk commented Dec 10, 2022

Interesting, I seem to be hitting the same problem when pushing to ::musl (first time using pkgdev to push to ::musl as far as I can remember):

~/gentoo/overlays/musl $ pkgdev push
Current branch master is up to date.
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pkgcheck/addons/git.py", line 341, in generate_restrictions
    p = subprocess.run(
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'diff-tree', '-r', '--name-only', '-z', 'origin..HEAD']' returned non-zero exit status 128.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.10/pkgdev", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.10/site-packages/pkgdev/scripts/__init__.py", line 46, in main
    run(os.path.basename(sys.argv[0]))
  File "/usr/lib/python3.10/site-packages/pkgdev/scripts/__init__.py", line 38, in run
    sys.exit(tool())
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/tool.py", line 79, in __call__
    ret = self.main()
  File "/usr/lib/python3.10/site-packages/pkgdev/cli.py", line 24, in main
    return super().main()
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/tool.py", line 185, in main
    self.handle_exec_exception(e)
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/tool.py", line 170, in main
    exitstatus = func(self.options, self.out, self.err)
  File "/usr/lib/python3.10/site-packages/pkgdev/scripts/pkgdev_push.py", line 55, in _push
    pipe = scan(options.scan_args)
  File "/usr/lib/python3.10/site-packages/pkgcheck/api.py", line 43, in scan
    options = pkgcheck.argparser.parse_args(base_args + ['scan'] + args)
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/arghparse.py", line 1211, in parse_args
    delayed(args, attr)
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/arghparse.py", line 381, in __call__
    self.invokable()
  File "/usr/lib/python3.10/site-packages/pkgcheck/addons/git.py", line 402, in __call__
    namespace.restrictions = self.generate_restrictions(parser, namespace, ref)
  File "/usr/lib/python3.10/site-packages/pkgcheck/addons/git.py", line 349, in generate_restrictions
    parser.error(f'failed running git: {error}')
  File "/usr/lib/python3.10/site-packages/snakeoil/cli/arghparse.py", line 1235, in error
    self.exit(status, '%s: error: %s\n' % (self.prog, message))
  File "/usr/lib/python3.10/site-packages/pkgcheck/api.py", line 35, in parser_exit
    raise PkgcheckException(message.strip())
pkgcheck.base.PkgcheckException: pkgcheck scan: error: failed running git: fatal: ambiguous argument 'origin..HEAD': unknown revision or path not in the working tree.

@jjakob
Copy link

jjakob commented Feb 9, 2023

I had this issue as well. I used 'pkgcheck scan' and 'git push' instead.

@jjakob
Copy link

jjakob commented Jul 18, 2023

$ git remote -vv
…
* master                                    ab0612bb2c6c [origin/master] app-emulation/xen: add 4.15.4

so master is tracking origin/master. I've set origins push URL to git+ssh://git@git.gentoo.org/repo/gentoo.git although I am skeptical that it makes any difference. And, in fact, I still get the error

I just noticed that the git command pkgdev constructs is

git diff-tree -r --name-only -z origin..HEAD

shouldn't it be

git diff-tree -r --name-only -z origin/master..HEAD

In my case origin/master..HEAD also works but origin..HEAD doesn't.
I checked that remote tracking seems to be correct:

# git remote show origin

* remote origin
  Fetch URL: git@github.com:jjakob/gentoo-overlay.git
  Push  URL: git@github.com:jjakob/gentoo-overlay.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

I only have one remote

# git remote -v
origin  git@github.com:jjakob/gentoo-overlay.git (fetch)
origin  git@github.com:jjakob/gentoo-overlay.git (push)

Am checked out on master with one unpushed commit and unstaged changes.


# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
...

@Flowdalic
Copy link
Contributor Author

Flowdalic commented Jul 31, 2023

This may be caused by the remote repository not setting the HEAD reference (i.e., the default branch). This seems to be true for https://github.com/gentoo/gentoo, as git branch -a only shows

  remotes/origin/master

where, for repositories that have a default branch set, it should look like

  remotes/origin/HEAD -> origin/master
  remotes/origin/master

The GitHub documentation on how to set the default branch can be found at https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/changing-the-default-branch

@Flowdalic
Copy link
Contributor Author

Correction, everything seems right with github.com/gentoo/gentoo.

I ran git remote set-head origin -a and set made

remotes/origin/HEAD -> origin/master

appear. Now pkgdev push seems to work. :)

@ajakk Maybe this also solves it for you and ::musl?

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

No branches or pull requests

4 participants