1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-29 22:07:13 +02:00

Support to reset the current branch to a selected branch upstream (#2940)

This commit is contained in:
Stefan Haller 2023-09-06 08:45:00 +02:00 committed by GitHub
commit 37048911ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 272 additions and 119 deletions

View File

@ -155,7 +155,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
<kbd>T</kbd>: Create tag <kbd>T</kbd>: Create tag
<kbd>g</kbd>: View reset options <kbd>g</kbd>: View reset options
<kbd>R</kbd>: Rename branch <kbd>R</kbd>: Rename branch
<kbd>u</kbd>: Set/Unset upstream <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: View commits <kbd>&lt;enter&gt;</kbd>: View commits
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -227,7 +227,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
<kbd>T</kbd>: タグを作成 <kbd>T</kbd>: タグを作成
<kbd>g</kbd>: View reset options <kbd>g</kbd>: View reset options
<kbd>R</kbd>: ブランチ名を変更 <kbd>R</kbd>: ブランチ名を変更
<kbd>u</kbd>: Set/Unset upstream <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: コミットを閲覧 <kbd>&lt;enter&gt;</kbd>: コミットを閲覧
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -190,7 +190,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
<kbd>T</kbd>: 태그를 생성 <kbd>T</kbd>: 태그를 생성
<kbd>g</kbd>: View reset options <kbd>g</kbd>: View reset options
<kbd>R</kbd>: 브랜치 이름 변경 <kbd>R</kbd>: 브랜치 이름 변경
<kbd>u</kbd>: Set/Unset upstream <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: 커밋 보기 <kbd>&lt;enter&gt;</kbd>: 커밋 보기
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -97,7 +97,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
<kbd>T</kbd>: Creëer tag <kbd>T</kbd>: Creëer tag
<kbd>g</kbd>: Bekijk reset opties <kbd>g</kbd>: Bekijk reset opties
<kbd>R</kbd>: Hernoem branch <kbd>R</kbd>: Hernoem branch
<kbd>u</kbd>: Set/Unset upstream <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: Bekijk commits <kbd>&lt;enter&gt;</kbd>: Bekijk commits
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -113,7 +113,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
<kbd>T</kbd>: Create tag <kbd>T</kbd>: Create tag
<kbd>g</kbd>: Wyświetl opcje resetu <kbd>g</kbd>: Wyświetl opcje resetu
<kbd>R</kbd>: Rename branch <kbd>R</kbd>: Rename branch
<kbd>u</kbd>: Set/Unset upstream <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: View commits <kbd>&lt;enter&gt;</kbd>: View commits
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -188,7 +188,7 @@ _Связки клавиш_
<kbd>T</kbd>: Создать тег <kbd>T</kbd>: Создать тег
<kbd>g</kbd>: Просмотреть параметры сброса <kbd>g</kbd>: Просмотреть параметры сброса
<kbd>R</kbd>: Переименовать ветку <kbd>R</kbd>: Переименовать ветку
<kbd>u</kbd>: Установить/убрать upstream-ветку <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: Просмотреть коммиты <kbd>&lt;enter&gt;</kbd>: Просмотреть коммиты
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -91,7 +91,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
<kbd>T</kbd>: 创建标签 <kbd>T</kbd>: 创建标签
<kbd>g</kbd>: 查看重置选项 <kbd>g</kbd>: 查看重置选项
<kbd>R</kbd>: 重命名分支 <kbd>R</kbd>: 重命名分支
<kbd>u</kbd>: Set/Unset upstream <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: 查看提交 <kbd>&lt;enter&gt;</kbd>: 查看提交
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -263,7 +263,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B_
<kbd>T</kbd>: 建立標籤 <kbd>T</kbd>: 建立標籤
<kbd>g</kbd>: 檢視重設選項 <kbd>g</kbd>: 檢視重設選項
<kbd>R</kbd>: 重新命名分支 <kbd>R</kbd>: 重新命名分支
<kbd>u</kbd>: 設定/取消設定上游 <kbd>u</kbd>: View upstream options
<kbd>w</kbd>: View worktree options <kbd>w</kbd>: View worktree options
<kbd>&lt;enter&gt;</kbd>: 檢視提交 <kbd>&lt;enter&gt;</kbd>: 檢視提交
<kbd>/</kbd>: Filter the current view by text <kbd>/</kbd>: Filter the current view by text

View File

@ -108,7 +108,8 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty
{ {
Key: opts.GetKey(opts.Config.Branches.SetUpstream), Key: opts.GetKey(opts.Config.Branches.SetUpstream),
Handler: self.checkSelected(self.setUpstream), Handler: self.checkSelected(self.setUpstream),
Description: self.c.Tr.SetUnsetUpstream, Description: self.c.Tr.ViewBranchUpstreamOptions,
Tooltip: self.c.Tr.ViewBranchUpstreamOptionsTooltip,
OpensMenu: true, OpensMenu: true,
}, },
} }
@ -139,34 +140,57 @@ func (self *BranchesController) GetOnRenderToMain() func() error {
} }
func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error { func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error {
return self.c.Menu(types.CreateMenuOptions{ options := []*types.MenuItem{
Title: self.c.Tr.Actions.SetUnsetUpstream, {
Items: []*types.MenuItem{ LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream},
{ OnPress: func() error {
LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream}, branch := self.context().GetSelected()
OnPress: func() error { if branch == nil {
branch := self.context().GetSelected() return nil
if branch == nil { }
return nil
if !branch.RemoteBranchStoredLocally() {
return self.c.ErrorMsg(self.c.Tr.DivergenceNoUpstream)
}
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
Ref: branch,
TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), branch.ShortUpstreamRefName()),
RefToShowDivergenceFrom: branch.FullUpstreamRefName(),
Context: self.context(),
ShowBranchHeads: false,
})
},
Key: 'v',
},
{
LabelColumns: []string{self.c.Tr.UnsetUpstream},
OnPress: func() error {
if err := self.c.Git().Branch.UnsetUpstream(selectedBranch.Name); err != nil {
return self.c.Error(err)
}
if err := self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{
types.BRANCHES,
types.COMMITS,
},
}); err != nil {
return self.c.Error(err)
}
return nil
},
Key: 'u',
},
{
LabelColumns: []string{self.c.Tr.SetUpstream},
OnPress: func() error {
return self.c.Helpers().Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error {
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
if err != nil {
return self.c.Error(err)
} }
if !branch.RemoteBranchStoredLocally() { if err := self.c.Git().Branch.SetUpstream(upstreamRemote, upstreamBranch, selectedBranch.Name); err != nil {
return self.c.ErrorMsg(self.c.Tr.DivergenceNoUpstream)
}
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
Ref: branch,
TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), branch.ShortUpstreamRefName()),
RefToShowDivergenceFrom: branch.FullUpstreamRefName(),
Context: self.context(),
ShowBranchHeads: false,
})
},
Key: 'v',
},
{
LabelColumns: []string{self.c.Tr.UnsetUpstream},
OnPress: func() error {
if err := self.c.Git().Branch.UnsetUpstream(selectedBranch.Name); err != nil {
return self.c.Error(err) return self.c.Error(err)
} }
if err := self.c.Refresh(types.RefreshOptions{ if err := self.c.Refresh(types.RefreshOptions{
@ -179,36 +203,55 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
return self.c.Error(err) return self.c.Error(err)
} }
return nil return nil
}, })
Key: 'u',
},
{
LabelColumns: []string{self.c.Tr.SetUpstream},
OnPress: func() error {
return self.c.Helpers().Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error {
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
if err != nil {
return self.c.Error(err)
}
if err := self.c.Git().Branch.SetUpstream(upstreamRemote, upstreamBranch, selectedBranch.Name); err != nil {
return self.c.Error(err)
}
if err := self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{
types.BRANCHES,
types.COMMITS,
},
}); err != nil {
return self.c.Error(err)
}
return nil
})
},
Key: 's',
}, },
Key: 's',
}, },
}
if selectedBranch.IsTrackingRemote() {
upstream := fmt.Sprintf("%s/%s", selectedBranch.UpstreamRemote, selectedBranch.Name)
upstreamResetOptions := utils.ResolvePlaceholderString(
self.c.Tr.ViewUpstreamResetOptions,
map[string]string{"upstream": upstream},
)
upstreamResetTooltip := utils.ResolvePlaceholderString(
self.c.Tr.ViewUpstreamResetOptionsTooltip,
map[string]string{"upstream": upstream},
)
options = append(options, &types.MenuItem{
LabelColumns: []string{upstreamResetOptions},
OpensMenu: true,
OnPress: func() error {
if selectedBranch.RemoteBranchNotStoredLocally() {
return self.c.ErrorMsg(self.c.Tr.UpstreamNotStoredLocallyError)
}
err := self.c.Helpers().Refs.CreateGitResetMenu(upstream)
if err != nil {
return self.c.Error(err)
}
return nil
},
Tooltip: upstreamResetTooltip,
Key: 'g',
})
} else {
options = append(options, &types.MenuItem{
LabelColumns: []string{self.c.Tr.ViewUpstreamDisabledResetOptions},
OpensMenu: true,
OnPress: func() error {
return self.c.ErrorMsg(self.c.Tr.UpstreamNotSetError)
},
Tooltip: self.c.Tr.UpstreamNotSetError,
Key: 'g',
})
}
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.BranchUpstreamOptionsTitle,
Items: options,
}) })
} }

