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

Cannot clone head of PR created by Agit workflow #32714

Closed
Infinoid opened this issue Dec 4, 2024 · 2 comments
Closed

Cannot clone head of PR created by Agit workflow #32714

Infinoid opened this issue Dec 4, 2024 · 2 comments
Labels

Comments

@Infinoid
Copy link
Contributor

Infinoid commented Dec 4, 2024

Description

Apologies if I use bad terminology here; I'm confused.

I am using a tool (atlantis) which tries to clone a PR and do some local work. This usually works, but fails to clone PRs that were created using the Agit workflow.

I created a PR as follows:

% git push origin HEAD:refs/for/main -o topic="agit-test" -o title="Test agit workflow"
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 64 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 530 bytes | 530.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: 
remote: Create a new pull request for 'infinoid/agit-test':
remote:   https://gitea.server/tf/repo/pulls/8
remote: 
remote: . Processing 1 references
remote: Processed 1 references in total
To https://gitea.server/tf/repo
 * [new reference]   HEAD -> refs/pull/8/head

The tool got a webhook notification, saw the new PR and tried to clone it. That failed:

running git clone --depth=1 --branch refs/pull/8/head --single-branch https://atlantis:<redacted>@gitea.server/tf/repo.git /atlantis-data/repos/tf/repo/8/default
Cloning into '/atlantis-data/repos/tf/repo/8/default'...
warning: Could not find remote branch refs/pull/8/head to clone.
fatal: Remote branch refs/pull/8/head not found in upstream origin
: exit status 128

What is the right git clone command to clone an Agit PR? The above command didn't work, and the AGit documentation doesn't have any specific details about cloning.

Apparently the PR head ref is not visible to clients. Is this expected? The Agit workflow seems quite magical, so I don't really understand it. My best guess is that the staging branch was created under a fork with a different owner (infinoid/, not tf/), but it's not outwardly visible, or if it is, the webhook doesn't point at the right location, or the tool misunderstood the webhook data somehow.

The gist link has container logs, and the json webhook content that was sent to the tool.

Thanks!

Gitea Version

1.22.4

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/Infinoid/2c81d377645ef39a7b878804c315e621

Screenshots

No response

Git Version

No response

Operating System

Linux

How are you running Gitea?

self-hosted container

Database

PostgreSQL

@hiifong
Copy link
Member

hiifong commented Dec 4, 2024

You may want to read the GitHub document "Checking out pull requests locally"

image

hiifong@rock-5b:~/workspace$ git clone http://192.168.5.112:3000/test/Test.git
Cloning into 'Test'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (8/8), done.
Resolving deltas: 100% (1/1), done.
hiifong@rock-5b:~/workspace$ cd Test/
hiifong@rock-5b:~/workspace/Test$ ls
LICENSE  README.md
hiifong@rock-5b:~/workspace/Test$ git fetch origin pull/1/head:agit-test
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 243 bytes | 121.00 KiB/s, done.
From http://192.168.5.112:3000/test/Test
 * [new ref]         refs/pull/1/head -> agit-test
hiifong@rock-5b:~/workspace/Test$ git checkout agit-test
Switched to branch 'agit-test'

@Infinoid
Copy link
Contributor Author

Infinoid commented Dec 4, 2024

The "git fetch" syntax does work, thanks for pointing it out.

When I make an Agit PR (number 9 in this repo) and a normal PR (with branch name pr-test), and diff the two webhooks, I see:

     "head": {
-      "label": "",
-      "ref": "refs/pull/9/head",
+      "label": "pr-test",
+      "ref": "pr-test",

So that explains why the tool works for normal PRs; it was using a branch name, not the PR ref.

I'll follow up with the tool authors, thanks!

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

2 participants