diff --git a/Makefile b/Makefile index 6eb64e7..6e26c2a 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test-e2e: .PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports -VERSION := 0.52.17 +VERSION := 0.52.18 COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)' diff --git a/pkg/cli/setup.go b/pkg/cli/setup.go index 213c537..9b59ab1 100644 --- a/pkg/cli/setup.go +++ b/pkg/cli/setup.go @@ -166,6 +166,19 @@ func promptYesNo() bool { return response == "yes" || response == "y" } +func promptBranch() string { + reader := bufio.NewReader(os.Stdin) + fmt.Printf(" Select branch (main/nightly) [default: main]: ") + response, _ := reader.ReadString('\n') + response = strings.ToLower(strings.TrimSpace(response)) + + if response == "nightly" { + return "nightly" + } + // Default to main for anything else (including empty) + return "main" +} + // isValidMultiaddr validates bootstrap peer multiaddr format func isValidMultiaddr(s string) bool { s = strings.TrimSpace(s) @@ -616,16 +629,38 @@ func setupDirectories() { func cloneAndBuild() { fmt.Printf("🔨 Cloning and building DeBros Network...\n") + // Prompt for branch selection + branch := promptBranch() + fmt.Printf(" Using branch: %s\n", branch) + // Check if already cloned if _, err := os.Stat("/home/debros/src/.git"); err == nil { fmt.Printf(" Updating repository...\n") - cmd := exec.Command("sudo", "-u", "debros", "git", "-C", "/home/debros/src", "pull", "origin", "nightly") + + // Check current branch and switch if needed + currentBranchCmd := exec.Command("sudo", "-u", "debros", "git", "-C", "/home/debros/src", "rev-parse", "--abbrev-ref", "HEAD") + if output, err := currentBranchCmd.Output(); err == nil { + currentBranch := strings.TrimSpace(string(output)) + if currentBranch != branch { + fmt.Printf(" Switching from %s to %s...\n", currentBranch, branch) + // Fetch the target branch first (needed for shallow clones) + exec.Command("sudo", "-u", "debros", "git", "-C", "/home/debros/src", "fetch", "origin", branch).Run() + // Checkout the selected branch + checkoutCmd := exec.Command("sudo", "-u", "debros", "git", "-C", "/home/debros/src", "checkout", branch) + if err := checkoutCmd.Run(); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to switch branch: %v\n", err) + } + } + } + + // Pull latest changes + cmd := exec.Command("sudo", "-u", "debros", "git", "-C", "/home/debros/src", "pull", "origin", branch) if err := cmd.Run(); err != nil { fmt.Fprintf(os.Stderr, "⚠️ Failed to update repo: %v\n", err) } } else { fmt.Printf(" Cloning repository...\n") - cmd := exec.Command("sudo", "-u", "debros", "git", "clone", "--branch", "nightly", "--depth", "1", "https://github.com/DeBrosOfficial/network.git", "/home/debros/src") + cmd := exec.Command("sudo", "-u", "debros", "git", "clone", "--branch", branch, "--depth", "1", "https://github.com/DeBrosOfficial/network.git", "/home/debros/src") if err := cmd.Run(); err != nil { fmt.Fprintf(os.Stderr, "❌ Failed to clone repo: %v\n", err) os.Exit(1)