From c355eb8ecb0bb1af0ccf55e6262ca8c0d5c7e352 Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Fri, 30 Jul 2021 08:46:35 -0600 Subject: [PATCH] fix(internal/carver): don't tag commits (#4518) After running some simulations in became apparent that the tool should not tags commits. This is because when merging the sha will change. The tool now outputs a template for the commands to run post merge. --- internal/carver/cmd/_tidyhack_tmpl.txt | 2 +- internal/carver/cmd/main.go | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/internal/carver/cmd/_tidyhack_tmpl.txt b/internal/carver/cmd/_tidyhack_tmpl.txt index b35c2fd5c06..552463e4b99 100644 --- a/internal/carver/cmd/_tidyhack_tmpl.txt +++ b/internal/carver/cmd/_tidyhack_tmpl.txt @@ -19,4 +19,4 @@ package {{.Package}} // Necessary for safely adding multi-module repo. See: https://github.com/golang/go/wiki/Modules#is-it-possible-to-add-a-module-to-a-multi-module-repository -import _ "{{.RootMod}}" \ No newline at end of file +import _ "{{.RootMod}}" diff --git a/internal/carver/cmd/main.go b/internal/carver/cmd/main.go index f2c90387394..59e702a6e4d 100644 --- a/internal/carver/cmd/main.go +++ b/internal/carver/cmd/main.go @@ -94,7 +94,6 @@ func main() { flag.Usage() os.Exit(1) } - log.Println("Successfully carved out module. Changes are ready to be pushed.") } func (c *carver) Run() error { @@ -304,6 +303,7 @@ func (c *carver) CreateGitTags(rootMod *modInfo) error { return err } childPrefix := strings.TrimPrefix(strings.TrimPrefix(c.childModPath, rootMod.filePath), "/") + childModTag := fmt.Sprintf("%s/%s", childPrefix, c.childTagVersion) log.Println("Commiting changes") if !c.dryRun { cmd := exec.Command("git", "add", "-A") @@ -312,28 +312,18 @@ func (c *carver) CreateGitTags(rootMod *modInfo) error { return fmt.Errorf("unable to add changes: %s", b) } cmd = exec.Command("git", "commit", "-m", - fmt.Sprintf("chore(%s): carve out sub-module", childPrefix)) + fmt.Sprintf("chore(%s): carve out sub-module\n\nThis commit will be tagged %s and %s.", childPrefix, futureTag, childModTag)) cmd.Dir = c.parentModPath if b, err := cmd.Output(); err != nil { return fmt.Errorf("unable to commit changes: %s", b) } } - log.Printf("Tagging Root module: %s", futureTag) - if !c.dryRun { - cmd := exec.Command("git", "tag", futureTag) - cmd.Dir = c.parentModPath - if b, err := cmd.Output(); err != nil { - return fmt.Errorf("unable to tag root module: %s", b) - } - } - log.Printf("Tagging Child module: %s/%s", childPrefix, c.childTagVersion) - if !c.dryRun { - cmd := exec.Command("git", "tag", fmt.Sprintf("%s/%s", childPrefix, c.childTagVersion)) - cmd.Dir = c.parentModPath - if b, err := cmd.Output(); err != nil { - return fmt.Errorf("unable to tag child module: %s", b) - } - } + log.Println("Successfully carved out module. Please run the following commands after your change is merged:") + fmt.Fprintf(os.Stdout, "git tag -a %s \n", futureTag) + fmt.Fprintf(os.Stdout, "git tag -a %s \n", childModTag) + fmt.Fprintf(os.Stdout, "git push origin ref/tags/%s\n", futureTag) + fmt.Fprintf(os.Stdout, "git push origin ref/tags/%s\n", childModTag) + return nil }