"Push and create" doesn't work with SHA-256 git repository #14189

Open
opened 2025-11-02 11:05:48 -06:00 by GiteaMirror · 11 comments
Owner

Originally created by @jhanmann on GitHub (Feb 25, 2025).

Description

When you create a SHA-256 Repository on one Gitea instance and try to setup a Push Mirror to another Gitea instance you must first create the blank repository on the target mirror with SHA-256. It appears Gitea does not know to set SHA-256 for the target repo when creating it using the ENABLE_PUSH_CREATE_USER or ENABLE_PUSH_CREATE_ORG options.

Admittedly this is only an inconvenience but noting it here as a bug/improvement with SHA-256 Git support now official.

Gitea Version

1.24.0+dev-314-g62389dd08b

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Alpine Linux and Debian

How are you running Gitea?

Server instances are running in Docker containers.

Database

MySQL/MariaDB

Originally created by @jhanmann on GitHub (Feb 25, 2025). ### Description When you create a SHA-256 Repository on one Gitea instance and try to setup a Push Mirror to another Gitea instance you must first create the blank repository on the target mirror with SHA-256. It appears Gitea does not know to set SHA-256 for the target repo when creating it using the ENABLE_PUSH_CREATE_USER or ENABLE_PUSH_CREATE_ORG options. Admittedly this is only an inconvenience but noting it here as a bug/improvement with SHA-256 Git support now official. ### Gitea Version 1.24.0+dev-314-g62389dd08b ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System Alpine Linux and Debian ### How are you running Gitea? Server instances are running in Docker containers. ### Database MySQL/MariaDB
GiteaMirror added the type/bug label 2025-11-02 11:05:48 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Feb 25, 2025):

At the moment, it's impossible to support sha256 "push-to-create".

Because IIRC when Gitea receives the push request (to create), it can't know whether it is a sha1 or sha256 repo.

One possible solution is to let users provide more options to the "push" command, for example: git push -o format=sha256 .... Does it look good to you? (This is only a proposal, it is not implemented yet)

@wxiaoguang commented on GitHub (Feb 25, 2025): At the moment, it's impossible to support sha256 "push-to-create". Because IIRC when Gitea receives the push request (to create), it can't know whether it is a sha1 or sha256 repo. One possible solution is to let users provide more options to the "push" command, for example: `git push -o format=sha256 ...`. Does it look good to you? (This is only a proposal, it is not implemented yet)
Author
Owner

@jhanmann commented on GitHub (Feb 27, 2025):

Hmmm. I think you're saying the Gitea instance on the target does not know the SHA type, correct? So yes, I think any means of the source telling the destination what SHA type is used in the source would be a solution. Not having looked at the Gitea code for the Push Mirror I can't comment in more detail on what the potential solutions would be.

The source Gitea instance definitely knows the SHA type it simply needs to be able to tell the mirror destination Gitea instance.

@jhanmann commented on GitHub (Feb 27, 2025): Hmmm. I think you're saying the Gitea instance on the target does not know the SHA type, correct? So yes, I think any means of the source telling the destination what SHA type is used in the source would be a solution. Not having looked at the Gitea code for the Push Mirror I can't comment in more detail on what the potential solutions would be. The source Gitea instance definitely knows the SHA type it simply needs to be able to tell the mirror destination Gitea instance.
Author
Owner

@wxiaoguang commented on GitHub (Feb 27, 2025):

Hmmm. I think you're saying the Gitea instance on the target does not know the SHA type, correct?

yes, "target instance" (the one receives the push request) doesn't know. When "push-to-create", the "target instance" only knows the repo name and push options before creating an empty repo.

@wxiaoguang commented on GitHub (Feb 27, 2025): > Hmmm. I think you're saying the Gitea instance on the target does not know the SHA type, correct? yes, "target instance" (the one receives the push request) doesn't know. When "push-to-create", the "target instance" only knows the repo name and push options before creating an empty repo.
Author
Owner

@jhanmann commented on GitHub (Feb 27, 2025):

Gotcha! So yes I'd agree that the additional piece of information that needs to be represented is SHA-1 or SHA-256 just like the --ojhect-format= option on the GIT INIT.

This obviously isn't your fault at all but after all the time they took implementing this in GIT it still seems only half thought out but then again what do I know about it? Just another armchair critic. ;-)

@jhanmann commented on GitHub (Feb 27, 2025): Gotcha! So yes I'd agree that the additional piece of information that needs to be represented is SHA-1 or SHA-256 just like the --ojhect-format= option on the GIT INIT. This obviously isn't your fault at all but after all the time they took implementing this in GIT it still seems only half thought out but then again what do I know about it? Just another armchair critic. ;-)
Author
Owner

@hiifong commented on GitHub (Mar 19, 2025):

When we enable push to create repositories automatically, perhaps we can determine whether to use sha265 to create a repository by determining the length of the commit id.

sha256 log

