Skip to content
Permalink
Browse files
fix(git): git warnings sometimes break werf
Refactored true_git module:
* moved common exec.Command logic into git_cmd.go
* separated stdout/stderr channels for git cli commands output

Fixed git warnings breaking werf dev mode by ignoring stderr whenever
it is not needed.
  • Loading branch information
ilya-lesikov committed Jan 19, 2022
1 parent 4bcd7c3 commit 0a509618bf8ba3734b7c942486e87895200ead6d
Showing with 264 additions and 349 deletions.
  1. +2 −2 cmd/werf/build/main.go
  2. +2 −2 cmd/werf/bundle/export/export.go
  3. +2 −2 cmd/werf/bundle/publish/publish.go
  4. +2 −2 cmd/werf/ci_env/ci_env.go
  5. +3 −3 cmd/werf/cleanup/cleanup.go
  6. +5 −5 cmd/werf/common/common.go
  7. +1 −1 cmd/werf/common/follow.go
  8. +2 −2 cmd/werf/compose/main.go
  9. +2 −2 cmd/werf/config/list/list.go
  10. +2 −2 cmd/werf/config/render/render.go
  11. +2 −2 cmd/werf/converge/converge.go
  12. +2 −2 cmd/werf/dismiss/dismiss.go
  13. +2 −2 cmd/werf/export/export.go
  14. +2 −2 cmd/werf/helm/get_autogenerated_values.go
  15. +2 −2 cmd/werf/helm/get_namespace.go
  16. +2 −2 cmd/werf/helm/get_release.go
  17. +2 −2 cmd/werf/helm/secret/rotate_secret_key/rotate_secret_key.go
  18. +1 −1 cmd/werf/host/cleanup/cleanup.go
  19. +2 −2 cmd/werf/managed_images/add/add.go
  20. +2 −2 cmd/werf/managed_images/ls/ls.go
  21. +2 −2 cmd/werf/managed_images/rm/rm.go
  22. +2 −2 cmd/werf/purge/purge.go
  23. +2 −2 cmd/werf/render/render.go
  24. +2 −2 cmd/werf/run/run.go
  25. +2 −2 cmd/werf/stage/image/main.go
  26. +1 −1 pkg/build/conveyor.go
  27. +2 −2 pkg/git_repo/base.go
  28. +10 −10 pkg/git_repo/local.go
  29. +3 −3 pkg/git_repo/remote.go
  30. +5 −20 pkg/true_git/common.go
  31. +11 −14 pkg/true_git/dot_git.go
  32. +72 −0 pkg/true_git/git_cmd.go
  33. +14 −4 pkg/true_git/git_cmd_test.go
  34. +9 −15 pkg/true_git/init.go
  35. +7 −29 pkg/true_git/merge.go
  36. +8 −7 pkg/true_git/merge_base.go
  37. +9 −17 pkg/true_git/repository.go
  38. +6 −21 pkg/true_git/service_branch.go
  39. +1 −1 pkg/true_git/service_branch_test.go
  40. +6 −10 pkg/true_git/show_ref.go
  41. +7 −18 pkg/true_git/status/status.go
  42. +6 −31 pkg/true_git/submodule.go
  43. +35 −94 pkg/true_git/work_tree.go