View File

@ -352,6 +352,9 @@ type TranslationSet struct {
DivergenceNoUpstream string DivergenceNoUpstream string
DivergenceSectionHeaderLocal string DivergenceSectionHeaderLocal string
DivergenceSectionHeaderRemote string DivergenceSectionHeaderRemote string
ViewUpstreamResetOptions string
ViewUpstreamResetOptionsTooltip string
ViewUpstreamDisabledResetOptions string
SetUpstreamTitle string SetUpstreamTitle string
SetUpstreamMessage string SetUpstreamMessage string
EditRemote string EditRemote string
@ -396,7 +399,11 @@ type TranslationSet struct {
KeybindingsMenuSectionGlobal string KeybindingsMenuSectionGlobal string
KeybindingsMenuSectionNavigation string KeybindingsMenuSectionNavigation string
RenameBranch string RenameBranch string
SetUnsetUpstream string ViewBranchUpstreamOptions string
BranchUpstreamOptionsTitle string
ViewBranchUpstreamOptionsTooltip string
UpstreamNotStoredLocallyError string
UpstreamNotSetError string
NewGitFlowBranchPrompt string NewGitFlowBranchPrompt string
RenameBranchWarning string RenameBranchWarning string
OpenMenu string OpenMenu string
@ -654,7 +661,6 @@ type Actions struct {
Merge string Merge string
RebaseBranch string RebaseBranch string
RenameBranch string RenameBranch string
SetUnsetUpstream string
CreateBranch string CreateBranch string
FastForwardBranch string FastForwardBranch string
CherryPick string CherryPick string
@ -1137,6 +1143,9 @@ func EnglishTranslationSet() TranslationSet {
DivergenceNoUpstream: "Cannot show divergence of a branch that has no (locally tracked) upstream", DivergenceNoUpstream: "Cannot show divergence of a branch that has no (locally tracked) upstream",
DivergenceSectionHeaderLocal: "Local", DivergenceSectionHeaderLocal: "Local",
DivergenceSectionHeaderRemote: "Remote", DivergenceSectionHeaderRemote: "Remote",
ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",
ViewUpstreamResetOptionsTooltip: "View options for resetting the checked-out branch onto {{upstream}}. Note: this will not reset the selected branch onto the upstream, it will reset the checked-out branch onto the upstream",
ViewUpstreamDisabledResetOptions: "Reset checked-out branch onto upstream of selected branch",
SetUpstreamTitle: "Set upstream branch", SetUpstreamTitle: "Set upstream branch",
SetUpstreamMessage: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'", SetUpstreamMessage: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'",
EditRemote: "Edit remote", EditRemote: "Edit remote",
@ -1166,51 +1175,55 @@ func EnglishTranslationSet() TranslationSet {
NotAGitFlowBranch: "This does not seem to be a git flow branch", NotAGitFlowBranch: "This does not seem to be a git flow branch",
NewGitFlowBranchPrompt: "New {{.branchType}} name:", NewGitFlowBranchPrompt: "New {{.branchType}} name:",
IgnoreTracked: "Ignore tracked file", IgnoreTracked: "Ignore tracked file",
IgnoreTrackedPrompt: "Are you sure you want to ignore a tracked file?", IgnoreTrackedPrompt: "Are you sure you want to ignore a tracked file?",
ExcludeTracked: "Exclude tracked file", ExcludeTracked: "Exclude tracked file",
ExcludeTrackedPrompt: "Are you sure you want to exclude a tracked file?", ExcludeTrackedPrompt: "Are you sure you want to exclude a tracked file?",
ViewResetToUpstreamOptions: "View upstream reset options", ViewResetToUpstreamOptions: "View upstream reset options",
NextScreenMode: "Next screen mode (normal/half/fullscreen)", NextScreenMode: "Next screen mode (normal/half/fullscreen)",
PrevScreenMode: "Prev screen mode", PrevScreenMode: "Prev screen mode",
StartSearch: "Search the current view by text", StartSearch: "Search the current view by text",
StartFilter: "Filter the current view by text", StartFilter: "Filter the current view by text",
Panel: "Panel", Panel: "Panel",
KeybindingsLegend: "Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b", KeybindingsLegend: "Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b",
RenameBranch: "Rename branch", RenameBranch: "Rename branch",
SetUnsetUpstream: "Set/Unset upstream", BranchUpstreamOptionsTitle: "Upstream options",
NewBranchNamePrompt: "Enter new branch name for branch", ViewBranchUpstreamOptionsTooltip: "View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream",
RenameBranchWarning: "This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?", UpstreamNotStoredLocallyError: "Cannot reset to upstream branch because it is not stored locally",
OpenMenu: "Open menu", UpstreamNotSetError: "The selected branch has no upstream",
ResetCherryPick: "Reset cherry-picked (copied) commits selection", ViewBranchUpstreamOptions: "View upstream options",
NextTab: "Next tab", NewBranchNamePrompt: "Enter new branch name for branch",
PrevTab: "Previous tab", RenameBranchWarning: "This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?",
CantUndoWhileRebasing: "Can't undo while rebasing", OpenMenu: "Open menu",
CantRedoWhileRebasing: "Can't redo while rebasing", ResetCherryPick: "Reset cherry-picked (copied) commits selection",
MustStashWarning: "Pulling a patch out into the index requires stashing and unstashing your changes. If something goes wrong, you'll be able to access your files from the stash. Continue?", NextTab: "Next tab",
MustStashTitle: "Must stash", PrevTab: "Previous tab",
ConfirmationTitle: "Confirmation panel", CantUndoWhileRebasing: "Can't undo while rebasing",
PrevPage: "Previous page", CantRedoWhileRebasing: "Can't redo while rebasing",
NextPage: "Next page", MustStashWarning: "Pulling a patch out into the index requires stashing and unstashing your changes. If something goes wrong, you'll be able to access your files from the stash. Continue?",
GotoTop: "Scroll to top", MustStashTitle: "Must stash",
GotoBottom: "Scroll to bottom", ConfirmationTitle: "Confirmation panel",
FilteringBy: "Filtering by", PrevPage: "Previous page",
ResetInParentheses: "(Reset)", NextPage: "Next page",
OpenFilteringMenu: "View filter-by-path options", GotoTop: "Scroll to top",
FilterBy: "Filter by", GotoBottom: "Scroll to bottom",
ExitFilterMode: "Stop filtering by path", FilteringBy: "Filtering by",
FilterPathOption: "Enter path to filter by", ResetInParentheses: "(Reset)",
EnterFileName: "Enter path:", OpenFilteringMenu: "View filter-by-path options",
FilteringMenuTitle: "Filtering", FilterBy: "Filter by",
MustExitFilterModeTitle: "Command not available", ExitFilterMode: "Stop filtering by path",
MustExitFilterModePrompt: "Command not available in filter-by-path mode. Exit filter-by-path mode?", FilterPathOption: "Enter path to filter by",
Diff: "Diff", EnterFileName: "Enter path:",
EnterRefToDiff: "Enter ref to diff", FilteringMenuTitle: "Filtering",
EnterRefName: "Enter ref:", MustExitFilterModeTitle: "Command not available",
ExitDiffMode: "Exit diff mode", MustExitFilterModePrompt: "Command not available in filter-by-path mode. Exit filter-by-path mode?",
DiffingMenuTitle: "Diffing", Diff: "Diff",
SwapDiff: "Reverse diff direction", EnterRefToDiff: "Enter ref to diff",
OpenDiffingMenu: "Open diff menu", EnterRefName: "Enter ref:",
ExitDiffMode: "Exit diff mode",
DiffingMenuTitle: "Diffing",
SwapDiff: "Reverse diff direction",
OpenDiffingMenu: "Open diff menu",
// the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part // the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part
OpenExtrasMenu: "Open command log menu", OpenExtrasMenu: "Open command log menu",
ShowingGitDiff: "Showing output for:", ShowingGitDiff: "Showing output for:",
@ -1394,7 +1407,6 @@ func EnglishTranslationSet() TranslationSet {
Merge: "Merge", Merge: "Merge",
RebaseBranch: "Rebase branch", RebaseBranch: "Rebase branch",
RenameBranch: "Rename branch", RenameBranch: "Rename branch",
SetUnsetUpstream: "Set/Unset upstream",
CreateBranch: "Create branch", CreateBranch: "Create branch",
CherryPick: "(Cherry-pick) paste commits", CherryPick: "(Cherry-pick) paste commits",
CheckoutFile: "Checkout file", CheckoutFile: "Checkout file",

View File

@ -476,7 +476,6 @@ func koreanTranslationSet() TranslationSet {
Merge: "병합", Merge: "병합",
RebaseBranch: "브랜치 리베이스", RebaseBranch: "브랜치 리베이스",
RenameBranch: "브랜치 이름 변경", RenameBranch: "브랜치 이름 변경",
SetUnsetUpstream: "Set/Unset upstream",
CreateBranch: "브랜치 생성", CreateBranch: "브랜치 생성",
CherryPick: "(Cherry-pick) 커밋 붙여넣기", CherryPick: "(Cherry-pick) 커밋 붙여넣기",
CheckoutFile: "체크아웃 파일", CheckoutFile: "체크아웃 파일",

View File

@ -395,7 +395,6 @@ func RussianTranslationSet() TranslationSet {
Panel: "Панель", Panel: "Панель",
KeybindingsLegend: "Связки клавиш", KeybindingsLegend: "Связки клавиш",
RenameBranch: "Переименовать ветку", RenameBranch: "Переименовать ветку",
SetUnsetUpstream: "Установить/убрать upstream-ветку",
NewBranchNamePrompt: "Введите новое название ветки", NewBranchNamePrompt: "Введите новое название ветки",
RenameBranchWarning: "Эта ветвь отслеживает удалённый репозитории. Это действие переименует только имя локальной ветки, а не имя удалённой ветки. Продолжать?", RenameBranchWarning: "Эта ветвь отслеживает удалённый репозитории. Это действие переименует только имя локальной ветки, а не имя удалённой ветки. Продолжать?",
OpenMenu: "Открыть меню", OpenMenu: "Открыть меню",
@ -566,7 +565,6 @@ func RussianTranslationSet() TranslationSet {
Merge: "Слить", Merge: "Слить",
RebaseBranch: "Перебазировать ветку", RebaseBranch: "Перебазировать ветку",
RenameBranch: "Переименовать ветку", RenameBranch: "Переименовать ветку",
SetUnsetUpstream: "Установить/убрать upstream-ветку",
CreateBranch: "Создать ветку", CreateBranch: "Создать ветку",
CherryPick: "(Cherry-pick) Вставить коммиты", CherryPick: "(Cherry-pick) Вставить коммиты",
CheckoutFile: "Переключить файл", CheckoutFile: "Переключить файл",

View File

@ -421,7 +421,6 @@ func traditionalChineseTranslationSet() TranslationSet {
Panel: "面板", Panel: "面板",
KeybindingsLegend: "說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B", KeybindingsLegend: "說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B",
RenameBranch: "重新命名分支", RenameBranch: "重新命名分支",
SetUnsetUpstream: "設定/取消設定上游",
NewBranchNamePrompt: "為分支輸入新名稱", NewBranchNamePrompt: "為分支輸入新名稱",
RenameBranchWarning: "此分支正在追蹤遠端分支。此操作僅會重新命名本地分支名稱,而不是遠端分支的名稱。是否繼續?", RenameBranchWarning: "此分支正在追蹤遠端分支。此操作僅會重新命名本地分支名稱,而不是遠端分支的名稱。是否繼續?",
OpenMenu: "開啟選單", OpenMenu: "開啟選單",
@ -592,7 +591,6 @@ func traditionalChineseTranslationSet() TranslationSet {
Merge: "合併", Merge: "合併",
RebaseBranch: "變基分支", RebaseBranch: "變基分支",
RenameBranch: "重新命名分支", RenameBranch: "重新命名分支",
SetUnsetUpstream: "設置/取消上游",
CreateBranch: "建立分支", CreateBranch: "建立分支",
CherryPick: "(Cherry-pick)粘貼提交", CherryPick: "(Cherry-pick)粘貼提交",
CheckoutFile: "檢出檔案", CheckoutFile: "檢出檔案",

View File

@ -0,0 +1,102 @@
package branch
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Hard reset the current branch to the selected branch upstream",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CloneIntoRemote("origin").
NewBranch("hard-branch").
EmptyCommit("hard commit").
PushBranch("origin", "hard-branch").
NewBranch("soft-branch").
EmptyCommit("soft commit").
PushBranch("origin", "soft-branch").
NewBranch("base").
EmptyCommit("base-branch commit").
CreateFile("file-1", "content").
GitAdd("file-1").
Commit("commit with file").
CreateFile("file-2", "content").
GitAdd("file-2")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
// soft reset
t.Views().Branches().
Focus().
Lines(
Contains("base").IsSelected(),
Contains("soft-branch"),
Contains("hard-branch"),
).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Reset checked-out branch onto upstream of selected branch")).
Tooltip(Contains("The selected branch has no upstream")).
Confirm()
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("The selected branch has no upstream")).
Confirm()
}).
SelectNextItem().
Lines(
Contains("base"),
Contains("soft-branch").IsSelected(),
Contains("hard-branch"),
).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Reset checked-out branch onto origin/soft-branch...")).
Confirm()
t.ExpectPopup().Menu().
Title(Equals("Reset to origin/soft-branch")).
Select(Contains("Soft reset")).
Confirm()
})
t.Views().Commits().Lines(
Contains("soft commit"),
Contains("hard commit"),
)
t.Views().Files().Lines(
Contains("file-1").Contains("A"),
Contains("file-2").Contains("A"),
)
// hard reset
t.Views().Branches().
Focus().
Lines(
Contains("base"),
Contains("soft-branch").IsSelected(),
Contains("hard-branch"),
).
NavigateToLine(Contains("hard-branch")).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Reset checked-out branch onto origin/hard-branch...")).
Confirm()
t.ExpectPopup().Menu().
Title(Equals("Reset to origin/hard-branch")).
Select(Contains("Hard reset")).
Confirm()
})
t.Views().Commits().Lines(Contains("hard commit"))
t.Views().Files().IsEmpty()
},
})

View File

@ -25,7 +25,7 @@ var ResetUpstream = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Branches.SetUpstream). Press(keys.Branches.SetUpstream).
Tap(func() { Tap(func() {
t.ExpectPopup().Menu(). t.ExpectPopup().Menu().
Title(Equals("Set/Unset upstream")). Title(Equals("Upstream options")).
Select(Contains("Unset upstream of selected branch")). Select(Contains("Unset upstream of selected branch")).
Confirm() Confirm()
}). }).

