Fetch from remotes
(
remote: str | None = None,
all_remotes: bool = False,
include_tags: YesNoOnce = YesNoOnce.NO,
force: bool = False,
branch: str | None = None,
only_tags: bool = False,
)
| 234 | |
| 235 | |
| 236 | def fetch( |
| 237 | remote: str | None = None, |
| 238 | all_remotes: bool = False, |
| 239 | include_tags: YesNoOnce = YesNoOnce.NO, |
| 240 | force: bool = False, |
| 241 | branch: str | None = None, |
| 242 | only_tags: bool = False, |
| 243 | ) -> str: |
| 244 | """Fetch from remotes""" |
| 245 | |
| 246 | if remote is not None and all_remotes: |
| 247 | raise RuntimeError("all_remotes must be false when a remote is specified") |
| 248 | |
| 249 | if branch is not None and remote is None: |
| 250 | raise RuntimeError("remote must be specified when a branch is specified") |
| 251 | |
| 252 | if branch is not None and only_tags: |
| 253 | raise RuntimeError("branch must not be specified if only_tags is set") |
| 254 | |
| 255 | command = ["git", "fetch"] |
| 256 | if spawn.capture(["git", "rev-parse", "--is-shallow-repository"]) == "true": |
| 257 | command.append("--unshallow") |
| 258 | |
| 259 | if remote: |
| 260 | command.append(remote) |
| 261 | |
| 262 | if branch: |
| 263 | command.append(branch) |
| 264 | |
| 265 | if all_remotes: |
| 266 | command.append("--all") |
| 267 | |
| 268 | fetch_tags = ( |
| 269 | include_tags == YesNoOnce.YES |
| 270 | # fetch tags again if used with force (tags might have changed) |
| 271 | or (include_tags == YesNoOnce.ONCE and force) |
| 272 | or ( |
| 273 | include_tags == YesNoOnce.ONCE |
| 274 | and remote not in fetched_tags_in_remotes |
| 275 | and "*" not in fetched_tags_in_remotes |
| 276 | ) |
| 277 | ) |
| 278 | |
| 279 | if fetch_tags: |
| 280 | command.append("--tags") |
| 281 | |
| 282 | if force: |
| 283 | command.append("--force") |
| 284 | |
| 285 | if not fetch_tags and only_tags: |
| 286 | return "" |
| 287 | |
| 288 | output = spawn.capture(command).strip() |
| 289 | |
| 290 | if fetch_tags: |
| 291 | fetched_tags_in_remotes.add(remote) |
| 292 | |
| 293 | if all_remotes: |