Cannot clone head of PR created by Agit workflow #13783

Closed
opened 2025-11-02 10:53:08 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @Infinoid on GitHub (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

Originally created by @Infinoid on GitHub (Dec 4, 2024). ### Description Apologies if I use bad terminology here; I'm confused. I am using a tool ([atlantis](https://github.com/runatlantis/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](https://docs.gitea.com/usage/agit) 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
GiteaMirror added the type/bug label 2025-11-02 10:53:08 -06:00
Author
Owner

@hiifong commented on GitHub (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'
@hiifong commented on GitHub (Dec 4, 2024): You may want to read the GitHub document "[Checking out pull requests locally](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally)" ![image](https://github.com/user-attachments/assets/70923a79-d52f-40f4-a36e-be071be9ec29) ```shell 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' ```
Author
Owner

@Infinoid commented on GitHub (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!

@Infinoid commented on GitHub (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: ```diff "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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13783