From 71aa592fb185699915c353b44f69811ae4476fb38befa00d327067bc08332e63 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Tue, 16 Jul 2024 14:52:35 +0200 Subject: [PATCH] . --- bots-common/git_utils_test.go | 37 ++++++++++++++++++++++++++++++----- bots-common/tsetup.sh | 11 +++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100755 bots-common/tsetup.sh diff --git a/bots-common/git_utils_test.go b/bots-common/git_utils_test.go index f0da848..5e78f83 100644 --- a/bots-common/git_utils_test.go +++ b/bots-common/git_utils_test.go @@ -1,6 +1,10 @@ package common import ( + "os" + "os/exec" + "path" + "strings" "testing" ) @@ -64,7 +68,7 @@ func TestGitMsgParsing(t *testing.T) { } gitHdr, err := parseGitMsg(data) - if err.Error() != "Invalid character during object hash parse" { + if err.Error() != "Invalid character during object hash parse 'r' at 4" { t.Error(err) } @@ -220,10 +224,33 @@ Reviewed-By: Marco Ippolito ` + "\x00" }) } -/*func TestCommitTreeParsingOfHead(t *testing.T) { - t.Run("reads HEAD and parses the tree", func (t *testing.T) { +func TestCommitTreeParsingOfHead(t *testing.T) { + gitDir := t.TempDir() + testDir, _ := os.Getwd() + var commitId string + cmd := exec.Command("/usr/bin/bash", path.Join(testDir, "tsetup.sh")) + cmd.Dir = gitDir + cmd.Stdout = writeFunc(func(data []byte) (int, error) { + commitId = commitId + strings.TrimSpace(string(data)) + return len(data), nil + }) + if err := cmd.Run(); err != nil { + t.Fatal(err.Error()) } -} -*/ + t.Run("reads HEAD and parses the tree", func(t *testing.T) { + const nodejs21 = "c678c57007d496a98bec668ae38f2c26a695f94af78012f15d044ccf066ccb41" + h := RequestHandler{ + GitPath: gitDir, + Logger: CreateTestLogger(t), + } + id, ok := h.GitSubmoduleCommitId("", "nodejs21", commitId) + if !ok { + t.Error("failed parse") + } + if id != nodejs21 { + t.Errorf("hash doesn't match: %s vs. expected %s", id, nodejs21) + } + }) +} diff --git a/bots-common/tsetup.sh b/bots-common/tsetup.sh new file mode 100755 index 0000000..9085500 --- /dev/null +++ b/bots-common/tsetup.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash + +git init -q --bare --object-format=sha256 +blobA=$(echo "help" | git hash-object --stdin -w) +blobB=$(echo "foo" | git hash-object --stdin -w) +tree=$(printf "100644 blob $blobA help\n100644 blob $blobB README.md\n160000 commit dc55b828328c8e494f67874a7d8c03dd1c6b4e02d16b86e08e47d70ecd799680 mingw32-gcc\n160000 commit d6a74c08406ce40cc8f7bff2d5cf309087a8728361cc75354b0862ba508193b8 nodejs-common\n160000 commit c678c57007d496a98bec668ae38f2c26a695f94af78012f15d044ccf066ccb41 nodejs21\n160000 commit 873a323b262ebb3bd77b2592b2e11bdd08dbc721cbf4ac9f97637e58e1fffce7 nodejs22\n160000 commit 35c702e8501eedeb5ce43d6f3460d11c791cfefaa77248f08cad55d00c37e73a python311\n"|git mktree) +commit=$(git commit-tree -m 'OK' $tree) +git reset --soft $commit + +echo $commit +