Skip to content

Commit

Permalink
Run 'git fetch' with '--force' if no revision given
Browse files Browse the repository at this point in the history
When we run 'git fetch' without a specific revision we
usually run it with '--all' which fetches tags (among
other things).

We now have movable tags in our plugin repositories
and when a tag is moved a 'git fetch' or 'checkout'
will produce a 'would clobber existing tag' error on
the command line, which warns the user that the tag
that has already been checked into the local clone
will be overwritten.

This commit fixes that error by running 'fetch' with
'--force' if we do not specify a revision.
  • Loading branch information
snim2 committed Mar 11, 2024
1 parent 657c9a8 commit 5ba0a83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed
- Fixed 'would clobber existing tag' error when running 'git fetch'

## [2.4.0] - 2024-01-29

### Changed
Expand Down
4 changes: 2 additions & 2 deletions src/Git/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function is_repo()

public function checkout($revision)
{
list($output, $return) = $this->run_command(['git', 'fetch', '-a', '&&', 'git', 'checkout', $revision]);
list($output, $return) = $this->run_command(['git', 'fetch', '-a', '--force', '&&', 'git', 'checkout', $revision]);

return $this->check_git_return('Checkout failed', $return, $output);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public function remote_revision_commit($revision)

public function fetch()
{
list($output, $return) = $this->run_command(['git', 'fetch', '-a']);
list($output, $return) = $this->run_command(['git', 'fetch', '-a', '--force']);

return $this->check_git_return('Checkout failed', $return, $output);
}
Expand Down

0 comments on commit 5ba0a83

Please sign in to comment.