21:39:24.190150 git.c:463               trace: built-in: git push origin master
21:39:24.190603 run-command.c:659       trace: run_command: unset GIT_PREFIX; ssh git@gitea.com 'git-receive-pack '\''hiifong/test-sha256.git'\'''
21:39:26.423026 pkt-line.c:85           packet:         push< 83611bbecc0b34d66dc60aaa92ae9d242e3a5ac28c9ce187aea430ceadef8d31 refs/heads/master\0report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta push-options object-format=sha256 agent=git/2.43.5
21:39:26.423866 pkt-line.c:85           packet:         push< 0000
21:39:26.424122 pkt-line.c:85           packet:         push> 83611bbecc0b34d66dc60aaa92ae9d242e3a5ac28c9ce187aea430ceadef8d31 a8b5561fd308c0ca101062736c3106f6191f225a630f88263a6c3fac3ead75fa refs/heads/master\0 report-status-v2 side-band-64k object-format=sha256 agent=git/2.43.0
21:39:26.424146 pkt-line.c:85           packet:         push> 0000
21:39:26.424247 run-command.c:659       trace: run_command: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress
21:39:26.426318 git.c:463               trace: built-in: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
21:39:26.860242 pkt-line.c:85           packet:     sideband< \1000eunpack ok0019ok refs/heads/master0000
21:39:26.860497 pkt-line.c:85           packet:         push< unpack ok
21:39:26.860582 pkt-line.c:85           packet:         push< ok refs/heads/master
21:39:26.860593 pkt-line.c:85           packet:         push< 0000
21:39:26.980279 pkt-line.c:85           packet:     sideband< \2. Processing 1 referencesProcessed 1 references in total
remote: . Processing 1 references
remote: Processed 1 references in total
21:39:26.988321 pkt-line.c:85           packet:     sideband< 0000
To gitea.com:hiifong/test-sha256.git
   83611bb..a8b5561  master -> master

Image

@hiifong commented on GitHub (Mar 19, 2025): ~~When we enable push to create repositories automatically, perhaps we can determine whether to use sha265 to create a repository by determining the length of the commit id.~~ **sha256 log** ```log 21:39:24.190150 git.c:463 trace: built-in: git push origin master 21:39:24.190603 run-command.c:659 trace: run_command: unset GIT_PREFIX; ssh git@gitea.com 'git-receive-pack '\''hiifong/test-sha256.git'\''' 21:39:26.423026 pkt-line.c:85 packet: push< 83611bbecc0b34d66dc60aaa92ae9d242e3a5ac28c9ce187aea430ceadef8d31 refs/heads/master\0report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta push-options object-format=sha256 agent=git/2.43.5 21:39:26.423866 pkt-line.c:85 packet: push< 0000 21:39:26.424122 pkt-line.c:85 packet: push> 83611bbecc0b34d66dc60aaa92ae9d242e3a5ac28c9ce187aea430ceadef8d31 a8b5561fd308c0ca101062736c3106f6191f225a630f88263a6c3fac3ead75fa refs/heads/master\0 report-status-v2 side-band-64k object-format=sha256 agent=git/2.43.0 21:39:26.424146 pkt-line.c:85 packet: push> 0000 21:39:26.424247 run-command.c:659 trace: run_command: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress 21:39:26.426318 git.c:463 trace: built-in: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 21:39:26.860242 pkt-line.c:85 packet: sideband< \1000eunpack ok0019ok refs/heads/master0000 21:39:26.860497 pkt-line.c:85 packet: push< unpack ok 21:39:26.860582 pkt-line.c:85 packet: push< ok refs/heads/master 21:39:26.860593 pkt-line.c:85 packet: push< 0000 21:39:26.980279 pkt-line.c:85 packet: sideband< \2. Processing 1 referencesProcessed 1 references in total remote: . Processing 1 references remote: Processed 1 references in total 21:39:26.988321 pkt-line.c:85 packet: sideband< 0000 To gitea.com:hiifong/test-sha256.git 83611bb..a8b5561 master -> master ``` ![Image](https://github.com/user-attachments/assets/f89672eb-d21a-48cf-ae05-716341c6ff52)
Author
Owner

@hiifong commented on GitHub (Mar 19, 2025):

there has object format:

Image

@hiifong commented on GitHub (Mar 19, 2025): there has object format: ![Image](https://github.com/user-attachments/assets/b114d35a-49cb-401b-9a50-01cd423a0d9d)
Author
Owner

@hiifong commented on GitHub (Mar 19, 2025):

Sorry, this idea doesn't work. You can only know which algorithm the object format supports after initializing the repository.

@hiifong commented on GitHub (Mar 19, 2025): Sorry, this idea doesn't work. You can only know which algorithm the object format supports after initializing the repository.
Author
Owner

@lunny commented on GitHub (Mar 19, 2025):

Another method is to detect the commit id length. When the hooks get the commit id is 64, then we think it's a sha256, if it's 40, it should be sha1.

@lunny commented on GitHub (Mar 19, 2025): Another method is to detect the commit id length. When the hooks get the commit id is 64, then we think it's a sha256, if it's 40, it should be sha1.
Author
Owner

@hiifong commented on GitHub (Mar 20, 2025):

no, this idea is not feasible, gitea initializes the git repository as sha1 by default, this algorithm is already set, it is impossible to change it during the receiving process.

@hiifong commented on GitHub (Mar 20, 2025): no, this idea is not feasible, gitea initializes the git repository as sha1 by default, this algorithm is already set, it is impossible to change it during the receiving process.
Author
Owner

@Salvora commented on GitHub (Jun 27, 2025):

When I use "push to create" with a local sha256 repo, it creates a blank repo on the remote gitea instance. Isn't it possible to use this?

@Salvora commented on GitHub (Jun 27, 2025): When I use "push to create" with a local sha256 repo, it creates a blank repo on the remote gitea instance. Isn't it possible to use this?
Author
Owner

@wxiaoguang commented on GitHub (Jun 27, 2025):

Impossible for sha256 https://github.com/go-gitea/gitea/issues/33717#issuecomment-2682737737

@wxiaoguang commented on GitHub (Jun 27, 2025): Impossible for sha256 https://github.com/go-gitea/gitea/issues/33717#issuecomment-2682737737
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#14189