feat(sync): adds --message flag for manual commit message

This commit is contained in:
Lewis Wynne 2026-02-11 17:49:02 +00:00
parent ac847f34ca
commit cf7dbf5bee
2 changed files with 18 additions and 4 deletions

View file

@ -322,6 +322,9 @@ If you're ahead of your Git repo, syncing will add your changes, commit them, an
```bash
# Sync with Git
pda sync
# With a custom commit message.
pda sync -m "added production credentials"
```
`pda!` supports some automation via its config. There are options for `git.auto_commit`, `git.auto_fetch`, and `git.auto_push`. Any of these operations will slow down `pda!` because it means versioning with every change, but it does effectively guarantee never managing to desync oneself and requiring manual fixes, and reduces the frequency with which one will need to manually run the sync command.

View file

@ -34,15 +34,17 @@ var syncCmd = &cobra.Command{
Short: "Manually sync your stores with Git",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return sync(true)
msg, _ := cmd.Flags().GetString("message")
return sync(true, msg)
},
}
func init() {
syncCmd.Flags().StringP("message", "m", "", "Custom commit message (defaults to timestamp)")
rootCmd.AddCommand(syncCmd)
}
func sync(manual bool) error {
func sync(manual bool, customMsg string) error {
repoDir, err := ensureVCSInitialized()
if err != nil {
return err
@ -62,7 +64,13 @@ func sync(manual bool) error {
return err
}
if changed {
msg := fmt.Sprintf("sync: %s", time.Now().UTC().Format(time.RFC3339))
msg := customMsg
if msg == "" {
msg = fmt.Sprintf("sync: %s", time.Now().UTC().Format(time.RFC3339))
if manual {
printHint("use -m to set a custom commit message")
}
}
if err := runGit(repoDir, "commit", "-m", msg); err != nil {
return err
}
@ -109,6 +117,9 @@ func sync(manual bool) error {
}
}
if manual {
okf("in sync!")
}
return nil
}
@ -119,5 +130,5 @@ func autoSync() error {
if _, err := ensureVCSInitialized(); err != nil {
return nil
}
return sync(false)
return sync(false, "")
}