@@ -25,6 +25,8 @@ const (
25
25
tilConfigDir = "~/.config/til/"
26
26
tilConfigFile = "config.yml"
27
27
28
+ defaultCommitMsg = "build, save, push"
29
+
28
30
defaultConfig = `---
29
31
commitMessage: "build, save, push"
30
32
@@ -124,7 +126,7 @@ func main() {
124
126
}
125
127
126
128
if saveFlag {
127
- commitMsg := strings . Join ( os .Args [ 2 :], " " )
129
+ commitMsg := determineCommitMessage ( globalConfig , os .Args )
128
130
129
131
buildContent ()
130
132
save (commitMsg )
@@ -528,6 +530,24 @@ func createNewPage(title string) string {
528
530
return filePath
529
531
}
530
532
533
+ // determineCommitMessage figures out which commit message to save the repo with
534
+ // The order of precedence is:
535
+ // * message passed in via the -s flag
536
+ // * message defined in config.yml for the commitMessage key
537
+ // * message as a hard-coded constant, at top, in defaultCommitMsg
538
+ // Example:
539
+ // > til -t b -s this is message
540
+ func determineCommitMessage (cfg * config.Config , args []string ) string {
541
+ if flag .NArg () == 0 {
542
+ return cfg .UString ("commitMessage" , defaultCommitMsg )
543
+ }
544
+
545
+ msgOffset := len (args ) - flag .NArg ()
546
+ msg := strings .Join (args [msgOffset :], " " )
547
+
548
+ return msg
549
+ }
550
+
531
551
// listTargetDirectories writes the list of target directories in the configuration
532
552
// out to the terminal
533
553
func listTargetDirectories (cfg * config.Config ) {
@@ -664,19 +684,18 @@ func save(commitMsg string) {
664
684
Defeat (err )
665
685
}
666
686
667
- defaultCommitMsg , err1 := globalConfig .String ("commitMessage" )
668
687
defaultCommitEmail , err2 := globalConfig .String ("committerEmail" )
669
688
defaultCommitName , err3 := globalConfig .String ("committerName" )
670
- if err1 != nil || err2 != nil || err3 != nil {
689
+ if err2 != nil || err3 != nil {
671
690
Defeat (errors .New (errConfigValueRead ))
672
691
}
673
692
674
- if commitMsg == "" {
675
- // The incoming commitMsg is optional (if it is set, it probably came in
676
- // via command line args on -save). If it isn't set, we use the default
677
- // from the config file instead
678
- commitMsg = defaultCommitMsg
679
- }
693
+ // if commitMsg == "" {
694
+ // // The incoming commitMsg is optional (if it is set, it probably came in
695
+ // // via command line args on -save). If it isn't set, we use the default
696
+ // // from the config file instead
697
+ // commitMsg = defaultCommitMsg
698
+ // }
680
699
681
700
commit , err := w .Commit (commitMsg , & git.CommitOptions {
682
701
Author : & object.Signature {
0 commit comments