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

Inherit submodules from template repository content #16237

Merged
merged 25 commits into from
Jan 1, 2025

Conversation

sschroe
Copy link
Contributor

@sschroe sschroe commented Jun 23, 2021

This PR addresses issue #10316 and makes submodules available in repositories created from templates.
Submodules are now inherited when creating a new repository from a template with "Git Content" checked,

Unlike the initial suggestion provided by @davidsvantesson in the original issue i decided not to use git submodule status initially because its output can look like this:

 0dff7e5493898954537202c0c975f7b1c55d0845 lib (no%_()delay)1 (heads/master)

Submodule names can contain all sorts of special characters and the (heads/master) part is not always present in the output which makes reliably parsing the name out of this quite a pain if not impossible. I replaced this step with git config -f .gitmodules --list --name-only which will give:

submodule.lib (no%_()delay)1.path
submodule.lib (no%_()delay)1.url

This is far easier to parse and provides the necessary submodule name. git submodule status lib (no%_()delay)1 is then used as second step to get the commit hash which is now easily parsed as well as there is only a single line of output.

These steps happen in the getSubmodules function and are the largest part of the change. This function does not throw any errors but will just skip broken submodules so that a template with a malformed .gitmodules file can still be used.

To re add the submodules i use git update-index --add --cacheinfo 160000 0dff7e5493898954537202c0c975f7b1c55d0845 lib (no%_()delay)1 instead of the regular git submodule add .... Updating the index directly skips cloning the submodule which is far faster and entirely avoids the problem of users adding excessively large submodules to possibly DoS attack the Gitea server. It also avoids the issue where a submodule repository might not be accessible by the Gitea server due to authentication/permissions or other reasons such as absolute local file paths being used.

@6543 6543 added this to the 1.16.0 milestone Jun 23, 2021
@6543 6543 added the type/enhancement An improvement of existing functionality label Jun 23, 2021
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 23, 2021
@6543
Copy link
Member

6543 commented Jun 24, 2021

@sschroe If you dont force-push and not swash, it's simpler to review and see made changes ...

... wills will be squash-merged if accepted anyways

modules/git/submodule.go Outdated Show resolved Hide resolved
modules/git/submodule.go Outdated Show resolved Hide resolved
modules/git/submodule.go Outdated Show resolved Hide resolved
modules/git/submodule.go Outdated Show resolved Hide resolved
Signed-off-by: Steffen Schröter <[email protected]>
@6543
Copy link
Member

6543 commented Jun 24, 2021

@sschroe avter #16243 got merged you dont need to rename import :)

and I think it should be more log.Debug sorry for writing log.Info first ...

@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@1f05417). Click here to learn what that means.
The diff coverage is 70.42%.

@@           Coverage Diff           @@
##             main   #16237   +/-   ##
=======================================
  Coverage        ?   47.42%           
=======================================
  Files           ?      951           
  Lines           ?   132431           
  Branches        ?        0           
=======================================
  Hits            ?    62801           
  Misses          ?    62071           
  Partials        ?     7559           
Impacted Files Coverage Δ
modules/repository/generate.go 29.85% <40.00%> (ø)
modules/git/submodule.go 74.62% <72.72%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1f05417...a467a2b. Read the comment docs.

@sschroe
Copy link
Contributor Author

sschroe commented Jun 30, 2021

@6543 all changes should be implemented so far. Just for the pipelines i need a little more info, is it enough to change the command to use RunInDirPipeline or is there more to that?

@6543
Copy link
Member

6543 commented Jun 30, 2021

Signed-off-by: Steffen Schröter <[email protected]>
@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 Jul 6, 2021
@techknowlogick techknowlogick modified the milestones: 1.16.0, 1.17.0 Nov 23, 2021
modules/git/submodule.go Outdated Show resolved Hide resolved
@sschroe
Copy link
Contributor Author

sschroe commented Mar 3, 2022

Any other input or changes needed here to proceed?

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 31, 2024
@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 Dec 31, 2024
@wxiaoguang
Copy link
Contributor

Ok will do so (and try to resolve conflichts ... next week :) )

Maybe we could get it in Jan 1 2025

@wxiaoguang wxiaoguang enabled auto-merge (squash) December 31, 2024 15:18
@wxiaoguang wxiaoguang disabled auto-merge December 31, 2024 15:22
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Dec 31, 2024
@wxiaoguang wxiaoguang added the backport/v1.23 This PR should be backported to Gitea 1.23 label Dec 31, 2024
@wxiaoguang wxiaoguang enabled auto-merge (squash) January 1, 2025 02:15
@wxiaoguang wxiaoguang merged commit 57eb9d0 into go-gitea:main Jan 1, 2025
26 checks passed
wxiaoguang pushed a commit to wxiaoguang/gitea that referenced this pull request Jan 1, 2025
@wxiaoguang wxiaoguang added backport/done All backports for this PR have been created backport/manual No power to the bots! Create your backport yourself! labels Jan 1, 2025
wxiaoguang added a commit that referenced this pull request Jan 2, 2025
Backport #16237 (it more likely a bug fix)

Co-authored-by: Steffen Schröter <[email protected]>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 2, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  unset XDG_HOME_CONFIG as gitea manages configuration locations (go-gitea#33067)
  Refactor repo-new.ts (go-gitea#33070)
  Refactor pull-request compare&create page (go-gitea#33071)
  feat: link to nuget dependencies (go-gitea#26554)
  Remove some unnecessary template helpers (go-gitea#33069)
  Inherit submodules from template repository content (go-gitea#16237)
  [skip ci] Updated translations via Crowdin
  feat(action): issue change title notifications (go-gitea#33050)
  Use project's redirect url instead of composing url (go-gitea#33058)
  Fix unittest and repo create bug (go-gitea#33061)
  Fix locale type (go-gitea#33059)
  Refactor maven package registry (go-gitea#33049)
  Optimize the installation page (go-gitea#32994)
  [Feature] Private README.md for organization (go-gitea#32872)
  Make issue suggestion work for new PR page (go-gitea#33035)
  Add IntelliJ Gateway's .uuid to gitignore (go-gitea#33052)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/done All backports for this PR have been created backport/manual No power to the bots! Create your backport yourself! backport/v1.23 This PR should be backported to Gitea 1.23 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 modifies/templates This PR modifies the template files size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/enhancement An improvement of existing functionality
Projects
None yet
7 participants