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

Don't automatically delete repository files if they are present #12409

Closed
wants to merge 18 commits into from

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Aug 2, 2020

Prior to this PR Gitea would delete any repository files if they are
present during creation or migration. This can in certain circumstances
lead to data-loss and is slightly unpleasant.

This PR provides a mechanism for Gitea to adopt repositories on creation
and otherwise requires an explicit flag for deletion.

PushCreate is slightly different - the create will cause adoption if
that is allowed otherwise it will delete the data if that is allowed.

Signed-off-by: Andrew Thornton art27@cantab.net

Prior to this PR Gitea would delete any repository files if they are
present during creation or migration. This can in certain circumstances
lead to data-loss and is slightly unpleasant.

This PR provides a mechanism for Gitea to adopt repositories on creation
and otherwise requires an explicit flag for deletion.

PushCreate is slightly different - the create will cause adoption if
that is allowed otherwise it will delete the data if that is allowed.

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Aug 2, 2020
@zeripath zeripath added this to the 1.13.0 milestone Aug 2, 2020
Signed-off-by: Andrew Thornton <art27@cantab.net>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 3, 2020
Signed-off-by: Andrew Thornton <art27@cantab.net>
@lunny
Copy link
Member

lunny commented Aug 4, 2020

How about not give the option to overwrite the exist repository and just returned error?

Only offer to adopt or overwrite if the user can do that.

Allow the site administrator to adopt or overwrite in all
circumstances

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

zeripath commented Aug 4, 2020

OK I've gone one step further - the adopt or overwrite option is only displayed if it is permitted for that user. Otherwise just the error is returned. The site admin can always adopt or overwrite.

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2020

Codecov Report

Merging #12409 into master will decrease coverage by 0.04%.
The diff coverage is 41.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12409      +/-   ##
==========================================
- Coverage   43.07%   43.02%   -0.05%     
==========================================
  Files         658      658              
  Lines       72454    72591     +137     
==========================================
+ Hits        31211    31234      +23     
- Misses      36186    36295     +109     
- Partials     5057     5062       +5     
Impacted Files Coverage Δ
models/error.go 34.51% <0.00%> (-0.30%) ⬇️
models/repo_generate.go 12.50% <ø> (ø)
modules/auth/repo_form.go 42.34% <ø> (ø)
modules/migrations/gitea.go 6.86% <0.00%> (-0.02%) ⬇️
modules/repository/generate.go 0.00% <0.00%> (ø)
modules/structs/repo.go 50.00% <ø> (ø)
routers/repo/setting.go 14.67% <0.00%> (-0.29%) ⬇️
services/repository/generate.go 0.00% <0.00%> (ø)
modules/repository/fork.go 47.61% <6.66%> (-12.39%) ⬇️
modules/repository/init.go 50.95% <11.11%> (-8.00%) ⬇️
... and 14 more

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 f215e01...74831a7. Read the comment docs.

Signed-off-by: Andrew Thornton <art27@cantab.net>
@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 Sep 6, 2020
models/repo.go Show resolved Hide resolved
@lafriks
Copy link
Member

lafriks commented Sep 16, 2020

Please resolve conflicts

@6543
Copy link
Member

6543 commented Sep 17, 2020

swagger lint

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

OK Swagger just needs to be run as part of our generate. Why aren't we doing that?

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

zeripath commented Sep 17, 2020

I'm serious - I don't understand why the swagger generate can't be done on generate. We can ensure that we generate a valid swagger description as part of lint - but AFAICS there is no good reason to have it in master.

@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 Sep 17, 2020
IsPrivate: opts.Private,
IsMirror: opts.Mirror,
Status: models.RepositoryBeingMigrated,
OverwritePreExisting: opts.OverwritePreExisting && (g.doer.IsAdmin || setting.Repository.AllowOverwriteOfUnadoptedRepositories),
Copy link
Member

Choose a reason for hiding this comment

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

Why an admin could not follow the setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

? This allows Site Admins to explicitly overwrite pre-existing repositories.

@lunny
Copy link
Member

lunny commented Sep 18, 2020

I don't like this PR now because I think it makes the process more complicated. Maybe we should add a new feature which is only a button adopt projects, then it will scan all the repositories root folder and automatically check if it exists on the database, if not then create it. If it's scanning, the button could not be clicked. Of course, the button should be in admin panel.

For this PR we can just return the error if the repository folder exists.

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

Any UI that involves adopting repositories is going to have to provide the information like:

  • Visibility
  • Description
  • Issue labels
  • Default branch

it's then going to require a UI to search to find repositories to adopt / overwrite.

@lunny
Copy link
Member

lunny commented Sep 19, 2020

You can change them after adopting them. Then you have resued the previous UI and features. And also this will resolve batching adopt projects feature.

Copy link
Member

@6543 6543 left a comment

Choose a reason for hiding this comment

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

lunny's suggestion sounds resonable

@zeripath zeripath mentioned this pull request Sep 21, 2020
@jolheiser
Copy link
Member

Under the context that this is primarily intended to stop unnecessary data loss (adoption/overwriting being a secondary effect of that), I think this PR is great.

I think the code it introduces could be used in a later PR to allow for batch adoption of repositories on disk.

Copy link
Member

@6543 6543 left a comment

Choose a reason for hiding this comment

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

this is nice now :)

@zeripath zeripath closed this Sep 24, 2020
@zeripath zeripath deleted the adopt-repositories branch September 25, 2020 17:01
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants