Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/cmd/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
flagCheckout bool
flagFetch bool
flagPull bool
flagResetHard bool
flagDefaultBranch string

flagExecuteTimeout *time.Duration
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ var rootCmd = &cobra.Command{
}

func init() {
rootCmd.Version = "v0.0.1-alpha1"
rootCmd.Version = "v0.0.1"

rootCmd.Flags().StringVarP(&flagDir, "dir", "d", "../", "Путь к каталогу с проектами")
rootCmd.Flags().StringVarP(&flagDefaultBranch, "branch", "b", "master", "Наименование ветки: master/main")
rootCmd.Flags().BoolVarP(&flagAll, "all", "a", false, "Выполнить все шаги checkout master, fetch, pull")
rootCmd.Flags().BoolVarP(&flagAll, "checkout", "c", false, "Выполнить checkout master")
rootCmd.Flags().BoolVarP(&flagAll, "fetch", "f", false, "Выполнить fetch")
rootCmd.Flags().BoolVarP(&flagAll, "pull", "p", false, "Выполнить pull")
rootCmd.Flags().BoolVarP(&flagCheckout, "checkout", "c", false, "Выполнить checkout master")
rootCmd.Flags().BoolVarP(&flagFetch, "fetch", "f", false, "Выполнить fetch")
rootCmd.Flags().BoolVarP(&flagPull, "pull", "p", false, "Выполнить pull")
rootCmd.Flags().BoolVarP(&flagResetHard, "reset-hard", "r", false, "При необходимости перед git checkout выполнить git reset --hard")

flagExecuteTimeout = rootCmd.Flags().DurationP("execute_timeout", "e", time.Second*30, "Максимальное время обработки одного каталога")
}
Expand Down
15 changes: 13 additions & 2 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,18 @@ func processDir(dir string, ch chan resultLogChan) {
}

if !strings.Contains(string(res), gitStatusOk) {
resultLogs.AddLog("skipped: there are uncommitted changes")
return
resultLogs.AddLog("find uncommitted changes")

if !flagResetHard {
resultLogs.AddLog("skipped: there are uncommitted changes")
return
}

if _, err := shell_executor.Run(ctx, dir, "git", "reset", "--hard"); err != nil {
resultLogs.AddLog("error: git reset --hard: " + err.Error())
return
}
resultLogs.AddLog("success: git reset --hard")
}

if _, err := shell_executor.Run(ctx, dir, "git", "checkout", flagDefaultBranch); err != nil {
Expand All @@ -124,4 +134,5 @@ func processDir(dir string, ch chan resultLogChan) {
return
}
resultLogs.AddLog("success: git pull")

}