Skip to content

Commit 96faa85

Browse files
authored
Merge branch 'main' into fix-git-client-redirect
2 parents 48cbca7 + c1b9ecc commit 96faa85

File tree

9 files changed

+52
-52
lines changed

9 files changed

+52
-52
lines changed

modules/git/batch.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ type Batch struct {
1414
Writer WriteCloserError
1515
}
1616

17-
func (repo *Repository) NewBatch(ctx context.Context) (*Batch, error) {
17+
// NewBatch creates a new batch for the given repository, the Close must be invoked before release the batch
18+
func NewBatch(ctx context.Context, repoPath string) (*Batch, error) {
1819
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
19-
if err := ensureValidGitRepository(ctx, repo.Path); err != nil {
20+
if err := ensureValidGitRepository(ctx, repoPath); err != nil {
2021
return nil, err
2122
}
2223

2324
var batch Batch
24-
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repo.Path)
25+
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath)
2526
return &batch, nil
2627
}
2728

28-
func (repo *Repository) NewBatchCheck(ctx context.Context) (*Batch, error) {
29+
func NewBatchCheck(ctx context.Context, repoPath string) (*Batch, error) {
2930
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
30-
if err := ensureValidGitRepository(ctx, repo.Path); err != nil {
31+
if err := ensureValidGitRepository(ctx, repoPath); err != nil {
3132
return nil, err
3233
}
3334

3435
var check Batch
35-
check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repo.Path)
36+
check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repoPath)
3637
return &check, nil
3738
}
3839

