mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
75 lines
2.6 KiB
Go
75 lines
2.6 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/modules/git/gitcmd"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func gitConfigContains(sub string) bool {
|
|
if b, err := os.ReadFile(gitcmd.HomeDir() + "/.gitconfig"); err == nil {
|
|
return strings.Contains(string(b), sub)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func TestGitConfig(t *testing.T) {
|
|
ctx := t.Context()
|
|
assert.False(t, gitConfigContains("key-a"))
|
|
|
|
assert.NoError(t, configSetNonExist(ctx, "test.key-a", "val-a"))
|
|
assert.True(t, gitConfigContains("key-a = val-a"))
|
|
|
|
assert.NoError(t, configSetNonExist(ctx, "test.key-a", "val-a-changed"))
|
|
assert.False(t, gitConfigContains("key-a = val-a-changed"))
|
|
|
|
assert.NoError(t, configSet(ctx, "test.key-a", "val-a-changed"))
|
|
assert.True(t, gitConfigContains("key-a = val-a-changed"))
|
|
|
|
assert.NoError(t, configAddNonExist(ctx, "test.key-b", "val-b"))
|
|
assert.True(t, gitConfigContains("key-b = val-b"))
|
|
|
|
assert.NoError(t, configAddNonExist(ctx, "test.key-b", "val-2b"))
|
|
assert.True(t, gitConfigContains("key-b = val-b"))
|
|
assert.True(t, gitConfigContains("key-b = val-2b"))
|
|
|
|
assert.NoError(t, configUnsetAll(ctx, "test.key-b", "val-b"))
|
|
assert.False(t, gitConfigContains("key-b = val-b"))
|
|
assert.True(t, gitConfigContains("key-b = val-2b"))
|
|
|
|
assert.NoError(t, configUnsetAll(ctx, "test.key-b", "val-2b"))
|
|
assert.False(t, gitConfigContains("key-b = val-2b"))
|
|
|
|
assert.NoError(t, configSet(ctx, "test.key-x", "*"))
|
|
assert.True(t, gitConfigContains("key-x = *"))
|
|
assert.NoError(t, configSetNonExist(ctx, "test.key-x", "*"))
|
|
assert.NoError(t, configUnsetAll(ctx, "test.key-x", "*"))
|
|
assert.False(t, gitConfigContains("key-x = *"))
|
|
}
|
|
|
|
func TestSyncGitConfig(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.GitConfig)()
|
|
|
|
assert.Empty(t, setting.GitConfig.Options)
|
|
assert.NoError(t, syncGitConfig(t.Context()))
|
|
assert.True(t, gitConfigContains("commitGraph = true")) // builtin default config
|
|
|
|
setting.GitConfig.Options["sync-test.cfg-key-a"] = "CfgValA"
|
|
setting.GitConfig.Options["core.commitgraph"] = "false"
|
|
assert.NoError(t, syncGitConfig(t.Context()))
|
|
assert.True(t, gitConfigContains("[sync-test]"))
|
|
assert.True(t, gitConfigContains("cfg-key-a = CfgValA"))
|
|
assert.False(t, gitConfigContains("commitGraph")) // builtin default config can be overridden
|
|
assert.True(t, gitConfigContains("commitgraph = false")) // git config key is case-insensitive
|
|
}
|