summaryrefslogtreecommitdiff
path: root/internal/sync/git_operations_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/sync/git_operations_test.go')
-rw-r--r--internal/sync/git_operations_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/sync/git_operations_test.go b/internal/sync/git_operations_test.go
index 4ca630d..ba40525 100644
--- a/internal/sync/git_operations_test.go
+++ b/internal/sync/git_operations_test.go
@@ -4,8 +4,11 @@ import (
"os"
"os/exec"
"path/filepath"
+ "reflect"
"strings"
"testing"
+
+ "codeberg.org/snonux/gitsyncer/internal/config"
)
func TestGitCommand_SetsDir(t *testing.T) {
@@ -24,6 +27,49 @@ func TestGitCommand_LeavesDirEmptyForGlobalCommands(t *testing.T) {
}
}
+func TestPushBranchArgs(t *testing.T) {
+ t.Parallel()
+
+ tests := []struct {
+ name string
+ setUpstream bool
+ org *config.Organization
+ want []string
+ }{
+ {
+ name: "regular backup push",
+ org: &config.Organization{BackupLocation: true},
+ want: []string{"push", "backup", "main", "--tags"},
+ },
+ {
+ name: "forced backup push",
+ org: &config.Organization{BackupLocation: true, ForcePush: true},
+ want: []string{"push", "backup", "main", "--tags", "--force"},
+ },
+ {
+ name: "forced backup push with upstream",
+ setUpstream: true,
+ org: &config.Organization{BackupLocation: true, ForcePush: true},
+ want: []string{"push", "-u", "backup", "main", "--tags", "--force"},
+ },
+ {
+ name: "force ignored for primary remote",
+ org: &config.Organization{ForcePush: true},
+ want: []string{"push", "backup", "main", "--tags"},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+ got := pushBranchArgs("backup", "main", tt.setUpstream, tt.org)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Fatalf("pushBranchArgs() = %#v, want %#v", got, tt.want)
+ }
+ })
+ }
+}
+
func TestParseTagHashOutput_EmptyOutput(t *testing.T) {
for _, in := range [][]byte{nil, []byte(""), []byte(" \n\t \n")} {
hash, err := parseTagHashOutput(in, "v1.0.0", "origin")