Skip to content

Fix bug when generating repository #34149

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

Closed
wants to merge 1 commit into from

Conversation

lunny
Copy link
Member

@lunny lunny commented Apr 8, 2025

Follow #31035

@lunny lunny added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Apr 8, 2025
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 8, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Apr 8, 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 Apr 8, 2025
@@ -107,7 +107,8 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
}()

// 2 - check whether the repository with the same storage exists
isExist, err := gitrepo.IsRepositoryExist(ctx, generateRepo)
var isExist bool
isExist, err = gitrepo.IsRepositoryExist(ctx, generateRepo)
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think it is a bug

Copy link
Member Author

Choose a reason for hiding this comment

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

line 103 will check if err is nil. Since the directory exist, we need to cleanupReposioty, so that this err should be the returned parameter but not a local variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Show me why


func TestError(t *testing.T) {
	f := func(t *testing.T) (err error) {
		defer func() {
			assert.ErrorContains(t, err, "error")
		}()
		val, err := 1, nil
		_ = val
		_ = err
		assert.NoError(t, err)
		return errors.New("error")
	}
	assert.ErrorContains(t, f(t), "error")
}

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I see. The return will assign the error to the returned parameter err.

@wxiaoguang wxiaoguang marked this pull request as draft April 8, 2025 06:03
@lunny lunny closed this Apr 8, 2025
@lunny lunny deleted the lunny/fix_temp_check branch April 8, 2025 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants