8a66c6a463
New commands: - tstudio update: self-updater from S3 - tstudio token create/list/revoke: API token management - tstudio setup-git: configures git HTTPS credentials (auto-run on login) Infrastructure: - CI pipeline (.gitea/workflows/build-tstudio.yml) — builds all 5 platforms, uploads to S3 - Version bump 0.1.0 → 0.2.0 - Login now auto-configures git credential helper + SSH→HTTPS rewrite Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
// Copyright 2026 Tinqs Ltd. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func cmdSetupGit(args []string) {
|
|
fs := flag.NewFlagSet("setup-git", flag.ExitOnError)
|
|
fs.Usage = func() {
|
|
fmt.Print(`Usage: tstudio setup-git
|
|
|
|
Configure git to use your tstudio credentials for HTTPS operations.
|
|
After this, git push/pull/fetch will work without SSH keys.
|
|
|
|
This is automatically run during 'tstudio login'.
|
|
`)
|
|
}
|
|
fs.Parse(args)
|
|
|
|
cfg := mustLoadConfig()
|
|
if err := setupGitCredentials(cfg); err != nil {
|
|
fatal("failed to configure git: %v", err)
|
|
}
|
|
fmt.Println("Git configured for HTTPS access.")
|
|
}
|
|
|
|
// setupGitCredentials stores the tstudio token in git's credential store
|
|
// so all HTTPS git operations to the instance work without SSH.
|
|
func setupGitCredentials(cfg *Config) error {
|
|
instance := strings.TrimRight(cfg.Instance, "/")
|
|
host := strings.TrimPrefix(instance, "https://")
|
|
host = strings.TrimPrefix(host, "http://")
|
|
|
|
// Store credentials via git credential approve (works with any credential helper)
|
|
credInput := fmt.Sprintf("protocol=https\nhost=%s\nusername=%s\npassword=%s\n\n", host, cfg.Username, cfg.Token)
|
|
credCmd := exec.Command("git", "credential", "approve")
|
|
credCmd.Stdin = strings.NewReader(credInput)
|
|
if err := credCmd.Run(); err != nil {
|
|
return fmt.Errorf("git credential approve failed: %v", err)
|
|
}
|
|
|
|
// Ensure a credential helper is configured (git may not have one by default)
|
|
out, _ := exec.Command("git", "config", "--global", "credential.helper").Output()
|
|
helper := strings.TrimSpace(string(out))
|
|
if helper == "" {
|
|
// Set up the default credential store
|
|
exec.Command("git", "config", "--global", "credential.helper", "store").Run()
|
|
// Re-store credentials now that helper is configured
|
|
credCmd2 := exec.Command("git", "credential", "approve")
|
|
credCmd2.Stdin = strings.NewReader(credInput)
|
|
credCmd2.Run()
|
|
}
|
|
|
|
// Configure git to prefer HTTPS clone URLs for this host
|
|
gitKey := fmt.Sprintf("url.https://%s/.insteadOf", host)
|
|
exec.Command("git", "config", "--global", gitKey, fmt.Sprintf("git@%s:", host)).Run()
|
|
|
|
fmt.Printf(" Credential helper: %s\n", helper)
|
|
fmt.Printf(" Instance: %s\n", instance)
|
|
fmt.Printf(" Username: %s\n", cfg.Username)
|
|
fmt.Printf(" SSH → HTTPS rewrite: git@%s: → https://%s/\n", host, host)
|
|
|
|
return nil
|
|
}
|