- origin_path = os.path.join(path, 'refs', 'remotes', 'origin')
- packed_refs = readfile(os.path.join(path, 'packed-refs'))
- if os.path.exists(origin_path) or 'refs/remotes/origin/' in packed_refs:
- cmd = ['git', '--git-dir', path, 'remote', 'prune', 'origin']
+ origin_path = path / 'refs' / 'remotes' / 'origin'
+ # Delete remote HEAD as we don't need it, and it might be stale.
+ head = origin_path / 'HEAD'
+ head.unlink(missing_ok=True)
+ packed_refs = readfile(path / 'packed-refs')
+ if origin_path.exists() or 'refs/remotes/origin/' in packed_refs:
+ cmd = ['git', '--git-dir', str(path), 'remote', 'prune', 'origin']