Skip to content

Commit af277b2

Browse files
committed
feat(release): support Sapling VCS
1 parent 5e9cd94 commit af277b2

File tree

1 file changed

+56
-17
lines changed

1 file changed

+56
-17
lines changed

dist/release.go

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var Steps []Step = []Step{
3737
Run: func() {
3838
uncommittedChanges := GetUncommittedChanges()
3939
if len(uncommittedChanges) > 0 {
40-
fmt.Printf("fatal error: uncommitted changes in Git:\n")
40+
fmt.Printf("fatal error: uncommitted changes:\n")
4141
for _, line := range uncommittedChanges {
4242
fmt.Printf(" %s\n", line)
4343
}
@@ -534,15 +534,25 @@ func UpdateReleaseVersions(fileContent []byte, pathForDebugging string) []byte {
534534
}
535535

536536
func GetCurrentCommitHash() string {
537-
commitHash, err := GetCurrentGitCommitHash()
538-
if err != nil {
539-
exitErr, ok := err.(*exec.ExitError)
540-
if ok {
541-
log.Printf("%s", exitErr.Stderr)
542-
}
543-
Stopf("failed to get Git commit hash: %v", err)
537+
commitHash, gitErr := GetCurrentGitCommitHash()
538+
if gitErr == nil {
539+
return commitHash
544540
}
545-
return commitHash
541+
commitHash, saplingErr := GetCurrentSaplingCommitHash()
542+
if saplingErr == nil {
543+
return commitHash
544+
}
545+
546+
exitErr, ok := gitErr.(*exec.ExitError)
547+
if ok {
548+
log.Printf("Git: %s", exitErr.Stderr)
549+
}
550+
exitErr, ok = saplingErr.(*exec.ExitError)
551+
if ok {
552+
log.Printf("Sapling: %s", exitErr.Stderr)
553+
}
554+
Stopf("failed to get commit hash:\nGit: %v\nSapling: %v", gitErr, saplingErr)
555+
return "(invalid)"
546556
}
547557

548558
func GetCurrentGitCommitHash() (string, error) {
@@ -554,16 +564,35 @@ func GetCurrentGitCommitHash() (string, error) {
554564
return strings.TrimSpace(string(stdout)), nil
555565
}
556566

557-
func GetUncommittedChanges() []string {
558-
changes, err := GetGitUncommittedChanges()
567+
func GetCurrentSaplingCommitHash() (string, error) {
568+
cmd := exec.Command("sl", "log", "--template", "{node}", "--rev", ".")
569+
stdout, err := cmd.Output()
559570
if err != nil {
560-
exitErr, ok := err.(*exec.ExitError)
561-
if ok {
562-
log.Printf("%s", exitErr.Stderr)
563-
}
564-
Stopf("failed to get uncommitted changes: %v", err)
571+
return "", err
572+
}
573+
return strings.TrimSpace(string(stdout)), nil
574+
}
575+
576+
func GetUncommittedChanges() []string {
577+
changes, gitErr := GetGitUncommittedChanges()
578+
if gitErr == nil {
579+
return changes
580+
}
581+
changes, saplingErr := GetSaplingUncommittedChanges()
582+
if saplingErr == nil {
583+
return changes
584+
}
585+
586+
exitErr, ok := gitErr.(*exec.ExitError)
587+
if ok {
588+
log.Printf("Git: %s", exitErr.Stderr)
565589
}
566-
return changes
590+
exitErr, ok = saplingErr.(*exec.ExitError)
591+
if ok {
592+
log.Printf("Sapling: %s", exitErr.Stderr)
593+
}
594+
Stopf("failed to get uncommitted changes:\nGit: %v\nSapling: %v", gitErr, saplingErr)
595+
return nil
567596
}
568597

569598
func GetGitUncommittedChanges() ([]string, error) {
@@ -576,6 +605,16 @@ func GetGitUncommittedChanges() ([]string, error) {
576605
return changes, nil
577606
}
578607

608+
func GetSaplingUncommittedChanges() ([]string, error) {
609+
cmd := exec.Command("sl", "status", "--added", "--modified", "--removed")
610+
stdout, err := cmd.Output()
611+
if err != nil {
612+
return nil, err
613+
}
614+
changes := RemoveEmptyStrings(StringLines(string(stdout)))
615+
return changes, nil
616+
}
617+
579618
type VersionFileInfo struct {
580619
VersionNumber string
581620
ReleaseDate time.Time

0 commit comments

Comments
 (0)