/
sondr
/
bxmake
Обзор
Документация
Войти
/
sondr
/
bxmake
Код
Запросы
0
Пакеты
0
Релизы
7
Аналитика
Безопасность
master
cmd/pull/pull.go
113 строк
3 KB
Denis Son
Initial commit
17 ноя 2025, 14:32
17 ноя 2025, 14:32
1a12c0b
Код
Авторство
О чём код?
package pull import ( "fmt" "strings" "github.com/spf13/cobra" "gitverse.ru/sondr/bxmake/internal/errors" "gitverse.ru/sondr/bxmake/internal/git" ) // pullCmd represents the pull command var pullCmd = &cobra.Command{ Use: "pull [--verbose]", Aliases: []string{"p"}, Short: "Pull changes from remote repository (alias: p)", Long: `Pulls all changes from the remote repository. Supports both SSH and HTTPS authentication automatically. Use --verbose to show detailed information about the pull process.`, RunE: runPull, } // GetPullCmd returns the pull command func GetPullCmd() *cobra.Command { return pullCmd } func init() { // Configure flags for pull command pullCmd.Flags().Bool("verbose", false, "Show detailed information about the pull process") } func runPull(cmd *cobra.Command, args []string) error { // Get --verbose flag value verbose, _ := cmd.Flags().GetBool("verbose") // Check that we are in a git repository if !git.IsRepository() { return errors.NewConfigError("current directory is not a Git repository", nil) } repo, err := git.NewRepository() if err != nil { return errors.NewConfigError("failed to open Git repository", err) } if verbose { fmt.Println("Verbose mode enabled") fmt.Println("Working directory:", ".") fmt.Println("Checking Git repository status...") } // Get current branch information currentBranch, err := repo.GetCurrentBranch() if err != nil { if verbose { fmt.Printf("Warning: Could not determine current branch: %v\n", err) } } else if verbose { fmt.Printf("Current branch: %s\n", currentBranch) } // Get remote repository information remoteURL, err := repo.GetRemoteURL() if err != nil { return errors.NewConfigError("failed to get remote repository URL", err) } if verbose { fmt.Printf("Remote repository: %s\n", remoteURL) fmt.Printf("Remote name: origin\n") // Determine authentication type if strings.HasPrefix(remoteURL, "git@") || strings.HasPrefix(remoteURL, "ssh://") { fmt.Println("Authentication method: SSH") } else if strings.HasPrefix(remoteURL, "https://") { fmt.Println("Authentication method: HTTPS") } else { fmt.Println("Authentication method: Unknown") } } fmt.Println("Pulling changes from remote repository...") // Execute git pull with automatic authentication err = repo.Pull() if err != nil { if verbose { fmt.Printf("Pull failed with error: %v\n", err) fmt.Println("Possible causes:") fmt.Println(" - Authentication issues (check SSH keys or credentials)") fmt.Println(" - Network connectivity problems") fmt.Println(" - Remote repository not accessible") fmt.Println(" - Local repository conflicts") } return errors.NewConfigError("failed to pull changes", err) } if verbose { fmt.Println("Pull operation completed successfully") fmt.Println("Checking for new commits...") // Get current branch after pull afterBranch, err := repo.GetCurrentBranch() if err == nil && afterBranch != currentBranch { fmt.Printf("Branch changed from '%s' to '%s'\n", currentBranch, afterBranch) } } else { fmt.Println("Successfully pulled changes from remote repository") } return nil }