pkgdev icon indicating copy to clipboard operation
pkgdev copied to clipboard

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

Open Flowdalic opened this issue 2 years ago • 5 comments

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 ;))

Flowdalic avatar Dec 06 '22 18:12 Flowdalic

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 [email protected]/repo/gentoo.git)

arthurzam avatar Dec 06 '22 19:12 arthurzam

$ 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	[email protected]:Flowdalic/gentoo.git (fetch)
my	[email protected]:Flowdalic/gentoo.git (push)
official	git+ssh://[email protected]/repo/gentoo.git (fetch)
official	git+ssh://[email protected]/repo/gentoo.git (push)
origin	https://github.com/gentoo/gentoo.git (fetch)
origin	ssh://[email protected]/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://[email protected]/repo/gentoo.git.

Flowdalic avatar Dec 07 '22 13:12 Flowdalic

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://[email protected]/repo/gentoo.git I see origin has other values then official

arthurzam avatar Dec 07 '22 13:12 arthurzam

$ 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://[email protected]/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

Flowdalic avatar Dec 07 '22 17:12 Flowdalic

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

ajakk avatar Dec 08 '22 03:12 ajakk

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.

ajakk avatar Dec 10 '22 03:12 ajakk

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

jjakob avatar Feb 09 '23 07:02 jjakob

$ 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://[email protected]/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: [email protected]:jjakob/gentoo-overlay.git
  Push  URL: [email protected]: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  [email protected]:jjakob/gentoo-overlay.git (fetch)
origin  [email protected]: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:
...

jjakob avatar Jul 18 '23 08:07 jjakob

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 avatar Jul 31 '23 08:07 Flowdalic

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?

Flowdalic avatar Jul 31 '23 09:07 Flowdalic