Skip to content

Commit c355eb8

Browse files
authored
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.
1 parent eabc63a commit c355eb8

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

internal/carver/cmd/_tidyhack_tmpl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
package {{.Package}}
2020

2121
// 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
22-
import _ "{{.RootMod}}"
22+
import _ "{{.RootMod}}"

internal/carver/cmd/main.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func main() {
9494
flag.Usage()
9595
os.Exit(1)
9696
}
97-
log.Println("Successfully carved out module. Changes are ready to be pushed.")
9897
}
9998

10099
func (c *carver) Run() error {
@@ -304,6 +303,7 @@ func (c *carver) CreateGitTags(rootMod *modInfo) error {
304303
return err
305304
}
306305
childPrefix := strings.TrimPrefix(strings.TrimPrefix(c.childModPath, rootMod.filePath), "/")
306+
childModTag := fmt.Sprintf("%s/%s", childPrefix, c.childTagVersion)
307307
log.Println("Commiting changes")
308308
if !c.dryRun {
309309
cmd := exec.Command("git", "add", "-A")
@@ -312,28 +312,18 @@ func (c *carver) CreateGitTags(rootMod *modInfo) error {
312312
return fmt.Errorf("unable to add changes: %s", b)
313313
}
314314
cmd = exec.Command("git", "commit", "-m",
315-
fmt.Sprintf("chore(%s): carve out sub-module", childPrefix))
315+
fmt.Sprintf("chore(%s): carve out sub-module\n\nThis commit will be tagged %s and %s.", childPrefix, futureTag, childModTag))
316316
cmd.Dir = c.parentModPath
317317
if b, err := cmd.Output(); err != nil {
318318
return fmt.Errorf("unable to commit changes: %s", b)
319319
}
320320
}
321-
log.Printf("Tagging Root module: %s", futureTag)
322-
if !c.dryRun {
323-
cmd := exec.Command("git", "tag", futureTag)
324-
cmd.Dir = c.parentModPath
325-
if b, err := cmd.Output(); err != nil {
326-
return fmt.Errorf("unable to tag root module: %s", b)
327-
}
328-
}
329-
log.Printf("Tagging Child module: %s/%s", childPrefix, c.childTagVersion)
330-
if !c.dryRun {
331-
cmd := exec.Command("git", "tag", fmt.Sprintf("%s/%s", childPrefix, c.childTagVersion))
332-
cmd.Dir = c.parentModPath
333-
if b, err := cmd.Output(); err != nil {
334-
return fmt.Errorf("unable to tag child module: %s", b)
335-
}
336-
}
321+
log.Println("Successfully carved out module. Please run the following commands after your change is merged:")
322+
fmt.Fprintf(os.Stdout, "git tag -a %s <COMMIT-SHA>\n", futureTag)
323+
fmt.Fprintf(os.Stdout, "git tag -a %s <COMMIT-SHA>\n", childModTag)
324+
fmt.Fprintf(os.Stdout, "git push origin ref/tags/%s\n", futureTag)
325+
fmt.Fprintf(os.Stdout, "git push origin ref/tags/%s\n", childModTag)
326+
337327
return nil
338328
}
339329

0 commit comments

Comments
 (0)