feat(sync): adds --message flag for manual commit message
This commit is contained in:
parent
ac847f34ca
commit
cf7dbf5bee
2 changed files with 18 additions and 4 deletions
|
|
@ -322,6 +322,9 @@ If you're ahead of your Git repo, syncing will add your changes, commit them, an
|
||||||
```bash
|
```bash
|
||||||
# Sync with Git
|
# Sync with Git
|
||||||
pda sync
|
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.
|
`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.
|
||||||
|
|
|
||||||
19
cmd/sync.go
19
cmd/sync.go
|
|
@ -34,15 +34,17 @@ var syncCmd = &cobra.Command{
|
||||||
Short: "Manually sync your stores with Git",
|
Short: "Manually sync your stores with Git",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return sync(true)
|
msg, _ := cmd.Flags().GetString("message")
|
||||||
|
return sync(true, msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
syncCmd.Flags().StringP("message", "m", "", "Custom commit message (defaults to timestamp)")
|
||||||
rootCmd.AddCommand(syncCmd)
|
rootCmd.AddCommand(syncCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sync(manual bool) error {
|
func sync(manual bool, customMsg string) error {
|
||||||
repoDir, err := ensureVCSInitialized()
|
repoDir, err := ensureVCSInitialized()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -62,7 +64,13 @@ func sync(manual bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if changed {
|
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 {
|
if err := runGit(repoDir, "commit", "-m", msg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -109,6 +117,9 @@ func sync(manual bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if manual {
|
||||||
|
okf("in sync!")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,5 +130,5 @@ func autoSync() error {
|
||||||
if _, err := ensureVCSInitialized(); err != nil {
|
if _, err := ensureVCSInitialized(); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return sync(false)
|
return sync(false, "")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue