From 09d0122e26c9c37aad888b0e849cc4c168c66372 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 21 May 2025 17:18:05 +0800 Subject: [PATCH] refactor: rewrite `git pull` command If we do not provide pulling remote branch, it will auto fetch all branches first. Signed-off-by: leo --- src/Commands/Pull.cs | 5 +--- src/Models/RepositorySettings.cs | 12 -------- src/Resources/Locales/de_DE.axaml | 2 -- src/Resources/Locales/en_US.axaml | 2 -- src/Resources/Locales/es_ES.axaml | 2 -- src/Resources/Locales/fr_FR.axaml | 2 -- src/Resources/Locales/it_IT.axaml | 2 -- src/Resources/Locales/ja_JP.axaml | 2 -- src/Resources/Locales/pt_BR.axaml | 2 -- src/Resources/Locales/ru_RU.axaml | 2 -- src/Resources/Locales/ta_IN.axaml | 2 -- src/Resources/Locales/uk_UA.axaml | 2 -- src/Resources/Locales/zh_CN.axaml | 2 -- src/Resources/Locales/zh_TW.axaml | 2 -- src/ViewModels/Pull.cs | 49 ++++--------------------------- src/Views/Pull.axaml | 13 +------- 16 files changed, 7 insertions(+), 96 deletions(-) diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs index 2695b16b..698fbfce 100644 --- a/src/Commands/Pull.cs +++ b/src/Commands/Pull.cs @@ -2,7 +2,7 @@ { public class Pull : Command { - public Pull(string repo, string remote, string branch, bool useRebase, bool noTags) + public Pull(string repo, string remote, string branch, bool useRebase) { WorkingDirectory = repo; Context = repo; @@ -12,9 +12,6 @@ if (useRebase) Args += "--rebase=true "; - if (noTags) - Args += "--no-tags "; - Args += $"{remote} {branch}"; } } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 42db3bb6..34189073 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -80,18 +80,6 @@ namespace SourceGit.Models set; } = true; - public bool FetchWithoutTagsOnPull - { - get; - set; - } = false; - - public bool FetchAllBranchesOnPull - { - get; - set; - } = true; - public bool CheckSubmodulesOnPush { get; diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 337b0ce3..886a07cf 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -526,12 +526,10 @@ Worktree Informationen in `$GIT_COMMON_DIR/worktrees` löschen Pull Remote-Branch: - Alle Branches fetchen Lokaler Branch: Lokale Änderungen: Verwerfen Stashen & wieder anwenden - Ohne Tags fetchen Remote: Pull (Fetch & Merge) Rebase anstatt Merge verwenden diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index d4d0335e..a1b0578b 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -531,12 +531,10 @@ Prune worktree information in `$GIT_COMMON_DIR/worktrees` Pull Remote Branch: - Fetch all branches Into: Local Changes: Discard Stash & Reapply - Fetch without tags Update all submodules Remote: Pull (Fetch & Merge) diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml index 15155dc7..8e61b8cb 100644 --- a/src/Resources/Locales/es_ES.axaml +++ b/src/Resources/Locales/es_ES.axaml @@ -529,12 +529,10 @@ Podar información de worktree en `$GIT_COMMON_DIR/worktrees` Pull Rama Remota: - Fetch todas las ramas En: Cambios Locales: Descartar Stash & Reaplicar - Fetch sin etiquetas Remoto: Pull (Fetch & Merge) Usar rebase en lugar de merge diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 872fb2c6..0c3ab91b 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -508,12 +508,10 @@ Élaguer les information de worktree dans `$GIT_COMMON_DIR/worktrees` Pull Branche distante : - Fetch toutes les branches Dans : Changements locaux : Rejeter Stash & Réappliquer - Fetch sans les tags Dépôt distant : Pull (Fetch & Merge) Utiliser rebase au lieu de merge diff --git a/src/Resources/Locales/it_IT.axaml b/src/Resources/Locales/it_IT.axaml index d46785d5..23c31c6e 100644 --- a/src/Resources/Locales/it_IT.axaml +++ b/src/Resources/Locales/it_IT.axaml @@ -529,12 +529,10 @@ Potatura delle informazioni di worktree in `$GIT_COMMON_DIR/worktrees` Scarica Branch Remoto: - Recupera tutti i branch In: Modifiche Locali: Scarta Stasha e Riapplica - Recupera senza tag Remoto: Scarica (Recupera e Unisci) Riallineare anziché unire diff --git a/src/Resources/Locales/ja_JP.axaml b/src/Resources/Locales/ja_JP.axaml index a20c5ddc..ca29b985 100644 --- a/src/Resources/Locales/ja_JP.axaml +++ b/src/Resources/Locales/ja_JP.axaml @@ -508,12 +508,10 @@ `$GIT_DIR/worktrees` の作業ツリー情報を削除 プル ブランチ: - すべてのブランチをフェッチ 宛先: ローカルの変更: 破棄 スタッシュして再適用 - タグなしでフェッチ リモート: プル (フェッチ & マージ) マージの代わりにリベースを使用 diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index db304f18..7ce861e9 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -464,12 +464,10 @@ Podar informações de worktree em `$GIT_COMMON_DIR/worktrees` Puxar Branch Remoto: - Buscar todos os branches Para: Alterações Locais: Descartar Guardar & Reaplicar - Buscar sem tags Remoto: Puxar (Buscar & Mesclar) Usar rebase em vez de merge diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index 11419b76..91025188 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -531,12 +531,10 @@ Информация об обрезке рабочего каталога в «$GIT_COMMON_DIR/worktrees» Загрузить Ветка внешнего репозитория: - Извлечь все ветки В: Локальные изменения: Отклонить Отложить и применить повторно - Загрузить без меток Внешний репозиторий: Загрузить (Получить и слить) Использовать перемещение вместо слияния diff --git a/src/Resources/Locales/ta_IN.axaml b/src/Resources/Locales/ta_IN.axaml index 89fd4e12..71df97c0 100644 --- a/src/Resources/Locales/ta_IN.axaml +++ b/src/Resources/Locales/ta_IN.axaml @@ -508,12 +508,10 @@ `$GIT_COMMON_DIR/பணிமரங்கள்` இதில் பணிமரம் தகவலை கத்தரி இழு தொலை கிளை: - எல்லா கிளைகளையும் எடு இதனுள்: உள்ளக மாற்றங்கள்: நிராகரி பதுக்கிவை & மீண்டும் இடு - குறிச்சொற்கள் இல்லாமல் பெறு தொலை: இழு (எடுத்து ஒன்றிணை) ஒன்றிணை என்பதற்குப் பதிலாக மறுதளத்தைப் பயன்படுத்து diff --git a/src/Resources/Locales/uk_UA.axaml b/src/Resources/Locales/uk_UA.axaml index 18ba643e..297878a6 100644 --- a/src/Resources/Locales/uk_UA.axaml +++ b/src/Resources/Locales/uk_UA.axaml @@ -512,12 +512,10 @@ Видалити застарілу інформацію про робочі дерева в `$GIT_COMMON_DIR/worktrees` Pull (Витягти) Віддалена гілка: - Отримати всі гілки В: Локальні зміни: Скасувати Сховати та Застосувати - Отримати без тегів Віддалене сховище: Pull (Fetch & Merge) Використовувати rebase замість merge diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 545623b7..d42b2344 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -535,12 +535,10 @@ 清理在`$GIT_COMMON_DIR/worktrees`中的无效工作树信息 拉回(pull) 拉取分支 : - 拉取远程中的所有分支变更 本地分支 : 未提交更改 : 丢弃更改 贮藏并自动恢复 - 不拉取远程标签 同时更新所有子模块 远程 : 拉回(拉取并合并) diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index b40f62fe..b89a44c6 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -535,12 +535,10 @@ 清理在 `$GIT_COMMON_DIR/worktrees` 中的無效工作區資訊 拉取 (pull) 拉取分支: - 拉取遠端中的所有分支 本機分支: 未提交變更: 捨棄變更 擱置變更並自動復原 - 不拉取遠端標籤 同時更新所有子模組 遠端: 拉取 (提取並合併) diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index 14451e98..b19ed9a5 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -50,18 +50,6 @@ namespace SourceGit.ViewModels set => _repo.Settings.PreferRebaseInsteadOfMerge = value; } - public bool FetchAllBranches - { - get => _repo.Settings.FetchAllBranchesOnPull; - set => _repo.Settings.FetchAllBranchesOnPull = value; - } - - public bool NoTags - { - get => _repo.Settings.FetchWithoutTagsOnPull; - set => _repo.Settings.FetchWithoutTagsOnPull = value; - } - public bool IsRecurseSubmoduleVisible { get => _repo.Submodules.Count > 0; @@ -155,38 +143,11 @@ namespace SourceGit.ViewModels } } - bool rs; - if (FetchAllBranches) - { - rs = new Commands.Fetch( - _repo.FullPath, - _selectedRemote.Name, - NoTags, - false).Use(log).Exec(); - if (!rs) - { - log.Complete(); - CallUIThread(() => _repo.SetWatcherEnabled(true)); - return false; - } - - _repo.MarkFetched(); - - // Use merge/rebase instead of pull as fetch is done manually. - if (UseRebase) - rs = new Commands.Rebase(_repo.FullPath, _selectedBranch.FriendlyName, false).Use(log).Exec(); - else - rs = new Commands.Merge(_repo.FullPath, _selectedBranch.FriendlyName, "").Use(log).Exec(); - } - else - { - rs = new Commands.Pull( - _repo.FullPath, - _selectedRemote.Name, - _selectedBranch.Name, - UseRebase, - NoTags).Use(log).Exec(); - } + bool rs = new Commands.Pull( + _repo.FullPath, + _selectedRemote.Name, + !string.IsNullOrEmpty(_current.Upstream) && _current.Upstream.Equals(_selectedBranch.FullName) ? string.Empty : _selectedBranch.Name, + UseRebase).Use(log).Exec(); if (rs) { diff --git a/src/Views/Pull.axaml b/src/Views/Pull.axaml index 1c438b8b..96d308b4 100644 --- a/src/Views/Pull.axaml +++ b/src/Views/Pull.axaml @@ -19,8 +19,6 @@ - - @@ -94,20 +92,11 @@ - - - - -