modules/git/command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ func (c *Command) run(ctx context.Context, skip int, opts *RunOpts) error {
350350
// We need to check if the context is canceled by the program on Windows.
351351
// This is because Windows does not have signal checking when terminating the process.
352352
// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
353+
// `err.Error()` returns "exit status 1" when using the `git check-attr` command after the context is canceled.
353354
if runtime.GOOS == "windows" &&
354355
err != nil &&
355-
err.Error() == "" &&
356+
(err.Error() == "" || err.Error() == "exit status 1") &&
356357
cmd.ProcessState.ExitCode() == 1 &&
357358
ctx.Err() == context.Canceled {
358359
return ctx.Err()

modules/git/repo_base_nogogit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
6767
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
6868
if repo.batch == nil {
6969
var err error
70-
repo.batch, err = repo.NewBatch(ctx)
70+
repo.batch, err = NewBatch(ctx, repo.Path)
7171
if err != nil {
7272
return nil, nil, nil, err
7373
}
@@ -81,7 +81,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bu
8181
}
8282

8383
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
84-
tempBatch, err := repo.NewBatch(ctx)
84+
tempBatch, err := NewBatch(ctx, repo.Path)
8585
if err != nil {
8686
return nil, nil, nil, err
8787
}
@@ -92,7 +92,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bu
9292
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
9393
if repo.check == nil {
9494
var err error
95-
repo.check, err = repo.NewBatchCheck(ctx)
95+
repo.check, err = NewBatchCheck(ctx, repo.Path)
9696
if err != nil {
9797
return nil, nil, nil, err
9898
}
@@ -106,7 +106,7 @@ func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError
106106
}
107107

108108
log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
109-
tempBatchCheck, err := repo.NewBatchCheck(ctx)
109+
tempBatchCheck, err := NewBatchCheck(ctx, repo.Path)
110110
if err != nil {
111111
return nil, nil, nil, err
112112
}

modules/indexer/code/bleve/bleve.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/analyze"
1717
"code.gitea.io/gitea/modules/charset"
1818
"code.gitea.io/gitea/modules/git"
19-
"code.gitea.io/gitea/modules/gitrepo"
2019
"code.gitea.io/gitea/modules/indexer"
2120
path_filter "code.gitea.io/gitea/modules/indexer/code/bleve/token/path"
2221
"code.gitea.io/gitea/modules/indexer/code/internal"
@@ -217,12 +216,7 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository, batch
217216
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
218217
batch := inner_bleve.NewFlushingBatch(b.inner.Indexer, maxBatchSize)
219218
if len(changes.Updates) > 0 {
220-
r, err := gitrepo.OpenRepository(ctx, repo)
221-
if err != nil {
222-
return err
223-
}
224-
defer r.Close()
225-
gitBatch, err := r.NewBatch(ctx)
219+
gitBatch, err := git.NewBatch(ctx, repo.RepoPath())
226220
if err != nil {
227221
return err
228222
}

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"code.gitea.io/gitea/modules/analyze"
1616
"code.gitea.io/gitea/modules/charset"
1717
"code.gitea.io/gitea/modules/git"
18-
"code.gitea.io/gitea/modules/gitrepo"
1918
"code.gitea.io/gitea/modules/indexer"
2019
"code.gitea.io/gitea/modules/indexer/code/internal"
2120
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
@@ -209,12 +208,7 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository) elasti
209208
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
210209
reqs := make([]elastic.BulkableRequest, 0)
211210
if len(changes.Updates) > 0 {
212-
r, err := gitrepo.OpenRepository(ctx, repo)
213-
if err != nil {
214-
return err
215-
}
216-
defer r.Close()
217-
batch, err := r.NewBatch(ctx)
211+
batch, err := git.NewBatch(ctx, repo.RepoPath())
218212
if err != nil {
219213
return err
220214
}

routers/web/repo/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func createCommon(ctx *context.Context) {
154154
ctx.Data["Licenses"] = repo_module.Licenses
155155
ctx.Data["Readmes"] = repo_module.Readmes
156156
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
157-
ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo()
158-
ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit()
157+
ctx.Data["CanCreateRepoInDoer"] = ctx.Doer.CanCreateRepo()
158+
ctx.Data["MaxCreationLimitOfDoer"] = ctx.Doer.MaxCreationLimit()
159159
ctx.Data["SupportedObjectFormats"] = git.DefaultFeatures().SupportedObjectFormats
160160
ctx.Data["DefaultObjectFormat"] = git.Sha1ObjectFormat
161161
}

templates/repo/create.tmpl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77
<div class="ui attached segment">
88
{{template "base/alert" .}}
99
{{template "repo/create_helper" .}}
10-
11-
{{if not .CanCreateRepo}}
12-
<div class="ui negative message">
13-
<p>{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}</p>
14-
</div>
15-
{{end}}
1610
<form class="ui form left-right-form new-repo-form" action="{{.Link}}" method="post">
1711
{{.CsrfTokenHtml}}
12+
<div id="create-repo-error-message" class="ui negative message tw-text-center tw-hidden"></div>
1813
<div class="inline required field {{if .Err_Owner}}error{{end}}">
1914
<label>{{ctx.Locale.Tr "repo.owner"}}</label>
20-
<div class="ui selection owner dropdown">
21-
<input type="hidden" id="uid" name="uid" value="{{.ContextUser.ID}}" required>
22-
<span class="text truncated-item-container" title="{{.ContextUser.Name}}">
23-
{{ctx.AvatarUtils.Avatar .ContextUser 28 "mini"}}
24-
<span class="truncated-item-name">{{.ContextUser.ShortName 40}}</span>
25-
</span>
15+
<div class="ui selection dropdown" id="repo_owner_dropdown">
16+
<input type="hidden" name="uid" value="{{.ContextUser.ID}}">
17+
<span class="text truncated-item-name"></span>
2618
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
2719
<div class="menu">
28-
<div class="item truncated-item-container" data-value="{{.SignedUser.ID}}" title="{{.SignedUser.Name}}">
20+
<div class="item truncated-item-container" data-value="{{.SignedUser.ID}}" title="{{.SignedUser.Name}}"
21+
{{if not .CanCreateRepoInDoer}}
22+
data-create-repo-disallowed-prompt="{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimitOfDoer}}"
23+
{{end}}
24+
>
2925
{{ctx.AvatarUtils.Avatar .SignedUser 28 "mini"}}
3026
<span class="truncated-item-name">{{.SignedUser.ShortName 40}}</span>
3127
</div>
@@ -212,7 +208,7 @@
212208
<br>
213209
<div class="inline field">
214210
<label></label>
215-
<button class="ui primary button{{if not .CanCreateRepo}} disabled{{end}}">
211+
<button class="ui primary button">
216212
{{ctx.Locale.Tr "repo.create_repo"}}
217213
</button>
218214
</div>

tests/integration/repo_generate_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateID, templateOw
3131

3232
// Step2: click the "Use this template" button
3333
htmlDoc := NewHTMLParser(t, resp.Body)
34-
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/create\"]").Attr("href")
34+
link, exists := htmlDoc.doc.Find(`a.ui.button[href^="/repo/create"]`).Attr("href")
3535
assert.True(t, exists, "The template has changed")
3636
req = NewRequest(t, "GET", link)
3737
resp = session.MakeRequest(t, req, http.StatusOK)
3838

39-
// Step3: fill the form of the create
39+
// Step3: fill the form on the "create" page
4040
htmlDoc = NewHTMLParser(t, resp.Body)
41-
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/create\"]").Attr("action")
41+
link, exists = htmlDoc.doc.Find(`form.ui.form[action^="/repo/create"]`).Attr("action")
4242
assert.True(t, exists, "The template has changed")
43-
_, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", generateOwner.ID)).Attr("data-value")
43+
_, exists = htmlDoc.doc.Find(fmt.Sprintf(`#repo_owner_dropdown .item[data-value="%d"]`, generateOwner.ID)).Attr("data-value")
4444
assert.True(t, exists, "Generate owner '%s' is not present in select box", generateOwnerName)
4545
req = NewRequestWithValues(t, "POST", link, map[string]string{
4646
"_csrf": htmlDoc.GetCSRF(),

web_src/js/features/repo-new.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import {hideElem, showElem, toggleElem} from '../utils/dom.ts';
1+
import {hideElem, querySingleVisibleElem, showElem, toggleElem} from '../utils/dom.ts';
22
import {htmlEscape} from 'escape-goat';
33
import {fomanticQuery} from '../modules/fomantic/base.ts';
44
import {sanitizeRepoName} from './repo-common.ts';
55

66
const {appSubUrl} = window.config;
77

88
function initRepoNewTemplateSearch(form: HTMLFormElement) {
9-
const inputRepoOwnerUid = form.querySelector<HTMLInputElement>('#uid');
9+
const elSubmitButton = querySingleVisibleElem<HTMLInputElement>(form, '.ui.primary.button');
10+
const elCreateRepoErrorMessage = form.querySelector('#create-repo-error-message');
11+
const elRepoOwnerDropdown = form.querySelector('#repo_owner_dropdown');
1012
const elRepoTemplateDropdown = form.querySelector<HTMLInputElement>('#repo_template_search');
1113
const inputRepoTemplate = form.querySelector<HTMLInputElement>('#repo_template');
1214
const elTemplateUnits = form.querySelector('#template_units');
@@ -19,11 +21,23 @@ function initRepoNewTemplateSearch(form: HTMLFormElement) {
1921
inputRepoTemplate.addEventListener('change', checkTemplate);
2022
checkTemplate();
2123

22-
const $dropdown = fomanticQuery(elRepoTemplateDropdown);
24+
const $repoOwnerDropdown = fomanticQuery(elRepoOwnerDropdown);
25+
const $repoTemplateDropdown = fomanticQuery(elRepoTemplateDropdown);
2326
const onChangeOwner = function () {
24-
$dropdown.dropdown('setting', {
27+
const ownerId = $repoOwnerDropdown.dropdown('get value');
28+
const $ownerItem = $repoOwnerDropdown.dropdown('get item', ownerId);
29+
hideElem(elCreateRepoErrorMessage);
30+
elSubmitButton.disabled = false;
31+
if ($ownerItem?.length) {
32+
const elOwnerItem = $ownerItem[0];
33+
elCreateRepoErrorMessage.textContent = elOwnerItem.getAttribute('data-create-repo-disallowed-prompt') ?? '';
34+
const hasError = Boolean(elCreateRepoErrorMessage.textContent);
35+
toggleElem(elCreateRepoErrorMessage, hasError);
36+
elSubmitButton.disabled = hasError;
37+
}
38+
$repoTemplateDropdown.dropdown('setting', {
2539
apiSettings: {
26-
url: `${appSubUrl}/repo/search?q={query}&template=true&priority_owner_id=${inputRepoOwnerUid.value}`,
40+
url: `${appSubUrl}/repo/search?q={query}&template=true&priority_owner_id=${ownerId}`,
2741
onResponse(response: any) {
2842
const results = [];
2943
results.push({name: '', value: ''}); // empty item means not using template
@@ -33,14 +47,14 @@ function initRepoNewTemplateSearch(form: HTMLFormElement) {
3347
value: String(tmplRepo.repository.id),
3448
});
3549
}
36-
$dropdown.fomanticExt.onResponseKeepSelectedItem($dropdown, inputRepoTemplate.value);
50+
$repoTemplateDropdown.fomanticExt.onResponseKeepSelectedItem($repoTemplateDropdown, inputRepoTemplate.value);
3751
return {results};
3852
},
3953
cache: false,
4054
},
4155
});
4256
};
43-
inputRepoOwnerUid.addEventListener('change', onChangeOwner);
57+
$repoOwnerDropdown.dropdown('setting', 'onChange', onChangeOwner);
4458
onChangeOwner();
4559
}
4660

0 commit comments

Comments
 (0)