loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(ui): clarify repo init instruction for sha256 (#7394)

- When the repository is initalized with a different objectformat than sha1, ensure that the empty repository instructions reflects that the `git init` command also needs to be initialized with that objectformat.
- Resolves https://codeberg.org/codeberg/community/issues/1837
- Added integration test.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7394
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>

authored by

Gusted
Gusted
and committed by
0ko
5275fbd4 86039a89

+68 -9
+1 -1
templates/repo/empty.tmpl
··· 50 50 <h3>{{ctx.Locale.Tr "repo.create_new_repo_command"}}</h3> 51 51 <div class="markup"> 52 52 <pre><code>touch README.md 53 - git init 53 + git init{{if eq .Repository.ObjectFormatName "sha256"}} --object-format=sha256{{end}} 54 54 {{if ne .Repository.DefaultBranch "master"}}git switch -c {{.Repository.DefaultBranch}}{{end}} 55 55 git add README.md 56 56 git commit -m "first commit"
+57
tests/integration/repo_test.go
··· 9 9 "net/http" 10 10 "net/url" 11 11 "path" 12 + "regexp" 12 13 "strings" 13 14 "testing" 14 15 "time" ··· 19 20 "forgejo.org/models/unittest" 20 21 user_model "forgejo.org/models/user" 21 22 "forgejo.org/modules/git" 23 + "forgejo.org/modules/optional" 22 24 "forgejo.org/modules/setting" 23 25 "forgejo.org/modules/test" 24 26 "forgejo.org/modules/translation" ··· 1438 1440 req = NewRequest(t, "GET", "/user2/repo59/blame/branch/master/deep") 1439 1441 MakeRequest(t, req, http.StatusNotFound) 1440 1442 } 1443 + 1444 + func TestInitInstructions(t *testing.T) { 1445 + defer tests.PrepareTestEnv(t)() 1446 + 1447 + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 1448 + session := loginUser(t, user.Name) 1449 + 1450 + sha256Repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user, tests.DeclarativeRepoOptions{ 1451 + Name: optional.Some("sha256-instruction"), 1452 + AutoInit: optional.Some(false), 1453 + EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}), 1454 + ObjectFormat: optional.Some("sha256"), 1455 + }) 1456 + defer f() 1457 + 1458 + sha1Repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user, tests.DeclarativeRepoOptions{ 1459 + Name: optional.Some("sha1-instruction"), 1460 + AutoInit: optional.Some(false), 1461 + EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}), 1462 + ObjectFormat: optional.Some("sha1"), 1463 + }) 1464 + defer f() 1465 + 1466 + portMatcher := regexp.MustCompile(`localhost:\d+`) 1467 + 1468 + t.Run("sha256", func(t *testing.T) { 1469 + defer tests.PrintCurrentTest(t)() 1470 + 1471 + resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+sha256Repo.FullName()), http.StatusOK) 1472 + 1473 + htmlDoc := NewHTMLParser(t, resp.Body) 1474 + assert.Equal(t, `touch README.md 1475 + git init --object-format=sha256 1476 + git switch -c main 1477 + git add README.md 1478 + git commit -m "first commit" 1479 + git remote add origin http://localhost/user2/sha256-instruction.git 1480 + git push -u origin main`, portMatcher.ReplaceAllString(htmlDoc.Find(".empty-repo-guide code").First().Text(), "localhost")) 1481 + }) 1482 + 1483 + t.Run("sha1", func(t *testing.T) { 1484 + defer tests.PrintCurrentTest(t)() 1485 + 1486 + resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+sha1Repo.FullName()), http.StatusOK) 1487 + 1488 + htmlDoc := NewHTMLParser(t, resp.Body) 1489 + assert.Equal(t, `touch README.md 1490 + git init 1491 + git switch -c main 1492 + git add README.md 1493 + git commit -m "first commit" 1494 + git remote add origin http://localhost/user2/sha1-instruction.git 1495 + git push -u origin main`, portMatcher.ReplaceAllString(htmlDoc.Find(".empty-repo-guide code").First().Text(), "localhost")) 1496 + }) 1497 + }
+10 -8
tests/test_utils.go
··· 355 355 WikiBranch optional.Option[string] 356 356 AutoInit optional.Option[bool] 357 357 IsTemplate optional.Option[bool] 358 + ObjectFormat optional.Option[string] 358 359 } 359 360 360 361 func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts DeclarativeRepoOptions) (*repo_model.Repository, string, func()) { ··· 378 379 379 380 // Create the repository 380 381 repo, err := repo_service.CreateRepository(db.DefaultContext, owner, owner, repo_service.CreateRepoOptions{ 381 - Name: repoName, 382 - Description: "Temporary Repo", 383 - AutoInit: autoInit, 384 - Gitignores: "", 385 - License: "WTFPL", 386 - Readme: "Default", 387 - DefaultBranch: "main", 388 - IsTemplate: opts.IsTemplate.Value(), 382 + Name: repoName, 383 + Description: "Temporary Repo", 384 + AutoInit: autoInit, 385 + Gitignores: "", 386 + License: "WTFPL", 387 + Readme: "Default", 388 + DefaultBranch: "main", 389 + IsTemplate: opts.IsTemplate.Value(), 390 + ObjectFormatName: opts.ObjectFormat.Value(), 389 391 }) 390 392 require.NoError(t, err) 391 393 assert.NotEmpty(t, repo)