@@ -155,7 +155,7 @@ func runMain(ctx context.Context, args []string) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -172,7 +172,7 @@ func runMain(ctx context.Context, args []string) error {
}
}()

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -155,7 +155,7 @@ func runExport(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -169,7 +169,7 @@ func runExport(ctx context.Context) error {
}
}()

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -171,7 +171,7 @@ func runPublish(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -185,7 +185,7 @@ func runPublish(ctx context.Context) error {
}
}()

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -102,7 +102,7 @@ func runCIEnv(cmd *cobra.Command, args []string) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -343,7 +343,7 @@ func generateGithubEnvs(ctx context.Context, w io.Writer, dockerConfig string) e
func generateGithubDefaultRepo(ctx context.Context, defaultRegistry, ciGithubDockerPackage string) (string, error) {
var defaultRepo string
if ciGithubDockerPackage != "" {
giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return "", err
}
@@ -116,7 +116,7 @@ func runCleanup(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -143,7 +143,7 @@ func runCleanup(ctx context.Context) error {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -162,7 +162,7 @@ func runCleanup(ctx context.Context) error {
}

if !werfConfig.Meta.GitWorktree.GetForceShallowClone() && !werfConfig.Meta.GitWorktree.GetAllowFetchingOriginBranchesAndTags() {
isShallow, err := giterminismManager.LocalGitRepo().IsShallowClone()
isShallow, err := giterminismManager.LocalGitRepo().IsShallowClone(ctx)
if err != nil {
return fmt.Errorf("check shallow clone failed: %s", err)
}
@@ -1163,10 +1163,10 @@ func GetWerfConfigOptions(cmdData *CmdData, logRenderedFilePath bool) config.Wer
}
}

func GetGiterminismManager(cmdData *CmdData) (giterminism_manager.Interface, error) {
func GetGiterminismManager(ctx context.Context, cmdData *CmdData) (giterminism_manager.Interface, error) {
workingDir := GetWorkingDir(cmdData)

gitWorkTree, err := GetGitWorkTree(cmdData, workingDir)
gitWorkTree, err := GetGitWorkTree(ctx, cmdData, workingDir)
if err != nil {
return nil, err
}
@@ -1200,11 +1200,11 @@ func GetGiterminismManager(cmdData *CmdData) (giterminism_manager.Interface, err
})
}

func GetGitWorkTree(cmdData *CmdData, workingDir string) (string, error) {
func GetGitWorkTree(ctx context.Context, cmdData *CmdData, workingDir string) (string, error) {
if *cmdData.GitWorkTree != "" {
workTree := *cmdData.GitWorkTree

if isValid, err := true_git.IsValidWorkTree(workTree); err != nil {
if isValid, err := true_git.IsValidWorkTree(ctx, workTree); err != nil {
return "", err
} else if isValid {
return util.GetAbsoluteFilepath(workTree), nil
@@ -1213,7 +1213,7 @@ func GetGitWorkTree(cmdData *CmdData, workingDir string) (string, error) {
return "", fmt.Errorf("werf requires a git work tree for the project to exist: not a valid git work tree %q specified", workTree)
}

if found, workTree, err := true_git.UpwardLookupAndVerifyWorkTree(workingDir); err != nil {
if found, workTree, err := true_git.UpwardLookupAndVerifyWorkTree(ctx, workingDir); err != nil {
return "", err
} else if found {
return util.GetAbsoluteFilepath(workTree), nil
@@ -21,7 +21,7 @@ func FollowGitHead(ctx context.Context, cmdData *CmdData, taskFunc func(ctx cont

var savedHeadCommit string
iterFunc := func() error {
giterminismManager, err := GetGiterminismManager(cmdData)
giterminismManager, err := GetGiterminismManager(ctx, cmdData)
if err != nil {
return fmt.Errorf("unable to get giterminism manager: %s", err)
}
@@ -317,7 +317,7 @@ func runMain(ctx context.Context, dockerComposeCmdName string, cmdData composeCm
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -331,7 +331,7 @@ func runMain(ctx context.Context, dockerComposeCmdName string, cmdData composeCm
}
}()

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -68,11 +68,11 @@ func run() error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -41,11 +41,11 @@ func NewCmd() *cobra.Command {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -195,7 +195,7 @@ func runMain(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -209,7 +209,7 @@ func runMain(ctx context.Context) error {
}
}()

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -143,7 +143,7 @@ func runDismiss(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -157,7 +157,7 @@ func runDismiss(ctx context.Context) error {

common.LogKubeContext(kube.Context)

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -136,15 +136,15 @@ func run(ctx context.Context, imagesToProcess, tagTemplateList []string) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

if err := common.DockerRegistryInit(ctx, &commonCmdData); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -120,15 +120,15 @@ func runGetServiceValues(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *getAutogeneratedValuedCmdData.LogVerbose || *getAutogeneratedValuedCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *getAutogeneratedValuedCmdData.LogVerbose || *getAutogeneratedValuedCmdData.LogDebug}); err != nil {
return err
}

if err := common.DockerRegistryInit(ctx, &getAutogeneratedValuedCmdData); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&getAutogeneratedValuedCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &getAutogeneratedValuedCmdData)
if err != nil {
return err
}
@@ -62,11 +62,11 @@ func runGetNamespace() error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *getNamespaceCmdData.LogVerbose || *getNamespaceCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *getNamespaceCmdData.LogVerbose || *getNamespaceCmdData.LogDebug}); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&getNamespaceCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &getNamespaceCmdData)
if err != nil {
return err
}
@@ -62,11 +62,11 @@ func runGetRelease() error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *getReleaseCmdData.LogVerbose || *getReleaseCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *getReleaseCmdData.LogVerbose || *getReleaseCmdData.LogDebug}); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&getReleaseCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &getReleaseCmdData)
if err != nil {
return err
}
@@ -80,11 +80,11 @@ func runRotateSecretKey(ctx context.Context, cmd *cobra.Command, secretValuesPat
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -111,7 +111,7 @@ func runGC(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -100,7 +100,7 @@ func run(ctx context.Context, imageName string) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -122,7 +122,7 @@ func run(ctx context.Context, imageName string) error {
}
defer tmp_manager.ReleaseProjectDir(projectTmpDir)

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -96,7 +96,7 @@ func run(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -118,7 +118,7 @@ func run(ctx context.Context) error {
}
defer tmp_manager.ReleaseProjectDir(projectTmpDir)

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -100,7 +100,7 @@ func run(ctx context.Context, imageNames []string) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -122,7 +122,7 @@ func run(ctx context.Context, imageNames []string) error {
}
defer tmp_manager.ReleaseProjectDir(projectTmpDir)

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -108,7 +108,7 @@ func runPurge(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

@@ -120,7 +120,7 @@ func runPurge(ctx context.Context) error {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}
@@ -160,11 +160,11 @@ func runRender(ctx context.Context) error {
return err
}

if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
if err := true_git.Init(ctx, true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}

giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
giterminismManager, err := common.GetGiterminismManager(ctx, &commonCmdData)
if err != nil {
return err
}

0 comments on commit 0a50961

Please sign in to comment.