feat: implement phase 1 sync functionality

- Add lnk status command to show repository sync status

- Add lnk push command for smart staging, committing, and pushing

- Add lnk pull command with automatic symlink restoration

- Add comprehensive sync functionality to git and core packages

- Add 5 new integration tests for sync commands (17 total tests)

- Update README with sync workflow examples and documentation

- Support commits ahead/behind tracking relative to remote

- Implement change detection to avoid empty commits

- Add graceful error handling for missing remotes

Closes: Phase 1 sync implementation
This commit is contained in:
Yar Kravtsov
2025-05-24 07:20:19 +03:00
parent 8ece50c5d7
commit 88b3fbd238
7 changed files with 736 additions and 62 deletions

36
cmd/pull.go Normal file
View File

@@ -0,0 +1,36 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/yarlson/lnk/internal/core"
)
var pullCmd = &cobra.Command{
Use: "pull",
Short: "Pull changes from remote and restore symlinks",
Long: "Fetches changes from remote repository and automatically restores symlinks for all managed files.",
RunE: func(cmd *cobra.Command, args []string) error {
lnk := core.NewLnk()
restored, err := lnk.Pull()
if err != nil {
return fmt.Errorf("failed to pull changes: %w", err)
}
if len(restored) > 0 {
fmt.Printf("Successfully pulled changes and restored %d symlink(s):\n", len(restored))
for _, file := range restored {
fmt.Printf(" - %s\n", file)
}
} else {
fmt.Println("Successfully pulled changes (no symlinks needed restoration)")
}
return nil
},
}
func init() {
rootCmd.AddCommand(pullCmd)
}