Skip to content

Commit

Permalink
fix: re-download remotes when called install with -f (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Apr 5, 2024
1 parent 9814621 commit 81a8375
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions internal/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *Repository) RemotesFolder() string {
// SyncRemote clones or pulls the latest changes for a git repository that was
// specified as a remote config repository. If successful, the path to the root
// of the repository will be returned.
func (r *Repository) SyncRemote(url, ref string) error {
func (r *Repository) SyncRemote(url, ref string, force bool) error {
remotesPath := r.RemotesFolder()

err := r.Fs.MkdirAll(remotesPath, remotesFolderMode)
Expand All @@ -42,9 +42,16 @@ func (r *Repository) SyncRemote(url, ref string) error {
directoryName := remoteDirectoryName(url, ref)
remotePath := filepath.Join(remotesPath, directoryName)

_, err = r.Fs.Stat(remotePath)
if err == nil {
return r.updateRemote(remotePath, ref)
if force {
err = r.Fs.RemoveAll(remotePath)
if err != nil {
return err
}
} else {
_, err = r.Fs.Stat(remotePath)
if err == nil {
return r.updateRemote(remotePath, ref)
}
}

return r.cloneRemote(remotesPath, directoryName, url, ref)
Expand Down
2 changes: 1 addition & 1 deletion internal/lefthook/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (l *Lefthook) Install(force bool) error {

for _, remote := range cfg.Remotes {
if remote.Configured() {
if err := l.repo.SyncRemote(remote.GitURL, remote.Ref); err != nil {
if err := l.repo.SyncRemote(remote.GitURL, remote.Ref, force); err != nil {
log.Warnf("Couldn't sync remotes. Will continue without them: %s", err)
} else {
// Reread the config file with synced remotes
Expand Down

0 comments on commit 81a8375

Please sign in to comment.