Skip to content

Commit

Permalink
fix: Allow changing refs for remote (#363)
Browse files Browse the repository at this point in the history
Support changing ref option value
  • Loading branch information
mrexox authored Nov 15, 2022
1 parent a5e6a23 commit 2a376a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)

- fix: Allow changing refs for remote ([PR #363](https://github.com/evilmartians/lefthook/pull/363) by @mrexox)

## 1.2.0 (2022-11-7)

- fix: Full support for interactive commands and scripts ([PR #352](https://github.com/evilmartians/lefthook/pull/352) by @mrexox)
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ remote:
ref: v1.0.0
```

> :warning: Please, note that if you initially had `ref` option, ran `lefthook install`, and then removed it, lefthook won't decide which branch/tag to use as a ref. So, if you added it once, please, use it always to avoid issues in local setups.

### `config`

Expand Down
24 changes: 17 additions & 7 deletions internal/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,24 @@ func (r *Repository) SyncRemote(url, ref string) error {
func (r *Repository) updateRemote(path, ref string) error {
log.Debugf("Updating remote config repository: %s", path)

cmdFetch := []string{"git", "-C", path, "pull", "--quiet"}
if len(ref) == 0 {
cmdFetch = append(cmdFetch, "origin", ref)
}
if len(ref) != 0 {
cmdFetch := []string{"git", "-C", path, "fetch", "--quiet", "--depth", "1", "origin", ref}
_, err := execGit(strings.Join(cmdFetch, " "))
if err != nil {
return err
}

_, err := execGit(strings.Join(cmdFetch, " "))
if err != nil {
return err
cmdFetch = []string{"git", "-C", path, "checkout", "FETCH_HEAD"}
_, err = execGit(strings.Join(cmdFetch, " "))
if err != nil {
return err
}
} else {
cmdFetch := []string{"git", "-C", path, "pull", "--quiet"}
_, err := execGit(strings.Join(cmdFetch, " "))
if err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 2a376a7

Please sign in to comment.