Skip to content

Delete local branch when repo branch is deleted #6497

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

Merged
merged 6 commits into from
Apr 8, 2019

Conversation

jolheiser
Copy link
Member

Fixes #6490

Currently, when creating a branch from the web UI (not a commit, directly from the branch dropdown), Gitea creates the branch in its local cache and pushes it to the real repo.

When the branch is deleted, it was not being deleted from the local cache and if a branch of the same name is created, Gitea panics because the local repo already has a branch with that name.

Since the Gitea's tmp directory is deleted on startup, the only (current) way to clear the local repo cache is to restart Gitea.

@codecov-io
Copy link

codecov-io commented Apr 2, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@49b2f45). Click here to learn what that means.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #6497   +/-   ##
=========================================
  Coverage          ?   40.41%           
=========================================
  Files             ?      404           
  Lines             ?    54140           
  Branches          ?        0           
=========================================
  Hits              ?    21883           
  Misses            ?    29240           
  Partials          ?     3017
Impacted Files Coverage Δ
routers/repo/branch.go 56.9% <0%> (ø)
models/repo_branch.go 54.97% <30%> (ø)

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 49b2f45...c569312. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 2, 2019
Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

The local cache needs to go. Do we even need it still?

I cannot believe that we're actually requiring a full clone to just do a branch creation - particularly a full clone we keep around.

Can't we follow the technique in

https://github.com/go-gitea/gitea/blob/master/modules/uploader/update.go

Where we just do a thin clone, create an index from the appropriate old branch and then push it as the new branch. We probably don't even need an index - We could just push our HEAD to the new branch.

In fact I wouldn't be surprised if we couldn't just do a push from an empty place to create a new branch. Would have to look at the documentation for git push.

A branch is simply a file with a hash to a tree object. It's nothing magical. The only benefit with pushing is that you make sure hooks etc will run.

@jolheiser
Copy link
Member Author

jolheiser commented Apr 2, 2019

If I do follow how the uploader does it, should I take that code and put it somewhere else (perhaps a new module, or in util) that can be re-used when we need to make a "temp" repo that gets cleaned up after use?

I could just use the existing code, but it would seem odd to use the uploader package when referencing temp repos.

Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

I'm gonna approve as this is a bug fix, but I'm gonna look at removing this unnecessary cloning from the codebase.

@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 Apr 3, 2019
@lafriks lafriks added this to the 1.9.0 milestone Apr 4, 2019
@zeripath
Copy link
Contributor

zeripath commented Apr 6, 2019

Take a look at: #6505

@ngourdon
Copy link
Contributor

ngourdon commented Apr 6, 2019

@zeripath Even if it's out of scope of this PR, yes you can push a new branch without checking it out.

The form of the git push command which will permit to do so is
git push <repository> <refspec>
repository can be a name like "origin" but may also be a path like "/path/to/gitea-repositories/username/repo.git".

From the directory of the gitea bare repository (/path/to/gitea-repositories/username/repo.git) you can do
git push . refs/heads/existing-branch:refs/heads/new-branch
or from a sha1
git push . sha1:refs/heads/new-branch

This will trigger git hooks

@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 Apr 6, 2019
@lafriks lafriks merged commit aa02463 into go-gitea:master Apr 8, 2019
@jolheiser jolheiser deleted the 6490_delete_local_branch branch April 8, 2019 15:00
@jolheiser
Copy link
Member Author

@zeripath Once your PR is merged I will look at submitting a new PR implementing those changes in this area. (Unless your PR just removes these changes as part of the conversion)

@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/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error 500 when recreating a deleted branch
7 participants