View File

@ -24,7 +24,7 @@ var SetUpstream = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Branches.SetUpstream). Press(keys.Branches.SetUpstream).
Tap(func() { Tap(func() {
t.ExpectPopup().Menu(). t.ExpectPopup().Menu().
Title(Equals("Set/Unset upstream")). Title(Equals("Upstream options")).
Select(Contains(" Set upstream of selected branch")). // using leading space to disambiguate from the 'reset' option Select(Contains(" Set upstream of selected branch")). // using leading space to disambiguate from the 'reset' option
Confirm() Confirm()

View File

@ -38,7 +38,7 @@ var ShowDivergenceFromUpstream = NewIntegrationTest(NewIntegrationTestArgs{
Lines(Contains("master")). Lines(Contains("master")).
Press(keys.Branches.SetUpstream) Press(keys.Branches.SetUpstream)
t.ExpectPopup().Menu().Title(Contains("upstream")).Select(Contains("View divergence from upstream")).Confirm() t.ExpectPopup().Menu().Title(Contains("Upstream")).Select(Contains("View divergence from upstream")).Confirm()
t.Views().SubCommits(). t.Views().SubCommits().
IsFocused(). IsFocused().

View File

@ -47,6 +47,7 @@ var tests = []*components.IntegrationTest{
branch.RebaseDoesNotAutosquash, branch.RebaseDoesNotAutosquash,
branch.RebaseFromMarkedBase, branch.RebaseFromMarkedBase,
branch.Reset, branch.Reset,
branch.ResetToUpstream,
branch.ResetUpstream, branch.ResetUpstream,
branch.SetUpstream, branch.SetUpstream,
branch.ShowDivergenceFromUpstream, branch.ShowDivergenceFromUpstream,