@@ -53,14 +53,27 @@ func Clone(repoURL string, dryRun bool) error {
5353 }
5454 } else {
5555 if dryRun {
56- fmt .Printf ("[DRY-RUN] Would pull latest dotfiles at %s\n " , dotfilesPath )
56+ fmt .Printf ("[DRY-RUN] Would sync latest dotfiles at %s\n " , dotfilesPath )
5757 return nil
5858 }
59- fmt .Printf ("Dotfiles already exist at %s, pulling latest changes\n " , dotfilesPath )
60- cmd := exec .Command ("git" , "-C" , dotfilesPath , "pull" )
61- cmd .Stdout = os .Stdout
62- cmd .Stderr = os .Stderr
63- return cmd .Run ()
59+ fmt .Printf ("Dotfiles already exist at %s, syncing latest changes\n " , dotfilesPath )
60+ // Use fetch + reset instead of pull to handle dirty states
61+ // (unmerged files, mid-rebase, etc.) gracefully.
62+ fetchCmd := exec .Command ("git" , "-C" , dotfilesPath , "fetch" , "origin" )
63+ fetchCmd .Stdout = os .Stdout
64+ fetchCmd .Stderr = os .Stderr
65+ if err := fetchCmd .Run (); err != nil {
66+ return err
67+ }
68+ branchOut , err := exec .Command ("git" , "-C" , dotfilesPath , "rev-parse" , "--abbrev-ref" , "HEAD" ).Output ()
69+ if err != nil {
70+ return fmt .Errorf ("failed to detect dotfiles branch: %w" , err )
71+ }
72+ branch := strings .TrimSpace (string (branchOut ))
73+ resetCmd := exec .Command ("git" , "-C" , dotfilesPath , "reset" , "--hard" , "origin/" + branch )
74+ resetCmd .Stdout = os .Stdout
75+ resetCmd .Stderr = os .Stderr
76+ return resetCmd .Run ()
6477 }
6578 }
6679
0 commit comments