Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix LFS file not stored in LFS when uploaded/edited via API or web UI #34367

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

bytedream
Copy link
Contributor

@bytedream bytedream commented May 4, 2025

Files that should be stored in LFS and are uploaded/edited from the API or web UI aren't stored in LFS. This may be a regression from #34154.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 4, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label May 4, 2025
@bytedream bytedream changed the title Fix file not stored in LFS when uploaded/edited via API or web UI Fix LFS file not stored in LFS when uploaded/edited via API or web UI May 4, 2025
@bytedream
Copy link
Contributor Author

Differences between 1.23.7 and 1.24.0-rc0 / current main. Same repository, lfs works fine when pushed with git on both versions, uploading a file via web UI that is then stored in lfs according to .gitattributes only works in 1.23.7.

.gitattributes
gitattrs

1.23.7 (stored in lfs)
1_23_7

1.24.0-rc0 / current main (not stored in lfs)
1_24_0_rc0

image

@lunny
Copy link
Member

lunny commented May 7, 2025

Take a look at the original implementation. It will read the git worktree rather than a HEAD branch directly. https://github.com/go-gitea/gitea/pull/34154/files#diff-eb96c4920cd1cce828a016dc1acdbf3cd320109a1c6c08f0ec5ac411c57cdc3c

PASSing HEAD will create a new temporory repository if git is lower than 2.40.

@bytedream
Copy link
Contributor Author

I've re-added the option to use --cached and read the attributes from the index (which is present for the bare repo when uploading/editing file in the web UI)

@lunny
Copy link
Member

lunny commented May 7, 2025

I've re-added the option to use --cached and read the attributes from the index (which is present for the bare repo when uploading/editing file in the web UI)

Can we always use --cached if reading from worktree or index?

@bytedream
Copy link
Contributor Author

--cached explicitly reads from the index, so if there are any unstaged changed in the worktree that affect the attributes, --cached won't include those changes in the output.
I only added it for git < 2.40, so that treeish doesn't need to be set to HEAD which would result in the creation of an unnecessary second index.

@lunny lunny added type/bug backport/v1.24 This PR should be backported to Gitea 1.24 labels May 7, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 7, 2025
@@ -107,10 +107,12 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
}

var attributesMap map[string]*attribute.Attributes
if setting.LFS.StartServer {
if setting.LFS.StartServer && hasOldBranch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the hasOldBranch still necessary?

Copy link
Contributor

@wxiaoguang wxiaoguang May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I am sure that we should not check hasOldBranch, because the "upload" should work on an empty repo, which doesn't have "old branch", while some "global gitattributes or info gitattributes" may exist.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v1.24 This PR should be backported to Gitea 1.24 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants