1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00

standardize commit hash commit sha (#3398)

Standardise on use of 'commit hash' rather than 'commit SHA'
Close: https://github.com/jesseduffield/lazygit/issues/3208
This commit is contained in:
Stefan Haller 2024-04-12 08:37:30 +02:00 committed by GitHub
commit 145fb6191c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
75 changed files with 1101 additions and 1018 deletions

View File

@ -6,7 +6,7 @@ You can add custom command keybindings in your config.yml (accessible by pressin
customCommands:
- key: '<c-r>'
context: 'commits'
command: 'hub browse -- "commit/{{.SelectedLocalCommit.Sha}}"'
command: 'hub browse -- "commit/{{.SelectedLocalCommit.Hash}}"'
- key: 'a'
context: 'files'
command: "git {{if .SelectedFile.HasUnstagedChanges}} add {{else}} reset {{end}} {{.SelectedFile.Name | quote}}"
@ -305,7 +305,7 @@ SelectedWorktree
CheckedOutBranch
```
To see what fields are available on e.g. the `SelectedFile`, see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/models/file.go) (all the modelling lives in the same directory). Note that the custom commands feature does not guarantee backwards compatibility (until we hit Lazygit version 1.0 of course) which means a field you're accessing on an object may no longer be available from one release to the next. Typically however, all you'll need is `{{.SelectedFile.Name}}`, `{{.SelectedLocalCommit.Sha}}` and `{{.SelectedLocalBranch.Name}}`. In the future we will likely introduce a tighter interface that exposes a limited set of fields for each model.
To see what fields are available on e.g. the `SelectedFile`, see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/models/file.go) (all the modelling lives in the same directory). Note that the custom commands feature does not guarantee backwards compatibility (until we hit Lazygit version 1.0 of course) which means a field you're accessing on an object may no longer be available from one release to the next. Typically however, all you'll need is `{{.SelectedFile.Name}}`, `{{.SelectedLocalCommit.Hash}}` and `{{.SelectedLocalBranch.Name}}`. In the future we will likely introduce a tighter interface that exposes a limited set of fields for each model.
## Keybinding collisions

View File

@ -76,7 +76,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Copy commit SHA to clipboard | |
| `` <c-o> `` | Copy commit hash to clipboard | |
| `` <c-r> `` | Reset copied (cherry-picked) commits selection | |
| `` b `` | View bisect options | |
| `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |
@ -245,7 +245,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Copy commit SHA to clipboard | |
| `` <c-o> `` | Copy commit hash to clipboard | |
| `` <space> `` | Checkout | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |
@ -313,7 +313,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Copy commit SHA to clipboard | |
| `` <c-o> `` | Copy commit hash to clipboard | |
| `` <space> `` | Checkout | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |

View File

@ -66,7 +66,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | コミットのSHAをクリップボードにコピー | |
| `` <c-o> `` | コミットのhashをクリップボードにコピー | |
| `` <space> `` | チェックアウト | Checkout the selected commit as a detached HEAD. |
| `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | ブラウザでコミットを開く | |
@ -93,7 +93,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | コミットのSHAをクリップボードにコピー | |
| `` <c-o> `` | コミットのhashをクリップボードにコピー | |
| `` <c-r> `` | Reset copied (cherry-picked) commits selection | |
| `` b `` | View bisect options | |
| `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |
@ -343,7 +343,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | コミットのSHAをクリップボードにコピー | |
| `` <c-o> `` | コミットのhashをクリップボードにコピー | |
| `` <space> `` | チェックアウト | Checkout the selected commit as a detached HEAD. |
| `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | ブラウザでコミットを開く | |

View File

@ -53,7 +53,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 커밋 SHA를 클립보드에 복사 | |
| `` <c-o> `` | 커밋 해시를 클립보드에 복사 | |
| `` <space> `` | 체크아웃 | Checkout the selected commit as a detached HEAD. |
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 브라우저에서 커밋 열기 | |
@ -83,7 +83,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 커밋 SHA를 클립보드에 복사 | |
| `` <c-o> `` | 커밋 해시를 클립보드에 복사 | |
| `` <space> `` | 체크아웃 | Checkout the selected commit as a detached HEAD. |
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 브라우저에서 커밋 열기 | |
@ -256,7 +256,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 커밋 SHA를 클립보드에 복사 | |
| `` <c-o> `` | 커밋 해시를 클립보드에 복사 | |
| `` <c-r> `` | Reset cherry-picked (copied) commits selection | |
| `` b `` | Bisect 옵션 보기 | |
| `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |

View File

@ -139,7 +139,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Kopieer commit SHA naar klembord | |
| `` <c-o> `` | Kopieer commit hash naar klembord | |
| `` <c-r> `` | Reset cherry-picked (gekopieerde) commits selectie | |
| `` b `` | View bisect options | |
| `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |
@ -223,7 +223,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Kopieer commit SHA naar klembord | |
| `` <c-o> `` | Kopieer commit hash naar klembord | |
| `` <space> `` | Uitchecken | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |
@ -313,7 +313,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Kopieer commit SHA naar klembord | |
| `` <c-o> `` | Kopieer commit hash naar klembord | |
| `` <space> `` | Uitchecken | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |

View File

@ -53,7 +53,7 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-b>` oznacza alt+b, `B` oznacza shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Kopiuj SHA commita do schowka | |
| `` <c-o> `` | Kopiuj hash commita do schowka | |
| `` <c-r> `` | Resetuj wybrane (cherry-picked) commity | |
| `` b `` | Zobacz opcje bisect | |
| `` s `` | Scal | Scal wybrany commit z commitami poniżej. Wiadomość wybranego commita zostanie dołączona do commita poniżej. |
@ -255,7 +255,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita,
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Kopiuj SHA commita do schowka | |
| `` <c-o> `` | Kopiuj hash commita do schowka | |
| `` <space> `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. |
| `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). |
| `` o `` | Otwórz commit w przeglądarce | |
@ -295,7 +295,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita,
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Kopiuj SHA commita do schowka | |
| `` <c-o> `` | Kopiuj hash commita do schowka | |
| `` <space> `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. |
| `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). |
| `` o `` | Otwórz commit w przeglądarce | |

View File

@ -123,7 +123,7 @@ _Связки клавиш_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Скопировать SHA коммита в буфер обмена | |
| `` <c-o> `` | Скопировать hash коммита в буфер обмена | |
| `` <space> `` | Переключить | Checkout the selected commit as a detached HEAD. |
| `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Открыть коммит в браузере | |
@ -140,7 +140,7 @@ _Связки клавиш_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Скопировать SHA коммита в буфер обмена | |
| `` <c-o> `` | Скопировать hash коммита в буфер обмена | |
| `` <c-r> `` | Сбросить отобранную (скопированную | cherry-picked) выборку коммитов | |
| `` b `` | Просмотреть параметры бинарного поиска | |
| `` s `` | Объединить коммиты (Squash) | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |
@ -219,7 +219,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | Скопировать SHA коммита в буфер обмена | |
| `` <c-o> `` | Скопировать hash коммита в буфер обмена | |
| `` <space> `` | Переключить | Checkout the selected commit as a detached HEAD. |
| `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Открыть коммит в браузере | |

View File

@ -53,7 +53,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 将提交的 SHA 复制到剪贴板 | |
| `` <c-o> `` | 将提交的 hash 复制到剪贴板 | |
| `` <space> `` | 检出 | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 在浏览器中打开提交 | |
@ -106,7 +106,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 将提交的 SHA 复制到剪贴板 | |
| `` <c-o> `` | 将提交的 hash 复制到剪贴板 | |
| `` <space> `` | 检出 | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 在浏览器中打开提交 | |
@ -137,7 +137,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 将提交的 SHA 复制到剪贴板 | |
| `` <c-o> `` | 将提交的 hash 复制到剪贴板 | |
| `` <c-r> `` | 重置已拣选(复制)的提交 | |
| `` b `` | 查看二分查找选项 | |
| `` s `` | 压缩 | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |

View File

@ -121,7 +121,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 複製提交 SHA 到剪貼簿 | |
| `` <c-o> `` | 複製提交 hash 到剪貼簿 | |
| `` <space> `` | 檢出 | Checkout the selected commit as a detached HEAD. |
| `` y `` | 複製提交屬性 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 在瀏覽器中開啟提交 | |
@ -162,7 +162,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 複製提交 SHA 到剪貼簿 | |
| `` <c-o> `` | 複製提交 hash 到剪貼簿 | |
| `` <c-r> `` | 重設選定的揀選 (複製) 提交 | |
| `` b `` | 查看二分選項 | |
| `` s `` | 壓縮 (Squash) | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. |
@ -236,7 +236,7 @@ If you would instead like to start an interactive rebase from the selected commi
| Key | Action | Info |
|-----|--------|-------------|
| `` <c-o> `` | 複製提交 SHA 到剪貼簿 | |
| `` <c-o> `` | 複製提交 hash 到剪貼簿 | |
| `` <space> `` | 檢出 | Checkout the selected commit as a detached HEAD. |
| `` y `` | 複製提交屬性 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 在瀏覽器中開啟提交 | |

View File

@ -212,7 +212,7 @@ func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
changes := lo.Map(self.Changes, func(c ChangeTodoAction, _ int) utils.TodoChange {
return utils.TodoChange{
Sha: c.Sha,
Hash: c.Hash,
OldAction: todo.Pick,
NewAction: c.NewAction,
}
@ -222,18 +222,18 @@ func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
})
}
// Takes the sha of some commit, and the sha of a fixup commit that was created
// Takes the hash of some commit, and the hash of a fixup commit that was created
// at the end of the branch, then moves the fixup commit down to right after the
// original commit, changing its type to "fixup"
type MoveFixupCommitDownInstruction struct {
OriginalSha string
FixupSha string
OriginalHash string
FixupHash string
}
func NewMoveFixupCommitDownInstruction(originalSha string, fixupSha string) Instruction {
func NewMoveFixupCommitDownInstruction(originalHash string, fixupHash string) Instruction {
return &MoveFixupCommitDownInstruction{
OriginalSha: originalSha,
FixupSha: fixupSha,
OriginalHash: originalHash,
FixupHash: fixupHash,
}
}
@ -247,17 +247,17 @@ func (self *MoveFixupCommitDownInstruction) SerializedInstructions() string {
func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
return utils.MoveFixupCommitDown(path, self.OriginalSha, self.FixupSha, getCommentChar())
return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, getCommentChar())
})
}
type MoveTodosUpInstruction struct {
Shas []string
Hashes []string
}
func NewMoveTodosUpInstruction(shas []string) Instruction {
func NewMoveTodosUpInstruction(hashes []string) Instruction {
return &MoveTodosUpInstruction{
Shas: shas,
Hashes: hashes,
}
}
@ -270,9 +270,9 @@ func (self *MoveTodosUpInstruction) SerializedInstructions() string {
}
func (self *MoveTodosUpInstruction) run(common *common.Common) error {
todosToMove := lo.Map(self.Shas, func(sha string, _ int) utils.Todo {
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
return utils.Todo{
Sha: sha,
Hash: hash,
Action: todo.Pick,
}
})
@ -283,12 +283,12 @@ func (self *MoveTodosUpInstruction) run(common *common.Common) error {
}
type MoveTodosDownInstruction struct {
Shas []string
Hashes []string
}
func NewMoveTodosDownInstruction(shas []string) Instruction {
func NewMoveTodosDownInstruction(hashes []string) Instruction {
return &MoveTodosDownInstruction{
Shas: shas,
Hashes: hashes,
}
}
@ -301,9 +301,9 @@ func (self *MoveTodosDownInstruction) SerializedInstructions() string {
}
func (self *MoveTodosDownInstruction) run(common *common.Common) error {
todosToMove := lo.Map(self.Shas, func(sha string, _ int) utils.Todo {
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
return utils.Todo{
Sha: sha,
Hash: hash,
Action: todo.Pick,
}
})

View File

@ -21,7 +21,7 @@ func (self *TodoLine) ToString() string {
if self.Action == "break" {
return self.Action + "\n"
} else {
return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n"
return self.Action + " " + self.Commit.Hash + " " + self.Commit.Name + "\n"
}
}
@ -34,7 +34,7 @@ func TodoLinesToString(todoLines []TodoLine) string {
}
type ChangeTodoAction struct {
Sha string
Hash string
NewAction todo.TodoCommand
}

View File

@ -263,7 +263,7 @@ func mergeBuildInfo(buildInfo *BuildInfo) {
buildInfo.Commit = revision.Value
// if lazygit was built from source we'll show the version as the
// abbreviated commit hash
buildInfo.Version = utils.ShortSha(revision.Value)
buildInfo.Version = utils.ShortHash(revision.Value)
}
// if version hasn't been set we assume that neither has the date

View File

@ -76,7 +76,7 @@ func (self *BisectCommands) GetInfoForGitDir(gitDir string) *BisectInfo {
return info
}
sha := strings.TrimSpace(string(fileContent))
hash := strings.TrimSpace(string(fileContent))
if name == info.newTerm {
status = BisectStatusNew
@ -86,7 +86,7 @@ func (self *BisectCommands) GetInfoForGitDir(gitDir string) *BisectInfo {
status = BisectStatusSkipped
}
info.statusMap[sha] = status
info.statusMap[hash] = status
}
currentContent, err := os.ReadFile(filepath.Join(gitDir, "BISECT_EXPECTED_REV"))
@ -94,8 +94,8 @@ func (self *BisectCommands) GetInfoForGitDir(gitDir string) *BisectInfo {
self.Log.Infof("error getting git bisect info: %s", err.Error())
return info
}
currentSha := strings.TrimSpace(string(currentContent))
info.current = currentSha
currentHash := strings.TrimSpace(string(currentContent))
info.current = currentHash
return info
}
@ -135,7 +135,7 @@ func (self *BisectCommands) StartWithTerms(oldTerm string, newTerm string) error
}
// tells us whether we've found our problem commit(s). We return a string slice of
// commit sha's if we're done, and that slice may have more that one item if
// commit hashes if we're done, and that slice may have more that one item if
// skipped commits are involved.
func (self *BisectCommands) IsDone() (bool, []string, error) {
info := self.GetInfo()
@ -143,8 +143,8 @@ func (self *BisectCommands) IsDone() (bool, []string, error) {
return false, nil, nil
}
newSha := info.GetNewSha()
if newSha == "" {
newHash := info.GetNewHash()
if newHash == "" {
return false, nil, nil
}
@ -153,14 +153,14 @@ func (self *BisectCommands) IsDone() (bool, []string, error) {
done := false
candidates := []string{}
cmdArgs := NewGitCmd("rev-list").Arg(newSha).ToArgv()
cmdArgs := NewGitCmd("rev-list").Arg(newHash).ToArgv()
err := self.cmd.New(cmdArgs).RunAndProcessLines(func(line string) (bool, error) {
sha := strings.TrimSpace(line)
hash := strings.TrimSpace(line)
if status, ok := info.statusMap[sha]; ok {
if status, ok := info.statusMap[hash]; ok {
switch status {
case BisectStatusSkipped, BisectStatusNew:
candidates = append(candidates, sha)
candidates = append(candidates, hash)
return false, nil
case BisectStatusOld:
done = true
@ -185,7 +185,7 @@ func (self *BisectCommands) IsDone() (bool, []string, error) {
// render the commits from the bad commit.
func (self *BisectCommands) ReachableFromStart(bisectInfo *BisectInfo) bool {
cmdArgs := NewGitCmd("merge-base").
Arg("--is-ancestor", bisectInfo.GetNewSha(), bisectInfo.GetStartSha()).
Arg("--is-ancestor", bisectInfo.GetNewHash(), bisectInfo.GetStartHash()).
ToArgv()
err := self.cmd.New(cmdArgs).DontLog().Run()

View File

@ -29,10 +29,10 @@ type BisectInfo struct {
newTerm string // 'bad' by default
oldTerm string // 'good' by default
// map of commit sha's to their status
// map of commit hashes to their status
statusMap map[string]BisectStatus
// the sha of the commit that's under test
// the hash of the commit that's under test
current string
}
@ -49,26 +49,26 @@ func NewNullBisectInfo() *BisectInfo {
return &BisectInfo{started: false}
}
func (self *BisectInfo) GetNewSha() string {
for sha, status := range self.statusMap {
func (self *BisectInfo) GetNewHash() string {
for hash, status := range self.statusMap {
if status == BisectStatusNew {
return sha
return hash
}
}
return ""
}
func (self *BisectInfo) GetCurrentSha() string {
func (self *BisectInfo) GetCurrentHash() string {
return self.current
}
func (self *BisectInfo) GetStartSha() string {
func (self *BisectInfo) GetStartHash() string {
return self.start
}
func (self *BisectInfo) Status(commitSha string) (BisectStatus, bool) {
status, ok := self.statusMap[commitSha]
func (self *BisectInfo) Status(commitHash string) (BisectStatus, bool) {
status, ok := self.statusMap[commitHash]
return status, ok
}
@ -93,7 +93,7 @@ func (self *BisectInfo) Bisecting() bool {
return false
}
if self.GetNewSha() == "" {
if self.GetNewHash() == "" {
return false
}

View File

@ -65,10 +65,10 @@ func (self *BranchCommands) CurrentBranchInfo() (BranchInfo, error) {
for _, line := range utils.SplitLines(output) {
split := strings.Split(strings.TrimRight(line, "\r\n"), "\x00")
if len(split) == 3 && split[0] == "*" {
sha := split[1]
hash := split[1]
displayName := split[2]
return BranchInfo{
RefName: sha,
RefName: hash,
DisplayName: displayName,
DetachedHead: true,
}, nil

View File

@ -39,8 +39,8 @@ func (self *CommitCommands) SetAuthor(value string) error {
}
// Add a commit's coauthor using Github/Gitlab Co-authored-by metadata. Value is expected to be of the form 'Name <Email>'
func (self *CommitCommands) AddCoAuthor(sha string, author string) error {
message, err := self.GetCommitMessage(sha)
func (self *CommitCommands) AddCoAuthor(hash string, author string) error {
message, err := self.GetCommitMessage(hash)
if err != nil {
return err
}
@ -74,8 +74,8 @@ func AddCoAuthorToDescription(description string, author string) string {
}
// ResetToCommit reset to commit
func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error {
cmdArgs := NewGitCmd("reset").Arg("--"+strength, sha).ToArgv()
func (self *CommitCommands) ResetToCommit(hash string, strength string, envVars []string) error {
cmdArgs := NewGitCmd("reset").Arg("--"+strength, hash).ToArgv()
return self.cmd.New(cmdArgs).
// prevents git from prompting us for input which would freeze the program
@ -155,9 +155,9 @@ func (self *CommitCommands) signoffFlag() string {
}
}
func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
func (self *CommitCommands) GetCommitMessage(commitHash string) (string, error) {
cmdArgs := NewGitCmd("log").
Arg("--format=%B", "--max-count=1", commitSha).
Arg("--format=%B", "--max-count=1", commitHash).
Config("log.showsignature=false").
ToArgv()
@ -165,9 +165,9 @@ func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
return strings.ReplaceAll(strings.TrimSpace(message), "\r\n", "\n"), err
}
func (self *CommitCommands) GetCommitSubject(commitSha string) (string, error) {
func (self *CommitCommands) GetCommitSubject(commitHash string) (string, error) {
cmdArgs := NewGitCmd("log").
Arg("--format=%s", "--max-count=1", commitSha).
Arg("--format=%s", "--max-count=1", commitHash).
Config("log.showsignature=false").
ToArgv()
@ -175,8 +175,8 @@ func (self *CommitCommands) GetCommitSubject(commitSha string) (string, error) {
return strings.TrimSpace(subject), err
}
func (self *CommitCommands) GetCommitDiff(commitSha string) (string, error) {
cmdArgs := NewGitCmd("show").Arg("--no-color", commitSha).ToArgv()
func (self *CommitCommands) GetCommitDiff(commitHash string) (string, error) {
cmdArgs := NewGitCmd("show").Arg("--no-color", commitHash).ToArgv()
diff, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
return diff, err
@ -187,9 +187,9 @@ type Author struct {
Email string
}
func (self *CommitCommands) GetCommitAuthor(commitSha string) (Author, error) {
func (self *CommitCommands) GetCommitAuthor(commitHash string) (Author, error) {
cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:'%an%x00%ae'", commitSha).
Arg("--no-patch", "--pretty=format:'%an%x00%ae'", commitHash).
ToArgv()
output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
@ -206,14 +206,14 @@ func (self *CommitCommands) GetCommitAuthor(commitSha string) (Author, error) {
return author, err
}
func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error) {
return self.GetCommitMessagesFirstLine([]string{sha})
func (self *CommitCommands) GetCommitMessageFirstLine(hash string) (string, error) {
return self.GetCommitMessagesFirstLine([]string{hash})
}
func (self *CommitCommands) GetCommitMessagesFirstLine(shas []string) (string, error) {
func (self *CommitCommands) GetCommitMessagesFirstLine(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:%s").
Arg(shas...).
Arg(hashes...).
ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput()
@ -224,19 +224,19 @@ func (self *CommitCommands) GetCommitMessagesFirstLine(shas []string) (string, e
// cd50c79ae Preserve the commit message correctly even if the description has blank lines
// 3ebba5f32 Add test demonstrating a bug with preserving the commit message
// 9a423c388 Remove unused function
func (self *CommitCommands) GetShasAndCommitMessagesFirstLine(shas []string) (string, error) {
func (self *CommitCommands) GetHashesAndCommitMessagesFirstLine(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:%h %s").
Arg(shas...).
Arg(hashes...).
ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput()
}
func (self *CommitCommands) GetCommitsOneline(shas []string) (string, error) {
func (self *CommitCommands) GetCommitsOneline(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--oneline").
Arg(shas...).
Arg(hashes...).
ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput()
@ -255,7 +255,7 @@ func (self *CommitCommands) AmendHeadCmdObj() oscommands.ICmdObj {
return self.cmd.New(cmdArgs)
}
func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj {
func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) oscommands.ICmdObj {
contextSize := self.AppState.DiffContextSize
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
@ -269,7 +269,7 @@ func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands
Arg("--stat").
Arg("--decorate").
Arg("-p").
Arg(sha).
Arg(hash).
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
ArgIf(filterPath != "", "--", filterPath).
Dir(self.repoPaths.worktreePath).
@ -278,23 +278,23 @@ func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands
return self.cmd.New(cmdArgs).DontLog()
}
// Revert reverts the selected commit by sha
func (self *CommitCommands) Revert(sha string) error {
cmdArgs := NewGitCmd("revert").Arg(sha).ToArgv()
// Revert reverts the selected commit by hash
func (self *CommitCommands) Revert(hash string) error {
cmdArgs := NewGitCmd("revert").Arg(hash).ToArgv()
return self.cmd.New(cmdArgs).Run()
}
func (self *CommitCommands) RevertMerge(sha string, parentNumber int) error {
cmdArgs := NewGitCmd("revert").Arg(sha, "-m", fmt.Sprintf("%d", parentNumber)).
func (self *CommitCommands) RevertMerge(hash string, parentNumber int) error {
cmdArgs := NewGitCmd("revert").Arg(hash, "-m", fmt.Sprintf("%d", parentNumber)).
ToArgv()
return self.cmd.New(cmdArgs).Run()
}
// CreateFixupCommit creates a commit that fixes up a previous commit
func (self *CommitCommands) CreateFixupCommit(sha string) error {
cmdArgs := NewGitCmd("commit").Arg("--fixup=" + sha).ToArgv()
func (self *CommitCommands) CreateFixupCommit(hash string) error {
cmdArgs := NewGitCmd("commit").Arg("--fixup=" + hash).ToArgv()
return self.cmd.New(cmdArgs).Run()
}

View File

@ -129,7 +129,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
}
for _, commit := range commits {
if commit.Sha == firstPushedCommit {
if commit.Hash == firstPushedCommit {
passedFirstPushedCommit = true
}
if commit.Status != models.StatusRebasing {
@ -198,14 +198,14 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod
return result, nil
}
// extractCommitFromLine takes a line from a git log and extracts the sha, message, date, and tag if present
// extractCommitFromLine takes a line from a git log and extracts the hash, message, date, and tag if present
// then puts them into a commit object
// example input:
// 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag
func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool) *models.Commit {
split := strings.SplitN(line, "\x00", 8)
sha := split[0]
hash := split[0]
unixTimestamp := split[1]
authorName := split[2]
authorEmail := split[3]
@ -241,7 +241,7 @@ func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool
}
return &models.Commit{
Sha: sha,
Hash: hash,
Name: message,
Tags: tags,
ExtraInfo: extraInfo,
@ -260,8 +260,8 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
return nil, nil
}
commitShas := lo.FilterMap(commits, func(commit *models.Commit, _ int) (string, bool) {
return commit.Sha, commit.Sha != ""
commitHashes := lo.FilterMap(commits, func(commit *models.Commit, _ int) (string, bool) {
return commit.Hash, commit.Hash != ""
})
// note that we're not filtering these as we do non-rebasing commits just because
@ -270,14 +270,14 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
NewGitCmd("show").
Config("log.showSignature=false").
Arg("--no-patch", "--oneline", "--abbrev=20", prettyFormat).
Arg(commitShas...).
Arg(commitHashes...).
ToArgv(),
).DontLog()
fullCommits := map[string]*models.Commit{}
err := cmdObj.RunAndProcessLines(func(line string) (bool, error) {
commit := self.extractCommitFromLine(line, false)
fullCommits[commit.Sha] = commit
fullCommits[commit.Hash] = commit
return false, nil
})
if err != nil {
@ -285,23 +285,23 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
}
findFullCommit := lo.Ternary(self.version.IsOlderThan(2, 25, 2),
func(sha string) *models.Commit {
func(hash string) *models.Commit {
for s, c := range fullCommits {
if strings.HasPrefix(s, sha) {
if strings.HasPrefix(s, hash) {
return c
}
}
return nil
},
func(sha string) *models.Commit {
return fullCommits[sha]
func(hash string) *models.Commit {
return fullCommits[hash]
})
hydratedCommits := make([]*models.Commit, 0, len(commits))
for _, rebasingCommit := range commits {
if rebasingCommit.Sha == "" {
if rebasingCommit.Hash == "" {
hydratedCommits = append(hydratedCommits, rebasingCommit)
} else if commit := findFullCommit(rebasingCommit.Sha); commit != nil {
} else if commit := findFullCommit(rebasingCommit.Hash); commit != nil {
commit.Action = rebasingCommit.Action
commit.Status = rebasingCommit.Status
hydratedCommits = append(hydratedCommits, commit)
@ -337,9 +337,9 @@ func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) []*mod
// See if the current commit couldn't be applied because it conflicted; if
// so, add a fake entry for it
if conflictedCommitSha := self.getConflictedCommit(todos); conflictedCommitSha != "" {
if conflictedCommitHash := self.getConflictedCommit(todos); conflictedCommitHash != "" {
commits = append(commits, &models.Commit{
Sha: conflictedCommitSha,
Hash: conflictedCommitHash,
Name: "",
Status: models.StatusRebasing,
Action: models.ActionConflict,
@ -354,7 +354,7 @@ func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) []*mod
continue
}
commits = utils.Prepend(commits, &models.Commit{
Sha: t.Commit,
Hash: t.Commit,
Name: t.Msg,
Status: models.StatusRebasing,
Action: t.Command,
@ -458,8 +458,8 @@ func setCommitMergedStatuses(ancestor string, commits []*models.Commit) {
passedAncestor := false
for i, commit := range commits {
// some commits aren't really commits and don't have sha's, such as the update-ref todo
if commit.Sha != "" && strings.HasPrefix(ancestor, commit.Sha) {
// some commits aren't really commits and don't have hashes, such as the update-ref todo
if commit.Hash != "" && strings.HasPrefix(ancestor, commit.Hash) {
passedAncestor = true
}
if commit.Status != models.StatusPushed && commit.Status != models.StatusUnpushed {
@ -559,7 +559,7 @@ func ignoringWarnings(commandOutput string) string {
return lastLine
}
// getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream.
// getFirstPushedCommit returns the first commit hash which has been pushed to the ref's upstream.
// all commits above this are deemed unpushed and marked as such.
func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) {
output, err := self.cmd.New(

View File

@ -86,7 +86,7 @@ func TestGetCommits(t *testing.T) {
expectedCommits: []*models.Commit{
{
Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Name: "better typing for rebase mode",
Status: models.StatusUnpushed,
Action: models.ActionNone,
@ -100,7 +100,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164",
Hash: "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164",
Name: "fix logging",
Status: models.StatusPushed,
Action: models.ActionNone,
@ -114,7 +114,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c",
Hash: "e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c",
Name: "refactor",
Status: models.StatusPushed,
Action: models.ActionNone,
@ -128,7 +128,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "d8084cd558925eb7c9c38afeed5725c21653ab90",
Hash: "d8084cd558925eb7c9c38afeed5725c21653ab90",
Name: "WIP",
Status: models.StatusPushed,
Action: models.ActionNone,
@ -142,7 +142,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "65f910ebd85283b5cce9bf67d03d3f1a9ea3813a",
Hash: "65f910ebd85283b5cce9bf67d03d3f1a9ea3813a",
Name: "WIP",
Status: models.StatusPushed,
Action: models.ActionNone,
@ -156,7 +156,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "26c07b1ab33860a1a7591a0638f9925ccf497ffa",
Hash: "26c07b1ab33860a1a7591a0638f9925ccf497ffa",
Name: "WIP",
Status: models.StatusMerged,
Action: models.ActionNone,
@ -170,7 +170,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "3d4470a6c072208722e5ae9a54bcb9634959a1c5",
Hash: "3d4470a6c072208722e5ae9a54bcb9634959a1c5",
Name: "WIP",
Status: models.StatusMerged,
Action: models.ActionNone,
@ -184,7 +184,7 @@ func TestGetCommits(t *testing.T) {
},
},
{
Sha: "053a66a7be3da43aacdc7aa78e1fe757b82c4dd2",
Hash: "053a66a7be3da43aacdc7aa78e1fe757b82c4dd2",
Name: "refactoring the config struct",
Status: models.StatusMerged,
Action: models.ActionNone,
@ -221,7 +221,7 @@ func TestGetCommits(t *testing.T) {
expectedCommits: []*models.Commit{
{
Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Name: "better typing for rebase mode",
Status: models.StatusUnpushed,
Action: models.ActionNone,
@ -260,7 +260,7 @@ func TestGetCommits(t *testing.T) {
expectedCommits: []*models.Commit{
{
Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Name: "better typing for rebase mode",
Status: models.StatusUnpushed,
Action: models.ActionNone,
@ -339,14 +339,14 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
todos []todo.Todo
doneTodos []todo.Todo
amendFileExists bool
expectedSha string
expectedHash string
}{
{
testName: "no done todos",
todos: []todo.Todo{},
doneTodos: []todo.Todo{},
amendFileExists: false,
expectedSha: "",
expectedHash: "",
},
{
testName: "common case (conflict)",
@ -362,7 +362,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: false,
expectedSha: "fa1afe1",
expectedHash: "fa1afe1",
},
{
testName: "last command was 'break'",
@ -371,7 +371,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
{Command: todo.Break},
},
amendFileExists: false,
expectedSha: "",
expectedHash: "",
},
{
testName: "last command was 'exec'",
@ -383,7 +383,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: false,
expectedSha: "",
expectedHash: "",
},
{
testName: "last command was 'reword'",
@ -392,7 +392,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
{Command: todo.Reword},
},
amendFileExists: false,
expectedSha: "",
expectedHash: "",
},
{
testName: "'pick' was rescheduled",
@ -409,7 +409,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: false,
expectedSha: "",
expectedHash: "",
},
{
testName: "'pick' was rescheduled, buggy git version",
@ -434,7 +434,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: false,
expectedSha: "",
expectedHash: "",
},
{
testName: "conflicting 'pick' after 'exec'",
@ -459,7 +459,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: false,
expectedSha: "fa1afe1",
expectedHash: "fa1afe1",
},
{
testName: "'edit' with amend file",
@ -471,7 +471,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: true,
expectedSha: "",
expectedHash: "",
},
{
testName: "'edit' without amend file",
@ -483,7 +483,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
},
amendFileExists: false,
expectedSha: "fa1afe1",
expectedHash: "fa1afe1",
},
}
for _, scenario := range scenarios {
@ -503,8 +503,8 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
},
}
sha := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists)
assert.Equal(t, scenario.expectedSha, sha)
hash := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists)
assert.Equal(t, scenario.expectedHash, hash)
})
}
}
@ -521,29 +521,29 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
{
testName: "basic",
commits: []*models.Commit{
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Sha: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusPushed},
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
{Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Hash: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusPushed},
{Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
},
ancestor: "67890",
expectedCommits: []*models.Commit{
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Sha: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusMerged},
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusMerged},
{Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Hash: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusMerged},
{Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusMerged},
},
},
{
testName: "with update-ref",
commits: []*models.Commit{
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Sha: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone},
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
{Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Hash: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone},
{Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
},
ancestor: "deadbeef",
expectedCommits: []*models.Commit{
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Sha: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone},
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
{Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Hash: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone},
{Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
},
},
}

View File

@ -153,7 +153,7 @@ func TestCommitCommitEditorCmdObj(t *testing.T) {
func TestCommitCreateFixupCommit(t *testing.T) {
type scenario struct {
testName string
sha string
hash string
runner *oscommands.FakeCmdObjRunner
test func(error)
}
@ -161,7 +161,7 @@ func TestCommitCreateFixupCommit(t *testing.T) {
scenarios := []scenario{
{
testName: "valid case",
sha: "12345",
hash: "12345",
runner: oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"commit", "--fixup=12345"}, "", nil),
test: func(err error) {
@ -174,7 +174,7 @@ func TestCommitCreateFixupCommit(t *testing.T) {
s := s
t.Run(s.testName, func(t *testing.T) {
instance := buildCommitCommands(commonDeps{runner: s.runner})
s.test(instance.CreateFixupCommit(s.sha))
s.test(instance.CreateFixupCommit(s.hash))
s.runner.CheckForMissingCalls()
})
}
@ -365,7 +365,7 @@ func TestGetCommitMessageFromHistory(t *testing.T) {
},
{
"Default case to retrieve a commit in history",
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "sha3 \n", nil).ExpectGitArgs([]string{"-c", "log.showsignature=false", "log", "--format=%B", "--max-count=1", "sha3"}, `use generics to DRY up context code`, nil),
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "hash3 \n", nil).ExpectGitArgs([]string{"-c", "log.showsignature=false", "log", "--format=%B", "--max-count=1", "hash3"}, `use generics to DRY up context code`, nil),
func(output string, err error) {
assert.NoError(t, err)
assert.Equal(t, "use generics to DRY up context code", output)

View File

@ -157,13 +157,13 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
baseIndex := sourceCommitIdx + 1
changes := []daemon.ChangeTodoAction{
{Sha: commits[sourceCommitIdx].Sha, NewAction: todo.Edit},
{Sha: commits[destinationCommitIdx].Sha, NewAction: todo.Edit},
{Hash: commits[sourceCommitIdx].Hash, NewAction: todo.Edit},
{Hash: commits[destinationCommitIdx].Hash, NewAction: todo.Edit},
}
self.os.LogCommand(logTodoChanges(changes), false)
err := self.rebase.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: commits[baseIndex].Sha,
baseHashOrRoot: commits[baseIndex].Hash,
overrideEditor: true,
instruction: daemon.NewChangeTodoActionsInstruction(changes),
}).Run()
@ -219,7 +219,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitIdx int, stash bool) error {
if stash {
if err := self.stash.Push(self.Tr.StashPrefix + commits[commitIdx].Sha); err != nil {
if err := self.stash.Push(self.Tr.StashPrefix + commits[commitIdx].Hash); err != nil {
return err
}
}
@ -324,7 +324,7 @@ func (self *PatchCommands) diffHeadAgainstCommit(commit *models.Commit) (string,
cmdArgs := NewGitCmd("diff").
Config("diff.noprefix=false").
Arg("--no-ext-diff").
Arg("HEAD.." + commit.Sha).
Arg("HEAD.." + commit.Hash).
ToArgv()
return self.cmd.New(cmdArgs).RunWithOutput()

View File

@ -56,14 +56,14 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, su
func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index int) (oscommands.ICmdObj, error) {
changes := []daemon.ChangeTodoAction{{
Sha: commits[index].Sha,
Hash: commits[index].Hash,
NewAction: todo.Reword,
}}
self.os.LogCommand(logTodoChanges(changes), false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: getBaseShaOrRoot(commits, index+1),
instruction: daemon.NewChangeTodoActionsInstruction(changes),
baseHashOrRoot: getBaseHashOrRoot(commits, index+1),
instruction: daemon.NewChangeTodoActionsInstruction(changes),
}), nil
}
@ -81,7 +81,7 @@ func (self *RebaseCommands) SetCommitAuthor(commits []*models.Commit, index int,
func (self *RebaseCommands) AddCommitCoAuthor(commits []*models.Commit, index int, value string) error {
return self.GenericAmend(commits, index, func() error {
return self.commit.AddCoAuthor(commits[index].Sha, value)
return self.commit.AddCoAuthor(commits[index].Hash, value)
})
}
@ -106,29 +106,29 @@ func (self *RebaseCommands) GenericAmend(commits []*models.Commit, index int, f
}
func (self *RebaseCommands) MoveCommitsDown(commits []*models.Commit, startIdx int, endIdx int) error {
baseShaOrRoot := getBaseShaOrRoot(commits, endIdx+2)
baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+2)
shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Sha
hashes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Hash
})
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot,
instruction: daemon.NewMoveTodosDownInstruction(shas),
baseHashOrRoot: baseHashOrRoot,
instruction: daemon.NewMoveTodosDownInstruction(hashes),
overrideEditor: true,
}).Run()
}
func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int, endIdx int) error {
baseShaOrRoot := getBaseShaOrRoot(commits, endIdx+1)
baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+1)
shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Sha
hashes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Hash
})
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot,
instruction: daemon.NewMoveTodosUpInstruction(shas),
baseHashOrRoot: baseHashOrRoot,
instruction: daemon.NewMoveTodosUpInstruction(hashes),
overrideEditor: true,
}).Run()
}
@ -139,11 +139,11 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx
baseIndex++
}
baseShaOrRoot := getBaseShaOrRoot(commits, baseIndex)
baseHashOrRoot := getBaseHashOrRoot(commits, baseIndex)
changes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) daemon.ChangeTodoAction {
return daemon.ChangeTodoAction{
Sha: commit.Sha,
Hash: commit.Hash,
NewAction: action,
}
})
@ -151,7 +151,7 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx
self.os.LogCommand(logTodoChanges(changes), false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot,
baseHashOrRoot: baseHashOrRoot,
overrideEditor: true,
instruction: daemon.NewChangeTodoActionsInstruction(changes),
}).Run()
@ -166,8 +166,8 @@ func (self *RebaseCommands) EditRebase(branchRef string) error {
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: branchRef,
instruction: daemon.NewInsertBreakInstruction(),
baseHashOrRoot: branchRef,
instruction: daemon.NewInsertBreakInstruction(),
}).Run()
}
@ -181,21 +181,21 @@ func (self *RebaseCommands) EditRebaseFromBaseCommit(targetBranchName string, ba
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseCommit,
onto: targetBranchName,
instruction: daemon.NewInsertBreakInstruction(),
baseHashOrRoot: baseCommit,
onto: targetBranchName,
instruction: daemon.NewInsertBreakInstruction(),
}).Run()
}
func logTodoChanges(changes []daemon.ChangeTodoAction) string {
changeTodoStr := strings.Join(lo.Map(changes, func(c daemon.ChangeTodoAction, _ int) string {
return fmt.Sprintf("%s:%s", c.Sha, c.NewAction)
return fmt.Sprintf("%s:%s", c.Hash, c.NewAction)
}), "\n")
return fmt.Sprintf("Changing TODO actions:\n%s", changeTodoStr)
}
type PrepareInteractiveRebaseCommandOpts struct {
baseShaOrRoot string
baseHashOrRoot string
onto string
instruction daemon.Instruction
overrideEditor bool
@ -216,7 +216,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract
Arg("--no-autosquash").
ArgIf(self.version.IsAtLeast(2, 22, 0), "--rebase-merges").
ArgIf(opts.onto != "", "--onto", opts.onto).
Arg(opts.baseShaOrRoot).
Arg(opts.baseHashOrRoot).
ToArgv()
debug := "FALSE"
@ -284,21 +284,21 @@ func (self *RebaseCommands) GitRebaseEditTodo(todosFileContent []byte) error {
func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) error {
commit := commits[commitIndex]
if err := self.commit.CreateFixupCommit(commit.Sha); err != nil {
if err := self.commit.CreateFixupCommit(commit.Hash); err != nil {
return err
}
// Get the sha of the commit we just created
// Get the hash of the commit we just created
cmdArgs := NewGitCmd("rev-parse").Arg("--verify", "HEAD").ToArgv()
fixupSha, err := self.cmd.New(cmdArgs).RunWithOutput()
fixupHash, err := self.cmd.New(cmdArgs).RunWithOutput()
if err != nil {
return err
}
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: getBaseShaOrRoot(commits, commitIndex+1),
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex+1),
overrideEditor: true,
instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Sha, fixupSha),
instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Hash, fixupHash),
}).Run()
}
@ -306,7 +306,7 @@ func todoFromCommit(commit *models.Commit) utils.Todo {
if commit.Action == todo.UpdateRef {
return utils.Todo{Ref: commit.Name, Action: commit.Action}
} else {
return utils.Todo{Sha: commit.Sha, Action: commit.Action}
return utils.Todo{Hash: commit.Hash, Action: commit.Action}
}
}
@ -314,7 +314,7 @@ func todoFromCommit(commit *models.Commit) utils.Todo {
func (self *RebaseCommands) EditRebaseTodo(commits []*models.Commit, action todo.TodoCommand) error {
commitsWithAction := lo.Map(commits, func(commit *models.Commit, _ int) utils.TodoChange {
return utils.TodoChange{
Sha: commit.Sha,
Hash: commit.Hash,
OldAction: commit.Action,
NewAction: action,
}
@ -364,13 +364,13 @@ func (self *RebaseCommands) MoveTodosUp(commits []*models.Commit) error {
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
func (self *RebaseCommands) SquashAllAboveFixupCommits(commit *models.Commit) error {
shaOrRoot := commit.Sha + "^"
hashOrRoot := commit.Hash + "^"
if commit.IsFirstCommit() {
shaOrRoot = "--root"
hashOrRoot = "--root"
}
cmdArgs := NewGitCmd("rebase").
Arg("--interactive", "--rebase-merges", "--autostash", "--autosquash", shaOrRoot).
Arg("--interactive", "--rebase-merges", "--autostash", "--autosquash", hashOrRoot).
ToArgv()
return self.runSkipEditorCommand(self.cmd.New(cmdArgs))
@ -393,13 +393,13 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
}
changes := []daemon.ChangeTodoAction{{
Sha: commits[commitIndex].Sha,
Hash: commits[commitIndex].Hash,
NewAction: todo.Edit,
}}
self.os.LogCommand(logTodoChanges(changes), false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: getBaseShaOrRoot(commits, commitIndex+1),
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex+1),
overrideEditor: true,
keepCommitsThatBecomeEmpty: keepCommitsThatBecomeEmpty,
instruction: daemon.NewChangeTodoActionsInstruction(changes),
@ -408,13 +408,13 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
// RebaseBranch interactive rebases onto a branch
func (self *RebaseCommands) RebaseBranch(branchName string) error {
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{baseShaOrRoot: branchName}).Run()
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{baseHashOrRoot: branchName}).Run()
}
func (self *RebaseCommands) RebaseBranchFromBaseCommit(targetBranchName string, baseCommit string) error {
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseCommit,
onto: targetBranchName,
baseHashOrRoot: baseCommit,
onto: targetBranchName,
}).Run()
}
@ -503,10 +503,10 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm
return self.ContinueRebase()
}
// CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD
// CherryPickCommits begins an interactive rebase with the given hashes being cherry picked onto HEAD
func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error {
commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string {
return fmt.Sprintf("%s %s", utils.ShortSha(commit.Sha), commit.Name)
return fmt.Sprintf("%s %s", utils.ShortHash(commit.Hash), commit.Name)
})
msg := utils.ResolvePlaceholderString(
self.Tr.Log.CherryPickCommits,
@ -517,8 +517,8 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error {
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: "HEAD",
instruction: daemon.NewCherryPickCommitsInstruction(commits),
baseHashOrRoot: "HEAD",
instruction: daemon.NewCherryPickCommitsInstruction(commits),
}).Run()
}
@ -538,13 +538,13 @@ func (self *RebaseCommands) CherryPickCommitsDuringRebase(commits []*models.Comm
// we can't start an interactive rebase from the first commit without passing the
// '--root' arg
func getBaseShaOrRoot(commits []*models.Commit, index int) string {
func getBaseHashOrRoot(commits []*models.Commit, index int) string {
// We assume that the commits slice contains the initial commit of the repo.
// Technically this assumption could prove false, but it's unlikely you'll
// be starting a rebase from 300 commits ago (which is the original commit limit
// at time of writing)
if index < len(commits) {
return commits[index].Sha
return commits[index].Hash
} else {
return "--root"
}

View File

@ -131,7 +131,7 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) {
{
testName: "returns error when using gpg",
gitConfigMockResponses: map[string]string{"commit.gpgsign": "true"},
commits: []*models.Commit{{Name: "commit", Sha: "123456"}},
commits: []*models.Commit{{Name: "commit", Hash: "123456"}},
commitIndex: 0,
fileName: []string{"test999.txt"},
runner: oscommands.NewFakeRunner(t),
@ -143,8 +143,8 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) {
testName: "checks out file if it already existed",
gitConfigMockResponses: nil,
commits: []*models.Commit{
{Name: "commit", Sha: "123456"},
{Name: "commit2", Sha: "abcdef"},
{Name: "commit", Hash: "123456"},
{Name: "commit2", Hash: "abcdef"},
},
commitIndex: 0,
fileName: []string{"test999.txt"},

View File

@ -45,7 +45,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit
}
// note that the unix timestamp here is the timestamp of the COMMIT, not the reflog entry itself,
// so two consecutive reflog entries may have both the same SHA and therefore same timestamp.
// so two consecutive reflog entries may have both the same hash and therefore same timestamp.
// We use the reflog message to disambiguate, and fingers crossed that we never see the same of those
// twice in a row. Reason being that it would mean we'd be erroneously exiting early.
if lastReflogCommit != nil && self.sameReflogCommit(commit, lastReflogCommit) {
@ -65,7 +65,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit
}
func (self *ReflogCommitLoader) sameReflogCommit(a *models.Commit, b *models.Commit) bool {
return a.Sha == b.Sha && a.UnixTimestamp == b.UnixTimestamp && a.Name == b.Name
return a.Hash == b.Hash && a.UnixTimestamp == b.UnixTimestamp && a.Name == b.Name
}
func (self *ReflogCommitLoader) parseLine(line string) (*models.Commit, bool) {
@ -83,7 +83,7 @@ func (self *ReflogCommitLoader) parseLine(line string) (*models.Commit, bool) {
}
return &models.Commit{
Sha: fields[0],
Hash: fields[0],
Name: fields[2],
UnixTimestamp: int64(unixTimestamp),
Status: models.StatusReflog,

View File

@ -50,35 +50,35 @@ func TestGetReflogCommits(t *testing.T) {
lastReflogCommit: nil,
expectedCommits: []*models.Commit{
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from A to B",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
Parents: []string{"51baa8c1"},
},
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from B to A",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
Parents: []string{"51baa8c1"},
},
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from A to B",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
Parents: []string{"51baa8c1"},
},
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from master to A",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
Parents: []string{"51baa8c1"},
},
{
Sha: "f4ddf2f0d4be4ccc7efa",
Hash: "f4ddf2f0d4be4ccc7efa",
Name: "checkout: moving from A to master",
Status: models.StatusReflog,
UnixTimestamp: 1643149435,
@ -94,7 +94,7 @@ func TestGetReflogCommits(t *testing.T) {
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, reflogOutput, nil),
lastReflogCommit: &models.Commit{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from B to A",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
@ -102,7 +102,7 @@ func TestGetReflogCommits(t *testing.T) {
},
expectedCommits: []*models.Commit{
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from A to B",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
@ -118,7 +118,7 @@ func TestGetReflogCommits(t *testing.T) {
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--follow", "--", "path"}, reflogOutput, nil),
lastReflogCommit: &models.Commit{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from B to A",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
@ -127,7 +127,7 @@ func TestGetReflogCommits(t *testing.T) {
filterPath: "path",
expectedCommits: []*models.Commit{
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from A to B",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
@ -143,7 +143,7 @@ func TestGetReflogCommits(t *testing.T) {
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--author=John Doe <john@doe.com>"}, reflogOutput, nil),
lastReflogCommit: &models.Commit{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from B to A",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,
@ -152,7 +152,7 @@ func TestGetReflogCommits(t *testing.T) {
filterAuthor: "John Doe <john@doe.com>",
expectedCommits: []*models.Commit{
{
Sha: "c3c4b66b64c97ffeecde",
Hash: "c3c4b66b64c97ffeecde",
Name: "checkout: moving from A to B",
Status: models.StatusReflog,
UnixTimestamp: 1643150483,

View File

@ -60,24 +60,24 @@ func (self *StashCommands) Push(message string) error {
return self.cmd.New(cmdArgs).Run()
}
func (self *StashCommands) Store(sha string, message string) error {
func (self *StashCommands) Store(hash string, message string) error {
trimmedMessage := strings.Trim(message, " \t")
cmdArgs := NewGitCmd("stash").Arg("store").
ArgIf(trimmedMessage != "", "-m", trimmedMessage).
Arg(sha).
Arg(hash).
ToArgv()
return self.cmd.New(cmdArgs).Run()
}
func (self *StashCommands) Sha(index int) (string, error) {
func (self *StashCommands) Hash(index int) (string, error) {
cmdArgs := NewGitCmd("rev-parse").
Arg(fmt.Sprintf("refs/stash@{%d}", index)).
ToArgv()
sha, _, err := self.cmd.New(cmdArgs).DontLog().RunWithOutputs()
return strings.Trim(sha, "\r\n"), err
hash, _, err := self.cmd.New(cmdArgs).DontLog().RunWithOutputs()
return strings.Trim(hash, "\r\n"), err
}
func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
@ -179,7 +179,7 @@ func (self *StashCommands) StashIncludeUntrackedChanges(message string) error {
}
func (self *StashCommands) Rename(index int, message string) error {
sha, err := self.Sha(index)
hash, err := self.Hash(index)
if err != nil {
return err
}
@ -188,7 +188,7 @@ func (self *StashCommands) Rename(index int, message string) error {
return err
}
err = self.Store(sha, message)
err = self.Store(hash, message)
if err != nil {
return err
}

View File

@ -47,7 +47,7 @@ func TestStashSave(t *testing.T) {
func TestStashStore(t *testing.T) {
type scenario struct {
testName string
sha string
hash string
message string
expected []string
}
@ -55,19 +55,19 @@ func TestStashStore(t *testing.T) {
scenarios := []scenario{
{
testName: "Non-empty message",
sha: "0123456789abcdef",
hash: "0123456789abcdef",
message: "New stash name",
expected: []string{"stash", "store", "-m", "New stash name", "0123456789abcdef"},
},
{
testName: "Empty message",
sha: "0123456789abcdef",
hash: "0123456789abcdef",
message: "",
expected: []string{"stash", "store", "0123456789abcdef"},
},
{
testName: "Space message",
sha: "0123456789abcdef",
hash: "0123456789abcdef",
message: " ",
expected: []string{"stash", "store", "0123456789abcdef"},
},
@ -80,20 +80,20 @@ func TestStashStore(t *testing.T) {
ExpectGitArgs(s.expected, "", nil)
instance := buildStashCommands(commonDeps{runner: runner})
assert.NoError(t, instance.Store(s.sha, s.message))
assert.NoError(t, instance.Store(s.hash, s.message))
runner.CheckForMissingCalls()
})
}
}
func TestStashSha(t *testing.T) {
func TestStashHash(t *testing.T) {
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"rev-parse", "refs/stash@{5}"}, "14d94495194651adfd5f070590df566c11d28243\n", nil)
instance := buildStashCommands(commonDeps{runner: runner})
sha, err := instance.Sha(5)
hash, err := instance.Hash(5)
assert.NoError(t, err)
assert.Equal(t, "14d94495194651adfd5f070590df566c11d28243", sha)
assert.Equal(t, "14d94495194651adfd5f070590df566c11d28243", hash)
runner.CheckForMissingCalls()
}
@ -153,8 +153,8 @@ func TestStashRename(t *testing.T) {
testName string
index int
message string
expectedShaCmd []string
shaResult string
expectedHashCmd []string
hashResult string
expectedDropCmd []string
expectedStoreCmd []string
}
@ -164,8 +164,8 @@ func TestStashRename(t *testing.T) {
testName: "Default case",
index: 3,
message: "New message",
expectedShaCmd: []string{"rev-parse", "refs/stash@{3}"},
shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedHashCmd: []string{"rev-parse", "refs/stash@{3}"},
hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedDropCmd: []string{"stash", "drop", "stash@{3}"},
expectedStoreCmd: []string{"stash", "store", "-m", "New message", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
},
@ -173,8 +173,8 @@ func TestStashRename(t *testing.T) {
testName: "Empty message",
index: 4,
message: "",
expectedShaCmd: []string{"rev-parse", "refs/stash@{4}"},
shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedHashCmd: []string{"rev-parse", "refs/stash@{4}"},
hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedDropCmd: []string{"stash", "drop", "stash@{4}"},
expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
},
@ -184,7 +184,7 @@ func TestStashRename(t *testing.T) {
s := s
t.Run(s.testName, func(t *testing.T) {
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs(s.expectedShaCmd, s.shaResult, nil).
ExpectGitArgs(s.expectedHashCmd, s.hashResult, nil).
ExpectGitArgs(s.expectedDropCmd, "", nil).
ExpectGitArgs(s.expectedStoreCmd, "", nil)
instance := buildStashCommands(commonDeps{runner: runner})

View File

@ -313,8 +313,8 @@ func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reve
}
// CheckoutFile checks out the file for the given commit
func (self *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error {
cmdArgs := NewGitCmd("checkout").Arg(commitSha, "--", fileName).
func (self *WorkingTreeCommands) CheckoutFile(commitHash, fileName string) error {
cmdArgs := NewGitCmd("checkout").Arg(commitHash, "--", fileName).
ToArgv()
return self.cmd.New(cmdArgs).Run()

View File

@ -397,18 +397,18 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
func TestWorkingTreeCheckoutFile(t *testing.T) {
type scenario struct {
testName string
commitSha string
fileName string
runner *oscommands.FakeCmdObjRunner
test func(error)
testName string
commitHash string
fileName string
runner *oscommands.FakeCmdObjRunner
test func(error)
}
scenarios := []scenario{
{
testName: "typical case",
commitSha: "11af912",
fileName: "test999.txt",
testName: "typical case",
commitHash: "11af912",
fileName: "test999.txt",
runner: oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"checkout", "11af912", "--", "test999.txt"}, "", nil),
test: func(err error) {
@ -416,9 +416,9 @@ func TestWorkingTreeCheckoutFile(t *testing.T) {
},
},
{
testName: "returns error if there is one",
commitSha: "11af912",
fileName: "test999.txt",
testName: "returns error if there is one",
commitHash: "11af912",
fileName: "test999.txt",
runner: oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"checkout", "11af912", "--", "test999.txt"}, "", errors.New("error")),
test: func(err error) {
@ -432,7 +432,7 @@ func TestWorkingTreeCheckoutFile(t *testing.T) {
t.Run(s.testName, func(t *testing.T) {
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
s.test(instance.CheckoutFile(s.commitSha, s.fileName))
s.test(instance.CheckoutFile(s.commitHash, s.fileName))
s.runner.CheckForMissingCalls()
})
}

View File

@ -14,7 +14,7 @@ var githubServiceDef = ServiceDefinition{
provider: "github",
pullRequestURLIntoDefaultBranch: "/compare/{{.From}}?expand=1",
pullRequestURLIntoTargetBranch: "/compare/{{.To}}...{{.From}}?expand=1",
commitURL: "/commit/{{.CommitSha}}",
commitURL: "/commit/{{.CommitHash}}",
regexStrings: defaultUrlRegexStrings,
repoURLTemplate: defaultRepoURLTemplate,
}
@ -23,7 +23,7 @@ var bitbucketServiceDef = ServiceDefinition{
provider: "bitbucket",
pullRequestURLIntoDefaultBranch: "/pull-requests/new?source={{.From}}&t=1",
pullRequestURLIntoTargetBranch: "/pull-requests/new?source={{.From}}&dest={{.To}}&t=1",
commitURL: "/commits/{{.CommitSha}}",
commitURL: "/commits/{{.CommitHash}}",
regexStrings: []string{
`^(?:https?|ssh)://.*/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^.*@.*:(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
@ -35,7 +35,7 @@ var gitLabServiceDef = ServiceDefinition{
provider: "gitlab",
pullRequestURLIntoDefaultBranch: "/-/merge_requests/new?merge_request[source_branch]={{.From}}",
pullRequestURLIntoTargetBranch: "/-/merge_requests/new?merge_request[source_branch]={{.From}}&merge_request[target_branch]={{.To}}",
commitURL: "/-/commit/{{.CommitSha}}",
commitURL: "/-/commit/{{.CommitHash}}",
regexStrings: defaultUrlRegexStrings,
repoURLTemplate: defaultRepoURLTemplate,
}
@ -44,7 +44,7 @@ var azdoServiceDef = ServiceDefinition{
provider: "azuredevops",
pullRequestURLIntoDefaultBranch: "/pullrequestcreate?sourceRef={{.From}}",
pullRequestURLIntoTargetBranch: "/pullrequestcreate?sourceRef={{.From}}&targetRef={{.To}}",
commitURL: "/commit/{{.CommitSha}}",
commitURL: "/commit/{{.CommitHash}}",
regexStrings: []string{
`^git@ssh.dev.azure.com.*/(?P<org>.*)/(?P<project>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^https://.*@dev.azure.com/(?P<org>.*?)/(?P<project>.*?)/_git/(?P<repo>.*?)(?:\.git)?$`,
@ -56,7 +56,7 @@ var bitbucketServerServiceDef = ServiceDefinition{
provider: "bitbucketServer",
pullRequestURLIntoDefaultBranch: "/pull-requests?create&sourceBranch={{.From}}",
pullRequestURLIntoTargetBranch: "/pull-requests?create&targetBranch={{.To}}&sourceBranch={{.From}}",
commitURL: "/commits/{{.CommitSha}}",
commitURL: "/commits/{{.CommitHash}}",
regexStrings: []string{
`^ssh://git@.*/(?P<project>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^https://.*/scm/(?P<project>.*)/(?P<repo>.*?)(?:\.git)?$`,
@ -68,7 +68,7 @@ var giteaServiceDef = ServiceDefinition{
provider: "gitea",
pullRequestURLIntoDefaultBranch: "/compare/{{.From}}",
pullRequestURLIntoTargetBranch: "/compare/{{.To}}...{{.From}}",
commitURL: "/commit/{{.CommitSha}}",
commitURL: "/commit/{{.CommitHash}}",
regexStrings: defaultUrlRegexStrings,
repoURLTemplate: defaultRepoURLTemplate,
}

View File

@ -51,13 +51,13 @@ func (self *HostingServiceMgr) GetPullRequestURL(from string, to string) (string
}
}
func (self *HostingServiceMgr) GetCommitURL(commitSha string) (string, error) {
func (self *HostingServiceMgr) GetCommitURL(commitHash string) (string, error) {
gitService, err := self.getService()
if err != nil {
return "", err
}
pullRequestURL := gitService.getCommitURL(commitSha)
pullRequestURL := gitService.getCommitURL(commitHash)
return pullRequestURL, nil
}
@ -174,8 +174,8 @@ func (self *Service) getPullRequestURLIntoTargetBranch(from string, to string) s
return self.resolveUrl(self.pullRequestURLIntoTargetBranch, map[string]string{"From": from, "To": to})
}
func (self *Service) getCommitURL(commitSha string) string {
return self.resolveUrl(self.commitURL, map[string]string{"CommitSha": commitSha})
func (self *Service) getCommitURL(commitHash string) string {
return self.resolveUrl(self.commitURL, map[string]string{"CommitHash": commitHash})
}
func (self *Service) resolveUrl(templateString string, args map[string]string) string {

View File

@ -43,7 +43,7 @@ const (
// Commit : A git commit
type Commit struct {
Sha string
Hash string
Name string
Status CommitStatus
Action todo.TodoCommand
@ -54,20 +54,20 @@ type Commit struct {
UnixTimestamp int64
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
// SHAs of parent commits (will be multiple if it's a merge commit)
// Hashes of parent commits (will be multiple if it's a merge commit)
Parents []string
}
func (c *Commit) ShortSha() string {
return utils.ShortSha(c.Sha)
func (c *Commit) ShortHash() string {
return utils.ShortHash(c.Hash)
}
func (c *Commit) FullRefName() string {
return c.Sha
return c.Hash
}
func (c *Commit) RefName() string {
return c.Sha
return c.Hash
}
func (c *Commit) ParentRefName() string {
@ -86,7 +86,7 @@ func (c *Commit) ID() string {
}
func (c *Commit) Description() string {
return fmt.Sprintf("%s %s", c.Sha[:7], c.Name)
return fmt.Sprintf("%s %s", c.Hash[:7], c.Name)
}
func (c *Commit) IsMerge() bool {

View File

@ -33,7 +33,7 @@ type (
// PatchBuilder manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility
type PatchBuilder struct {
// To is the commit sha if we're dealing with files of a commit, or a stash ref for a stash
// To is the commit hash if we're dealing with files of a commit, or a stash ref for a stash
To string
From string
reverse bool
@ -46,7 +46,7 @@ type PatchBuilder struct {
fileInfoMap map[string]*fileInfo
Log *logrus.Entry
// loadFileDiff loads the diff of a file, for a given to (typically a commit SHA)
// loadFileDiff loads the diff of a file, for a given to (typically a commit hash)
loadFileDiff loadFileDiffFunc
}

View File

@ -29,12 +29,12 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
)
getDisplayStrings := func(startIdx int, endIdx int) [][]string {
selectedCommitSha := ""
selectedCommitHash := ""
if c.CurrentContext().GetKey() == LOCAL_COMMITS_CONTEXT_KEY {
selectedCommit := viewModel.GetSelected()
if selectedCommit != nil {
selectedCommitSha = selectedCommit.Sha
selectedCommitHash = selectedCommit.Hash
}
}
@ -48,14 +48,14 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
c.Model().CheckedOutBranch,
hasRebaseUpdateRefsConfig,
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(),
c.Modes().CherryPicking.SelectedHashSet(),
c.Modes().Diffing.Ref,
c.Modes().MarkedBaseCommit.GetSha(),
c.Modes().MarkedBaseCommit.GetHash(),
c.UserConfig.Gui.TimeFormat,
c.UserConfig.Gui.ShortTimeFormat,
time.Now(),
c.UserConfig.Git.ParseEmoji,
selectedCommitSha,
selectedCommitHash,
startIdx,
endIdx,
shouldShowGraph(c),
@ -133,7 +133,7 @@ func (self *LocalCommitsContext) GetSelectedCommitHash() string {
if commit == nil {
return ""
}
return commit.Sha
return commit.Hash
}
func (self *LocalCommitsContext) SelectCommitByHash(hash string) bool {
@ -141,7 +141,7 @@ func (self *LocalCommitsContext) SelectCommitByHash(hash string) bool {
return false
}
if _, idx, found := lo.FindIndexOf(self.GetItems(), func(c *models.Commit) bool { return c.Sha == hash }); found {
if _, idx, found := lo.FindIndexOf(self.GetItems(), func(c *models.Commit) bool { return c.Hash == hash }); found {
self.SetSelection(idx)
return true
}

View File

@ -22,7 +22,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
viewModel := NewFilteredListViewModel(
func() []*models.Commit { return c.Model().FilteredReflogCommits },
func(commit *models.Commit) []string {
return []string{commit.ShortSha(), commit.Name}
return []string{commit.ShortHash(), commit.Name}
},
)
@ -30,7 +30,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
return presentation.GetReflogCommitListDisplayStrings(
viewModel.GetItems(),
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(),
c.Modes().CherryPicking.SelectedHashSet(),
c.Modes().Diffing.Ref,
time.Now(),
c.UserConfig.Gui.TimeFormat,

View File

@ -44,11 +44,11 @@ func NewSubCommitsContext(
return [][]string{}
}
selectedCommitSha := ""
selectedCommitHash := ""
if c.CurrentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY {
selectedCommit := viewModel.GetSelected()
if selectedCommit != nil {
selectedCommitSha = selectedCommit.Sha
selectedCommitHash = selectedCommit.Hash
}
}
branches := []*models.Branch{}
@ -63,14 +63,14 @@ func NewSubCommitsContext(
viewModel.GetRef().RefName(),
hasRebaseUpdateRefsConfig,
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(),
c.Modes().CherryPicking.SelectedHashSet(),
c.Modes().Diffing.Ref,
"",
c.UserConfig.Gui.TimeFormat,
c.UserConfig.Gui.ShortTimeFormat,
time.Now(),
c.UserConfig.Git.ParseEmoji,
selectedCommitSha,
selectedCommitHash,
startIdx,
endIdx,
// Don't show the graph in the left/right view; we'd like to, but

View File

@ -125,9 +125,9 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard,
Items: []*types.MenuItem{
{
Label: self.c.Tr.CommitSha,
Label: self.c.Tr.CommitHash,
OnPress: func() error {
return self.copyCommitSHAToClipboard(commit)
return self.copyCommitHashToClipboard(commit)
},
},
{
@ -169,18 +169,18 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
})
}
func (self *BasicCommitsController) copyCommitSHAToClipboard(commit *models.Commit) error {
self.c.LogAction(self.c.Tr.Actions.CopyCommitSHAToClipboard)
if err := self.c.OS().CopyToClipboard(commit.Sha); err != nil {
func (self *BasicCommitsController) copyCommitHashToClipboard(commit *models.Commit) error {
self.c.LogAction(self.c.Tr.Actions.CopyCommitHashToClipboard)
if err := self.c.OS().CopyToClipboard(commit.Hash); err != nil {
return self.c.Error(err)
}
self.c.Toast(fmt.Sprintf("'%s' %s", commit.Sha, self.c.Tr.CopiedToClipboard))
self.c.Toast(fmt.Sprintf("'%s' %s", commit.Hash, self.c.Tr.CopiedToClipboard))
return nil
}
func (self *BasicCommitsController) copyCommitURLToClipboard(commit *models.Commit) error {
url, err := self.c.Helpers().Host.GetCommitURL(commit.Sha)
url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -195,7 +195,7 @@ func (self *BasicCommitsController) copyCommitURLToClipboard(commit *models.Comm
}
func (self *BasicCommitsController) copyCommitDiffToClipboard(commit *models.Commit) error {
diff, err := self.c.Git().Commit.GetCommitDiff(commit.Sha)
diff, err := self.c.Git().Commit.GetCommitDiff(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -210,7 +210,7 @@ func (self *BasicCommitsController) copyCommitDiffToClipboard(commit *models.Com
}
func (self *BasicCommitsController) copyAuthorToClipboard(commit *models.Commit) error {
author, err := self.c.Git().Commit.GetCommitAuthor(commit.Sha)
author, err := self.c.Git().Commit.GetCommitAuthor(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -227,7 +227,7 @@ func (self *BasicCommitsController) copyAuthorToClipboard(commit *models.Commit)
}
func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error {
message, err := self.c.Git().Commit.GetCommitMessage(commit.Sha)
message, err := self.c.Git().Commit.GetCommitMessage(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -242,7 +242,7 @@ func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models.
}
func (self *BasicCommitsController) copyCommitSubjectToClipboard(commit *models.Commit) error {
message, err := self.c.Git().Commit.GetCommitSubject(commit.Sha)
message, err := self.c.Git().Commit.GetCommitSubject(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -257,7 +257,7 @@ func (self *BasicCommitsController) copyCommitSubjectToClipboard(commit *models.
}
func (self *BasicCommitsController) openInBrowser(commit *models.Commit) error {
url, err := self.c.Helpers().Host.GetCommitURL(commit.Sha)
url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -275,7 +275,7 @@ func (self *BasicCommitsController) newBranch(commit *models.Commit) error {
}
func (self *BasicCommitsController) createResetMenu(commit *models.Commit) error {
return self.c.Helpers().Refs.CreateGitResetMenu(commit.Sha)
return self.c.Helpers().Refs.CreateGitResetMenu(commit.Hash)
}
func (self *BasicCommitsController) checkout(commit *models.Commit) error {
@ -284,7 +284,7 @@ func (self *BasicCommitsController) checkout(commit *models.Commit) error {
Prompt: self.c.Tr.SureCheckoutThisCommit,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.CheckoutCommit)
return self.c.Helpers().Refs.CheckoutRef(commit.Sha, types.CheckoutRefOptions{})
return self.c.Helpers().Refs.CheckoutRef(commit.Hash, types.CheckoutRefOptions{})
},
})
}
@ -295,7 +295,7 @@ func (self *BasicCommitsController) copyRange(*models.Commit) error {
func (self *BasicCommitsController) canCopyCommits(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason {
for _, commit := range selectedCommits {
if commit.Sha == "" {
if commit.Hash == "" {
return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickNonCommit, ShowErrorInPanel: true}
}

View File

@ -69,18 +69,18 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
// Originally we were allowing the user to, from the bisect menu, select whether
// they were talking about the selected commit or the current bisect commit,
// and that was a bit confusing (and required extra keypresses).
selectCurrentAfter := info.GetCurrentSha() == "" || info.GetCurrentSha() == commit.Sha
selectCurrentAfter := info.GetCurrentHash() == "" || info.GetCurrentHash() == commit.Hash
// we need to wait to reselect if our bisect commits aren't ancestors of our 'start'
// ref, because we'll be reloading our commits in that case.
waitToReselect := selectCurrentAfter && !self.c.Git().Bisect.ReachableFromStart(info)
// If we have a current sha already, then we always want to use that one. If
// If we have a current hash already, then we always want to use that one. If
// not, we're still picking the initial commits before we really start, so
// use the selected commit in that case.
bisecting := info.GetCurrentSha() != ""
shaToMark := lo.Ternary(bisecting, info.GetCurrentSha(), commit.Sha)
shortShaToMark := utils.ShortSha(shaToMark)
bisecting := info.GetCurrentHash() != ""
hashToMark := lo.Ternary(bisecting, info.GetCurrentHash(), commit.Hash)
shortHashToMark := utils.ShortHash(hashToMark)
// For marking a commit as bad, when we're not already bisecting, we require
// a single item selected, but once we are bisecting, it doesn't matter because
@ -92,10 +92,10 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
menuItems := []*types.MenuItem{
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortShaToMark, info.NewTerm()),
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.NewTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(shaToMark, info.NewTerm()); err != nil {
if err := self.c.Git().Bisect.Mark(hashToMark, info.NewTerm()); err != nil {
return self.c.Error(err)
}
@ -105,10 +105,10 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 'b',
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortShaToMark, info.OldTerm()),
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.OldTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(shaToMark, info.OldTerm()); err != nil {
if err := self.c.Git().Bisect.Mark(hashToMark, info.OldTerm()); err != nil {
return self.c.Error(err)
}
@ -118,10 +118,10 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 'g',
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortShaToMark),
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortHashToMark),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(shaToMark); err != nil {
if err := self.c.Git().Bisect.Skip(hashToMark); err != nil {
return self.c.Error(err)
}
@ -131,12 +131,12 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 's',
},
}
if info.GetCurrentSha() != "" && info.GetCurrentSha() != commit.Sha {
if info.GetCurrentHash() != "" && info.GetCurrentHash() != commit.Hash {
menuItems = append(menuItems, lo.ToPtr(types.MenuItem{
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortSha()),
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortHash()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(commit.Sha); err != nil {
if err := self.c.Git().Bisect.Skip(commit.Hash); err != nil {
return self.c.Error(err)
}
@ -165,14 +165,14 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
Title: self.c.Tr.Bisect.BisectMenuTitle,
Items: []*types.MenuItem{
{
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.NewTerm()),
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.NewTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.Start(); err != nil {
return self.c.Error(err)
}
if err := self.c.Git().Bisect.Mark(commit.Sha, info.NewTerm()); err != nil {
if err := self.c.Git().Bisect.Mark(commit.Hash, info.NewTerm()); err != nil {
return self.c.Error(err)
}
@ -182,14 +182,14 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
Key: 'b',
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()),
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.OldTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.Start(); err != nil {
return self.c.Error(err)
}
if err := self.c.Git().Bisect.Mark(commit.Sha, info.OldTerm()); err != nil {
if err := self.c.Git().Bisect.Mark(commit.Hash, info.OldTerm()); err != nil {
return self.c.Error(err)
}
@ -224,13 +224,13 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
})
}
func (self *BisectController) showBisectCompleteMessage(candidateShas []string) error {
func (self *BisectController) showBisectCompleteMessage(candidateHashes []string) error {
prompt := self.c.Tr.Bisect.CompletePrompt
if len(candidateShas) > 1 {
if len(candidateHashes) > 1 {
prompt = self.c.Tr.Bisect.CompletePromptIndeterminate
}
formattedCommits, err := self.c.Git().Commit.GetCommitsOneline(candidateShas)
formattedCommits, err := self.c.Git().Commit.GetCommitsOneline(candidateHashes)
if err != nil {
return self.c.Error(err)
}
@ -250,7 +250,7 @@ func (self *BisectController) showBisectCompleteMessage(candidateShas []string)
}
func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool) error {
done, candidateShas, err := self.c.Git().Bisect.IsDone()
done, candidateHashes, err := self.c.Git().Bisect.IsDone()
if err != nil {
return self.c.Error(err)
}
@ -260,7 +260,7 @@ func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool)
}
if done {
return self.showBisectCompleteMessage(candidateShas)
return self.showBisectCompleteMessage(candidateHashes)
}
return nil
@ -284,10 +284,10 @@ func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToR
func (self *BisectController) selectCurrentBisectCommit() {
info := self.c.Git().Bisect.GetInfo()
if info.GetCurrentSha() != "" {
// find index of commit with that sha, move cursor to that.
if info.GetCurrentHash() != "" {
// find index of commit with that hash, move cursor to that.
for i, commit := range self.c.Model().Commits {
if commit.Sha == info.GetCurrentSha() {
if commit.Hash == info.GetCurrentHash() {
self.context().SetSelection(i)
_ = self.context().HandleFocus(types.OnFocusOpts{})
break

View File

@ -67,7 +67,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
if self.c.CurrentContext().GetKey() == self.c.Contexts().LocalCommits.GetKey() {
selectedCommit := self.c.Contexts().LocalCommits.GetSelected()
if selectedCommit != nil && self.c.Git().Patch.PatchBuilder.To != selectedCommit.Sha {
if selectedCommit != nil && self.c.Git().Patch.PatchBuilder.To != selectedCommit.Hash {
var disabledReason *types.DisabledReason
if self.c.Contexts().LocalCommits.AreMultipleItemsSelected() {
@ -80,7 +80,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
append(
[]*types.MenuItem{
{
Label: fmt.Sprintf(self.c.Tr.MovePatchToSelectedCommit, selectedCommit.Sha),
Label: fmt.Sprintf(self.c.Tr.MovePatchToSelectedCommit, selectedCommit.Hash),
Tooltip: self.c.Tr.MovePatchToSelectedCommitTooltip,
OnPress: self.handleMovePatchToSelectedCommit,
Key: 'm',
@ -106,7 +106,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
func (self *CustomPatchOptionsMenuAction) getPatchCommitIndex() int {
for index, commit := range self.c.Model().Commits {
if commit.Sha == self.c.Git().Patch.PatchBuilder.To {
if commit.Hash == self.c.Git().Patch.PatchBuilder.To {
return index
}
}

View File

@ -38,10 +38,10 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
return err
}
commitSet := self.getData().SelectedShaSet()
commitSet := self.getData().SelectedHashSet()
allCommitsCopied := lo.EveryBy(commitsList[startIdx:endIdx+1], func(commit *models.Commit) bool {
return commitSet.Includes(commit.Sha)
return commitSet.Includes(commit.Hash)
})
// if all selected commits are already copied, we'll uncopy them

View File

@ -44,14 +44,14 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
return self.c.ErrorMsg(self.c.Tr.NoDeletedLinesInDiff)
}
shas := self.blameDeletedLines(deletedLineInfos)
hashes := self.blameDeletedLines(deletedLineInfos)
if len(shas) == 0 {
if len(hashes) == 0 {
// This should never happen
return self.c.ErrorMsg(self.c.Tr.NoBaseCommitsFound)
}
if len(shas) > 1 {
subjects, err := self.c.Git().Commit.GetShasAndCommitMessagesFirstLine(shas)
if len(hashes) > 1 {
subjects, err := self.c.Git().Commit.GetHashesAndCommitMessagesFirstLine(hashes)
if err != nil {
return err
}
@ -62,7 +62,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
}
commit, index, ok := lo.FindIndexOf(self.c.Model().Commits, func(commit *models.Commit) bool {
return commit.Sha == shas[0]
return commit.Hash == hashes[0]
})
if !ok {
commits := self.c.Model().Commits
@ -164,7 +164,7 @@ func (self *FixupHelper) parseDiff(diff string) ([]*deletedLineInfo, bool) {
// returns the list of commit hashes that introduced the lines which have now been deleted
func (self *FixupHelper) blameDeletedLines(deletedLineInfos []*deletedLineInfo) []string {
var wg sync.WaitGroup
shaChan := make(chan string)
hashChan := make(chan string)
for _, info := range deletedLineInfos {
wg.Add(1)
@ -178,19 +178,19 @@ func (self *FixupHelper) blameDeletedLines(deletedLineInfos []*deletedLineInfo)
}
blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n")
for _, line := range blameLines {
shaChan <- strings.Split(line, " ")[0]
hashChan <- strings.Split(line, " ")[0]
}
}(info)
}
go func() {
wg.Wait()
close(shaChan)
close(hashChan)
}()
result := set.New[string]()
for sha := range shaChan {
result.Add(sha)
for hash := range hashChan {
result.Add(hash)
}
return result.ToSlice()

View File

@ -8,7 +8,7 @@ import (
type IHostHelper interface {
GetPullRequestURL(from string, to string) (string, error)
GetCommitURL(commitSha string) (string, error)
GetCommitURL(commitHash string) (string, error)
}
type HostHelper struct {
@ -31,12 +31,12 @@ func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error
return mgr.GetPullRequestURL(from, to)
}
func (self *HostHelper) GetCommitURL(commitSha string) (string, error) {
func (self *HostHelper) GetCommitURL(commitHash string) (string, error) {
mgr, err := self.getHostingServiceMgr()
if err != nil {
return "", err
}
return mgr.GetCommitURL(commitSha)
return mgr.GetCommitURL(commitHash)
}
// getting this on every request rather than storing it in state in case our remoteURL changes

View File

@ -241,7 +241,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(task gocui.Task) error {
baseCommit := self.c.Modes().MarkedBaseCommit.GetSha()
baseCommit := self.c.Modes().MarkedBaseCommit.GetHash()
var err error
if baseCommit != "" {
err = self.c.Git().Rebase.RebaseBranchFromBaseCommit(ref, baseCommit)
@ -262,7 +262,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
Tooltip: self.c.Tr.InteractiveRebaseTooltip,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
baseCommit := self.c.Modes().MarkedBaseCommit.GetSha()
baseCommit := self.c.Modes().MarkedBaseCommit.GetHash()
var err error
if baseCommit != "" {
err = self.c.Git().Rebase.EditRebaseFromBaseCommit(ref, baseCommit)
@ -281,7 +281,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
}
title := utils.ResolvePlaceholderString(
lo.Ternary(self.c.Modes().MarkedBaseCommit.GetSha() != "",
lo.Ternary(self.c.Modes().MarkedBaseCommit.GetHash() != "",
self.c.Tr.RebasingFromBaseCommitTitle,
self.c.Tr.RebasingTitle),
map[string]string{

View File

@ -267,7 +267,7 @@ func (self *RefreshHelper) refreshCommitsAndCommitFiles() {
_ = self.refreshCommitsWithLimit()
ctx, ok := self.c.Contexts().CommitFiles.GetParentContext()
if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position.
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit hash at the same position.
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
// showing the contents of a different commit than the one we initially entered.
// Ideally we would know when to refresh the commit files context and when not to,
@ -290,16 +290,16 @@ func (self *RefreshHelper) determineCheckedOutBranchName() string {
return strings.TrimPrefix(rebasedBranch, "refs/heads/")
}
if bisectInfo := self.c.Git().Bisect.GetInfo(); bisectInfo.Bisecting() && bisectInfo.GetStartSha() != "" {
if bisectInfo := self.c.Git().Bisect.GetInfo(); bisectInfo.Bisecting() && bisectInfo.GetStartHash() != "" {
// Likewise, when we're bisecting we're on a detached head as well. In
// this case we read the branch name from the ".git/BISECT_START" file.
return bisectInfo.GetStartSha()
return bisectInfo.GetStartHash()
}
// In all other cases, get the branch name by asking git what branch is
// checked out. Note that if we're on a detached head (for reasons other
// than rebasing or bisecting, i.e. it was explicitly checked out), then
// this will return its sha.
// this will return its hash.
if branchName, err := self.c.Git().Branch.CurrentBranchName(); err == nil {
return branchName
}
@ -721,10 +721,10 @@ func (self *RefreshHelper) refForLog() string {
// need to see if our bisect's current commit is reachable from our 'new' ref.
if bisectInfo.Bisecting() && !self.c.Git().Bisect.ReachableFromStart(bisectInfo) {
return bisectInfo.GetNewSha()
return bisectInfo.GetNewHash()
}
return bisectInfo.GetStartSha()
return bisectInfo.GetStartHash()
}
func (self *RefreshHelper) refreshView(context types.Context) error {

View File

@ -62,8 +62,8 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
// is a branch
branchDisplay = strings.TrimPrefix(content, refsPrefix)
} else {
// detached HEAD state, displaying short SHA
branchDisplay = utils.ShortSha(content)
// detached HEAD state, displaying short hash
branchDisplay = utils.ShortHash(content)
}
return branchDisplay, nil
}

View File

@ -285,7 +285,7 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error {
"ref": strings.TrimPrefix(commit.Name, "refs/heads/"),
}))
} else {
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath())
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash, self.c.Modes().Filtering.GetPath())
task = types.NewRunPtyTask(cmdObj.GetCmd())
}
@ -350,7 +350,7 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star
}
func (self *LocalCommitsController) reword(commit *models.Commit) error {
commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Sha)
commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -508,9 +508,9 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
self.c.LogAction(self.c.Tr.Actions.EditCommit)
selectedIdx, rangeStartIdx, rangeSelectMode := self.context().GetSelectionRangeAndMode()
commits := self.c.Model().Commits
selectedSha := commits[selectedIdx].Sha
rangeStartSha := commits[rangeStartIdx].Sha
err := self.c.Git().Rebase.EditRebase(commitsToEdit[len(commitsToEdit)-1].Sha)
selectedHash := commits[selectedIdx].Hash
rangeStartHash := commits[rangeStartIdx].Hash
err := self.c.Git().Rebase.EditRebase(commitsToEdit[len(commitsToEdit)-1].Hash)
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
err,
types.RefreshOptions{Mode: types.BLOCK_UI, Then: func() {
@ -518,7 +518,7 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
for _, c := range commitsToEdit[:len(commitsToEdit)-1] {
// Merge commits can't be set to "edit", so just skip them
if !c.IsMerge() {
todos = append(todos, &models.Commit{Sha: c.Sha, Action: todo.Pick})
todos = append(todos, &models.Commit{Hash: c.Hash, Action: todo.Pick})
}
}
if len(todos) > 0 {
@ -532,10 +532,10 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
// new lines can be added for update-ref commands in the TODO file, due to
// stacked branches. So the selected commits may be in different positions in the list.
_, newSelectedIdx, ok1 := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool {
return c.Sha == selectedSha
return c.Hash == selectedHash
})
_, newRangeStartIdx, ok2 := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool {
return c.Sha == rangeStartSha
return c.Hash == rangeStartHash
})
if ok1 && ok2 {
self.context().SetSelectionRangeAndMode(newSelectedIdx, newRangeStartIdx, rangeSelectMode)
@ -782,12 +782,12 @@ func (self *LocalCommitsController) revert(commit *models.Commit) error {
Prompt: utils.ResolvePlaceholderString(
self.c.Tr.ConfirmRevertCommit,
map[string]string{
"selectedCommit": commit.ShortSha(),
"selectedCommit": commit.ShortHash(),
}),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.RevertCommit)
return self.c.WithWaitingStatusSync(self.c.Tr.RevertingStatus, func() error {
if err := self.c.Git().Commit.Revert(commit.Sha); err != nil {
if err := self.c.Git().Commit.Revert(commit.Hash); err != nil {
return err
}
return self.afterRevertCommit()
@ -799,20 +799,20 @@ func (self *LocalCommitsController) revert(commit *models.Commit) error {
func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.Commit) error {
menuItems := make([]*types.MenuItem, len(commit.Parents))
for i, parentSha := range commit.Parents {
for i, parentHash := range commit.Parents {
i := i
message, err := self.c.Git().Commit.GetCommitMessageFirstLine(parentSha)
message, err := self.c.Git().Commit.GetCommitMessageFirstLine(parentHash)
if err != nil {
return self.c.Error(err)
}
menuItems[i] = &types.MenuItem{
Label: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message),
Label: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentHash, 8), message),
OnPress: func() error {
parentNumber := i + 1
self.c.LogAction(self.c.Tr.Actions.RevertCommit)
return self.c.WithWaitingStatusSync(self.c.Tr.RevertingStatus, func() error {
if err := self.c.Git().Commit.RevertMerge(commit.Sha, parentNumber); err != nil {
if err := self.c.Git().Commit.RevertMerge(commit.Hash, parentNumber); err != nil {
return err
}
return self.afterRevertCommit()
@ -850,7 +850,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
return self.c.Helpers().WorkingTree.WithEnsureCommitableFiles(func() error {
self.c.LogAction(self.c.Tr.Actions.CreateFixupCommit)
return self.c.WithWaitingStatusSync(self.c.Tr.CreatingFixupCommitStatus, func() error {
if err := self.c.Git().Commit.CreateFixupCommit(commit.Sha); err != nil {
if err := self.c.Git().Commit.CreateFixupCommit(commit.Hash); err != nil {
return self.c.Error(err)
}
@ -884,7 +884,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
}
func (self *LocalCommitsController) createAmendCommit(commit *models.Commit, includeFileChanges bool) error {
commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Sha)
commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Hash)
if err != nil {
return self.c.Error(err)
}
@ -1024,7 +1024,7 @@ func isFixupCommit(subject string) (string, bool) {
}
func (self *LocalCommitsController) createTag(commit *models.Commit) error {
return self.c.Helpers().Tags.OpenCreateTagPrompt(commit.Sha, func() {})
return self.c.Helpers().Tags.OpenCreateTagPrompt(commit.Hash, func() {})
}
func (self *LocalCommitsController) openSearch() error {
@ -1181,11 +1181,11 @@ func (self *LocalCommitsController) canPaste() *types.DisabledReason {
}
func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) error {
if commit.Sha == self.c.Modes().MarkedBaseCommit.GetSha() {
if commit.Hash == self.c.Modes().MarkedBaseCommit.GetHash() {
// Reset when invoking it again on the marked commit
self.c.Modes().MarkedBaseCommit.SetSha("")
self.c.Modes().MarkedBaseCommit.SetHash("")
} else {
self.c.Modes().MarkedBaseCommit.SetSha(commit.Sha)
self.c.Modes().MarkedBaseCommit.SetHash(commit.Hash)
}
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
}

View File

@ -45,7 +45,7 @@ func (self *ReflogCommitsController) GetOnRenderToMain() func() error {
if commit == nil {
task = types.NewRenderStringTask("No reflog history")
} else {
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath())
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash, self.c.Modes().Filtering.GetPath())
task = types.NewRunPtyTask(cmdObj.GetCmd())
}

View File

@ -46,7 +46,7 @@ func (self *SubCommitsController) GetOnRenderToMain() func() error {
if commit == nil {
task = types.NewRenderStringTask("No commits")
} else {
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath())
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash, self.c.Modes().Filtering.GetPath())
task = types.NewRunPtyTask(cmdObj.GetCmd())
}

View File

@ -230,7 +230,7 @@ func (self *TagsController) createResetMenu(tag *models.Tag) error {
}
func (self *TagsController) create() error {
// leaving commit SHA blank so that we're just creating the tag for the current commit
// leaving commit hash blank so that we're just creating the tag for the current commit
return self.c.Helpers().Tags.OpenCreateTagPrompt("", func() {
self.context().SetSelection(0)
})

View File

@ -181,34 +181,34 @@ func (self *UndoController) reflogRedo() error {
func (self *UndoController) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error {
counter := 0
reflogCommits := self.c.Model().FilteredReflogCommits
rebaseFinishCommitSha := ""
rebaseFinishCommitHash := ""
var action *reflogAction
for reflogCommitIdx, reflogCommit := range reflogCommits {
action = nil
prevCommitSha := ""
prevCommitHash := ""
if len(reflogCommits)-1 >= reflogCommitIdx+1 {
prevCommitSha = reflogCommits[reflogCommitIdx+1].Sha
prevCommitHash = reflogCommits[reflogCommitIdx+1].Hash
}
if rebaseFinishCommitSha == "" {
if rebaseFinishCommitHash == "" {
if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^\[lazygit undo\]`); ok {
counter++
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^\[lazygit redo\]`); ok {
counter--
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(abort\)|^rebase (-i )?\(finish\)`); ok {
rebaseFinishCommitSha = reflogCommit.Sha
rebaseFinishCommitHash = reflogCommit.Hash
} else if ok, match := utils.FindStringSubmatch(reflogCommit.Name, `^checkout: moving from ([\S]+) to ([\S]+)`); ok {
action = &reflogAction{kind: CHECKOUT, from: match[1], to: match[2]}
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^commit|^reset: moving to|^pull`); ok {
action = &reflogAction{kind: COMMIT, from: prevCommitSha, to: reflogCommit.Sha}
action = &reflogAction{kind: COMMIT, from: prevCommitHash, to: reflogCommit.Hash}
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok {
// if we're here then we must be currently inside an interactive rebase
action = &reflogAction{kind: CURRENT_REBASE, from: prevCommitSha}
action = &reflogAction{kind: CURRENT_REBASE, from: prevCommitHash}
}
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok {
action = &reflogAction{kind: REBASE, from: prevCommitSha, to: rebaseFinishCommitSha}
rebaseFinishCommitSha = ""
action = &reflogAction{kind: REBASE, from: prevCommitHash, to: rebaseFinishCommitHash}
rebaseFinishCommitHash = ""
}
if action != nil {
@ -232,9 +232,9 @@ type hardResetOptions struct {
}
// only to be used in the undo flow for now (does an autostash)
func (self *UndoController) hardResetWithAutoStash(commitSha string, options hardResetOptions) error {
func (self *UndoController) hardResetWithAutoStash(commitHash string, options hardResetOptions) error {
reset := func() error {
if err := self.c.Helpers().Refs.ResetToRef(commitSha, "hard", options.EnvVars); err != nil {
if err := self.c.Helpers().Refs.ResetToRef(commitHash, "hard", options.EnvVars); err != nil {
return self.c.Error(err)
}
return nil
@ -249,7 +249,7 @@ func (self *UndoController) hardResetWithAutoStash(commitSha string, options har
Prompt: self.c.Tr.AutoStashPrompt,
HandleConfirm: func() error {
return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error {
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitSha); err != nil {
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitHash); err != nil {
return self.c.Error(err)
}
if err := reset(); err != nil {

View File

@ -148,7 +148,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard,
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
Description: self.c.Tr.CopyCommitShaToClipboard,
Description: self.c.Tr.CopyCommitHashToClipboard,
},
{
ViewName: "commits",
@ -161,14 +161,14 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
Handler: self.handleCopySelectedSideContextItemToClipboard,
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
Description: self.c.Tr.CopyCommitShaToClipboard,
Description: self.c.Tr.CopyCommitHashToClipboard,
},
{
ViewName: "subCommits",
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard,
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
Description: self.c.Tr.CopyCommitShaToClipboard,
Description: self.c.Tr.CopyCommitHashToClipboard,
},
{
ViewName: "information",

View File

@ -24,33 +24,33 @@ func (self *CherryPicking) Active() bool {
return len(self.CherryPickedCommits) > 0
}
func (self *CherryPicking) SelectedShaSet() *set.Set[string] {
shas := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string {
return commit.Sha
func (self *CherryPicking) SelectedHashSet() *set.Set[string] {
hashes := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string {
return commit.Hash
})
return set.NewFromSlice(shas)
return set.NewFromSlice(hashes)
}
func (self *CherryPicking) Add(selectedCommit *models.Commit, commitsList []*models.Commit) {
commitSet := self.SelectedShaSet()
commitSet.Add(selectedCommit.Sha)
commitSet := self.SelectedHashSet()
commitSet.Add(selectedCommit.Hash)
self.update(commitSet, commitsList)
}
func (self *CherryPicking) Remove(selectedCommit *models.Commit, commitsList []*models.Commit) {
commitSet := self.SelectedShaSet()
commitSet.Remove(selectedCommit.Sha)
commitSet := self.SelectedHashSet()
commitSet.Remove(selectedCommit.Hash)
self.update(commitSet, commitsList)
}
func (self *CherryPicking) update(selectedShaSet *set.Set[string], commitsList []*models.Commit) {
func (self *CherryPicking) update(selectedHashSet *set.Set[string], commitsList []*models.Commit) {
cherryPickedCommits := lo.Filter(commitsList, func(commit *models.Commit, _ int) bool {
return selectedShaSet.Includes(commit.Sha)
return selectedHashSet.Includes(commit.Hash)
})
self.CherryPickedCommits = lo.Map(cherryPickedCommits, func(commit *models.Commit, _ int) *models.Commit {
return &models.Commit{Name: commit.Name, Sha: commit.Sha}
return &models.Commit{Name: commit.Name, Hash: commit.Hash}
})
}

View File

@ -1,7 +1,7 @@
package marked_base_commit
type MarkedBaseCommit struct {
sha string // the sha of the commit used as a rebase base commit; empty string when unset
hash string // the hash of the commit used as a rebase base commit; empty string when unset
}
func New() MarkedBaseCommit {
@ -9,17 +9,17 @@ func New() MarkedBaseCommit {
}
func (m *MarkedBaseCommit) Active() bool {
return m.sha != ""
return m.hash != ""
}
func (m *MarkedBaseCommit) Reset() {
m.sha = ""
m.hash = ""
}
func (m *MarkedBaseCommit) SetSha(sha string) {
m.sha = sha
func (m *MarkedBaseCommit) SetHash(hash string) {
m.hash = hash
}
func (m *MarkedBaseCommit) GetSha() string {
return m.sha
func (m *MarkedBaseCommit) GetHash() string {
return m.hash
}

View File

@ -106,7 +106,7 @@ func getBranchDisplayStrings(
}
if showCommitHash {
res = append(res, utils.ShortSha(b.CommitHash))
res = append(res, utils.ShortHash(b.CommitHash))
}
res = append(res, coloredName)

View File

@ -22,7 +22,7 @@ import (
)
type pipeSetCacheKey struct {
commitSha string
commitHash string
commitCount int
}
@ -43,14 +43,14 @@ func GetCommitListDisplayStrings(
currentBranchName string,
hasRebaseUpdateRefsConfig bool,
fullDescription bool,
cherryPickedCommitShaSet *set.Set[string],
cherryPickedCommitHashSet *set.Set[string],
diffName string,
markedBaseCommit string,
timeFormat string,
shortTimeFormat string,
now time.Time,
parseEmoji bool,
selectedCommitSha string,
selectedCommitHash string,
startIdx int,
endIdx int,
showGraph bool,
@ -89,7 +89,7 @@ func GetCommitListDisplayStrings(
graphLines := graph.RenderAux(
graphPipeSets,
graphCommits,
selectedCommitSha,
selectedCommitHash,
)
getGraphLine = func(idx int) string {
if idx >= graphOffset {
@ -123,7 +123,7 @@ func GetCommitListDisplayStrings(
!lo.Contains(common.UserConfig.Git.MainBranches, b.Name) &&
// Don't show a marker for the head commit unless the
// rebase.updateRefs config is on
(hasRebaseUpdateRefsConfig || b.CommitHash != commits[0].Sha)
(hasRebaseUpdateRefsConfig || b.CommitHash != commits[0].Hash)
}))
lines := make([][]string, 0, len(filteredCommits))
@ -131,13 +131,13 @@ func GetCommitListDisplayStrings(
willBeRebased := markedBaseCommit == ""
for i, commit := range filteredCommits {
unfilteredIdx := i + startIdx
bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds)
bisectStatus = getBisectStatus(unfilteredIdx, commit.Hash, bisectInfo, bisectBounds)
isYouAreHereCommit := false
if showYouAreHereLabel && (commit.Action == models.ActionConflict || unfilteredIdx == rebaseOffset) {
isYouAreHereCommit = true
showYouAreHereLabel = false
}
isMarkedBaseCommit := commit.Sha != "" && commit.Sha == markedBaseCommit
isMarkedBaseCommit := commit.Hash != "" && commit.Hash == markedBaseCommit
if isMarkedBaseCommit {
willBeRebased = true
}
@ -146,7 +146,7 @@ func GetCommitListDisplayStrings(
commit,
branchHeadsToVisualize,
hasRebaseUpdateRefsConfig,
cherryPickedCommitShaSet,
cherryPickedCommitHashSet,
isMarkedBaseCommit,
willBeRebased,
diffName,
@ -172,11 +172,11 @@ func getbisectBounds(commits []*models.Commit, bisectInfo *git_commands.BisectIn
bisectBounds := &bisectBounds{}
for i, commit := range commits {
if commit.Sha == bisectInfo.GetNewSha() {
if commit.Hash == bisectInfo.GetNewHash() {
bisectBounds.newIndex = i
}
status, ok := bisectInfo.Status(commit.Sha)
status, ok := bisectInfo.Status(commit.Hash)
if ok && status == git_commands.BisectStatusOld {
bisectBounds.oldIndex = i
return bisectBounds
@ -200,10 +200,10 @@ func indexOfFirstNonTODOCommit(commits []*models.Commit) int {
}
func loadPipesets(commits []*models.Commit) [][]*graph.Pipe {
// given that our cache key is a commit sha and a commit count, it's very important that we don't actually try to render pipes
// given that our cache key is a commit hash and a commit count, it's very important that we don't actually try to render pipes
// when dealing with things like filtered commits.
cacheKey := pipeSetCacheKey{
commitSha: commits[0].Sha,
commitHash: commits[0].Hash,
commitCount: len(commits),
}
@ -236,16 +236,16 @@ const (
BisectStatusCurrent
)
func getBisectStatus(index int, commitSha string, bisectInfo *git_commands.BisectInfo, bisectBounds *bisectBounds) BisectStatus {
func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.BisectInfo, bisectBounds *bisectBounds) BisectStatus {
if !bisectInfo.Started() {
return BisectStatusNone
}
if bisectInfo.GetCurrentSha() == commitSha {
if bisectInfo.GetCurrentHash() == commitHash {
return BisectStatusCurrent
}
status, ok := bisectInfo.Status(commitSha)
status, ok := bisectInfo.Status(commitHash)
if ok {
switch status {
case git_commands.BisectStatusNew:
@ -298,7 +298,7 @@ func displayCommit(
commit *models.Commit,
branchHeadsToVisualize *set.Set[string],
hasRebaseUpdateRefsConfig bool,
cherryPickedCommitShaSet *set.Set[string],
cherryPickedCommitHashSet *set.Set[string],
isMarkedBaseCommit bool,
willBeRebased bool,
diffName string,
@ -312,7 +312,7 @@ func displayCommit(
bisectInfo *git_commands.BisectInfo,
isYouAreHereCommit bool,
) []string {
shaColor := getShaColor(commit, diffName, cherryPickedCommitShaSet, bisectStatus, bisectInfo)
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
bisectString := getBisectStatusText(bisectStatus, bisectInfo)
actionString := ""
@ -331,7 +331,7 @@ func displayCommit(
tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " "
}
if branchHeadsToVisualize.Includes(commit.Sha) &&
if branchHeadsToVisualize.Includes(commit.Hash) &&
// Don't show branch head on commits that are already merged to a main branch
commit.Status != models.StatusMerged &&
// Don't show branch head on a "pick" todo if the rebase.updateRefs config is on
@ -369,11 +369,11 @@ func displayCommit(
cols := make([]string, 0, 7)
if commit.Divergence != models.DivergenceNone {
cols = append(cols, shaColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓")))
cols = append(cols, hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓")))
} else if icons.IsIconEnabled() {
cols = append(cols, shaColor.Sprint(icons.IconForCommit(commit)))
cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit)))
}
cols = append(cols, shaColor.Sprint(commit.ShortSha()))
cols = append(cols, hashColor.Sprint(commit.ShortHash()))
cols = append(cols, bisectString)
if fullDescription {
cols = append(cols, style.FgBlue.Sprint(
@ -410,10 +410,10 @@ func getBisectStatusColor(status BisectStatus) style.TextStyle {
return style.FgWhite
}
func getShaColor(
func getHashColor(
commit *models.Commit,
diffName string,
cherryPickedCommitShaSet *set.Set[string],
cherryPickedCommitHashSet *set.Set[string],
bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo,
) style.TextStyle {
@ -421,31 +421,31 @@ func getShaColor(
return getBisectStatusColor(bisectStatus)
}
diffed := commit.Sha != "" && commit.Sha == diffName
shaColor := theme.DefaultTextColor
diffed := commit.Hash != "" && commit.Hash == diffName
hashColor := theme.DefaultTextColor
switch commit.Status {
case models.StatusUnpushed:
shaColor = style.FgRed
hashColor = style.FgRed
case models.StatusPushed:
shaColor = style.FgYellow
hashColor = style.FgYellow
case models.StatusMerged:
shaColor = style.FgGreen
hashColor = style.FgGreen
case models.StatusRebasing:
shaColor = style.FgBlue
hashColor = style.FgBlue
case models.StatusReflog:
shaColor = style.FgBlue
hashColor = style.FgBlue
default:
}
if diffed {
shaColor = theme.DiffTerminalColor
} else if cherryPickedCommitShaSet.Includes(commit.Sha) {
shaColor = theme.CherryPickedCommitTextStyle
hashColor = theme.DiffTerminalColor
} else if cherryPickedCommitHashSet.Includes(commit.Hash) {
hashColor = theme.CherryPickedCommitTextStyle
} else if commit.Divergence == models.DivergenceRight && commit.Status != models.StatusMerged {
shaColor = style.FgBlue
hashColor = style.FgBlue
}
return shaColor
return hashColor
}
func actionColorMap(action todo.TodoCommand) style.TextStyle {

View File

@ -22,361 +22,361 @@ func formatExpected(expected string) string {
func TestGetCommitListDisplayStrings(t *testing.T) {
scenarios := []struct {
testName string
commits []*models.Commit
branches []*models.Branch
currentBranchName string
hasUpdateRefConfig bool
fullDescription bool
cherryPickedCommitShaSet *set.Set[string]
markedBaseCommit string
diffName string
timeFormat string
shortTimeFormat string
now time.Time
parseEmoji bool
selectedCommitSha string
startIdx int
endIdx int
showGraph bool
bisectInfo *git_commands.BisectInfo
showYouAreHereLabel bool
expected string
focus bool
testName string
commits []*models.Commit
branches []*models.Branch
currentBranchName string
hasUpdateRefConfig bool
fullDescription bool
cherryPickedCommitHashSet *set.Set[string]
markedBaseCommit string
diffName string
timeFormat string
shortTimeFormat string
now time.Time
parseEmoji bool
selectedCommitHash string
startIdx int
endIdx int
showGraph bool
bisectInfo *git_commands.BisectInfo
showYouAreHereLabel bool
expected string
focus bool
}{
{
testName: "no commits",
commits: []*models.Commit{},
startIdx: 0,
endIdx: 1,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: "",
testName: "no commits",
commits: []*models.Commit{},
startIdx: 0,
endIdx: 1,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: "",
},
{
testName: "some commits",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2"},
{Name: "commit1", Hash: "hash1"},
{Name: "commit2", Hash: "hash2"},
},
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 commit2
hash1 commit1
hash2 commit2
`),
},
{
testName: "commit with tags",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Tags: []string{"tag1", "tag2"}},
{Name: "commit2", Sha: "sha2"},
{Name: "commit1", Hash: "hash1", Tags: []string{"tag1", "tag2"}},
{Name: "commit2", Hash: "hash2"},
},
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 tag1 tag2 commit1
sha2 commit2
hash1 tag1 tag2 commit1
hash2 commit2
`),
},
{
testName: "show local branch head, except the current branch, main branches, or merged branches",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2"},
{Name: "commit3", Sha: "sha3"},
{Name: "commit4", Sha: "sha4", Status: models.StatusMerged},
{Name: "commit1", Hash: "hash1"},
{Name: "commit2", Hash: "hash2"},
{Name: "commit3", Hash: "hash3"},
{Name: "commit4", Hash: "hash4", Status: models.StatusMerged},
},
branches: []*models.Branch{
{Name: "current-branch", CommitHash: "sha1", Head: true},
{Name: "other-branch", CommitHash: "sha2", Head: false},
{Name: "master", CommitHash: "sha3", Head: false},
{Name: "old-branch", CommitHash: "sha4", Head: false},
{Name: "current-branch", CommitHash: "hash1", Head: true},
{Name: "other-branch", CommitHash: "hash2", Head: false},
{Name: "master", CommitHash: "hash3", Head: false},
{Name: "old-branch", CommitHash: "hash4", Head: false},
},
currentBranchName: "current-branch",
hasUpdateRefConfig: true,
startIdx: 0,
endIdx: 4,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
currentBranchName: "current-branch",
hasUpdateRefConfig: true,
startIdx: 0,
endIdx: 4,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 * commit2
sha3 commit3
sha4 commit4
hash1 commit1
hash2 * commit2
hash3 commit3
hash4 commit4
`),
},
{
testName: "show local branch head for head commit if updateRefs is on",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2"},
{Name: "commit1", Hash: "hash1"},
{Name: "commit2", Hash: "hash2"},
},
branches: []*models.Branch{
{Name: "current-branch", CommitHash: "sha1", Head: true},
{Name: "other-branch", CommitHash: "sha1", Head: false},
{Name: "current-branch", CommitHash: "hash1", Head: true},
{Name: "other-branch", CommitHash: "hash1", Head: false},
},
currentBranchName: "current-branch",
hasUpdateRefConfig: true,
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
currentBranchName: "current-branch",
hasUpdateRefConfig: true,
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 * commit1
sha2 commit2
hash1 * commit1
hash2 commit2
`),
},
{
testName: "don't show local branch head for head commit if updateRefs is off",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2"},
{Name: "commit1", Hash: "hash1"},
{Name: "commit2", Hash: "hash2"},
},
branches: []*models.Branch{
{Name: "current-branch", CommitHash: "sha1", Head: true},
{Name: "other-branch", CommitHash: "sha1", Head: false},
{Name: "current-branch", CommitHash: "hash1", Head: true},
{Name: "other-branch", CommitHash: "hash1", Head: false},
},
currentBranchName: "current-branch",
hasUpdateRefConfig: false,
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
currentBranchName: "current-branch",
hasUpdateRefConfig: false,
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 commit2
hash1 commit1
hash2 commit2
`),
},
{
testName: "show local branch head and tag if both exist",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2", Tags: []string{"some-tag"}},
{Name: "commit3", Sha: "sha3"},
{Name: "commit1", Hash: "hash1"},
{Name: "commit2", Hash: "hash2", Tags: []string{"some-tag"}},
{Name: "commit3", Hash: "hash3"},
},
branches: []*models.Branch{
{Name: "some-branch", CommitHash: "sha2"},
{Name: "some-branch", CommitHash: "hash2"},
},
startIdx: 0,
endIdx: 3,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 3,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 * some-tag commit2
sha3 commit3
hash1 commit1
hash2 * some-tag commit2
hash3 commit3
`),
},
{
testName: "showing graph",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 0,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 commit2
sha3 commit3
sha4 commit4
sha5 commit5
hash1 commit1
hash2 commit2
hash3 commit3
hash4 commit4
hash5 commit5
`),
},
{
testName: "showing graph, including rebase commits",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 0,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
sha3 <-- YOU ARE HERE --- commit3
sha4 commit4
sha5 commit5
hash1 pick commit1
hash2 pick commit2
hash3 <-- YOU ARE HERE --- commit3
hash4 commit4
hash5 commit5
`),
},
{
testName: "showing graph, including rebase commits, with offset",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 1,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 1,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha2 pick commit2
sha3 <-- YOU ARE HERE --- commit3
sha4 commit4
sha5 commit5
hash2 pick commit2
hash3 <-- YOU ARE HERE --- commit3
hash4 commit4
hash5 commit5
`),
},
{
testName: "startIdx is past TODO commits",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 3,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 3,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha4 commit4
sha5 commit5
hash4 commit4
hash5 commit5
`),
},
{
testName: "only showing TODO commits",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 0,
endIdx: 2,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 2,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
hash1 pick commit1
hash2 pick commit2
`),
},
{
testName: "no TODO commits, towards bottom",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 4,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 4,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha5 commit5
hash5 commit5
`),
},
{
testName: "only TODO commits except last",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}, Action: todo.Pick},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}, Action: todo.Pick},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}, Action: todo.Pick},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}, Action: todo.Pick},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 0,
endIdx: 2,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 2,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
hash1 pick commit1
hash2 pick commit2
`),
},
{
testName: "don't show YOU ARE HERE label when not asked for (e.g. in branches panel)",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
},
startIdx: 0,
endIdx: 3,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
startIdx: 0,
endIdx: 3,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 commit2
sha3 commit3
hash1 pick commit1
hash2 commit2
hash3 commit3
`),
},
{
testName: "custom time format",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"},
{Name: "commit2", Sha: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"},
{Name: "commit1", Hash: "hash1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"},
{Name: "commit2", Hash: "hash2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"},
},
fullDescription: true,
timeFormat: "2006-01-02",
shortTimeFormat: "3:04PM",
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
fullDescription: true,
timeFormat: "2006-01-02",
shortTimeFormat: "3:04PM",
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
expected: formatExpected(`
sha1 2:03AM Jesse Duffield commit1
sha2 2019-12-20 Jesse Duffield commit2
hash1 2:03AM Jesse Duffield commit1
hash2 2019-12-20 Jesse Duffield commit2
`),
},
}
@ -406,14 +406,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
s.currentBranchName,
s.hasUpdateRefConfig,
s.fullDescription,
s.cherryPickedCommitShaSet,
s.cherryPickedCommitHashSet,
s.diffName,
s.markedBaseCommit,
s.timeFormat,
s.shortTimeFormat,
s.now,
s.parseEmoji,
s.selectedCommitSha,
s.selectedCommitHash,
s.startIdx,
s.endIdx,
s.showGraph,

View File

@ -22,19 +22,19 @@ const (
)
type Pipe struct {
fromPos int
toPos int
fromSha string
toSha string
kind PipeKind
style style.TextStyle
fromPos int
toPos int
fromHash string
toHash string
kind PipeKind
style style.TextStyle
}
var highlightStyle = style.FgLightWhite.SetBold()
func ContainsCommitSha(pipes []*Pipe, sha string) bool {
func ContainsCommitHash(pipes []*Pipe, hash string) bool {
for _, pipe := range pipes {
if equalHashes(pipe.fromSha, sha) {
if equalHashes(pipe.fromHash, hash) {
return true
}
}
@ -49,13 +49,13 @@ func (self Pipe) right() int {
return max(self.fromPos, self.toPos)
}
func RenderCommitGraph(commits []*models.Commit, selectedCommitSha string, getStyle func(c *models.Commit) style.TextStyle) []string {
func RenderCommitGraph(commits []*models.Commit, selectedCommitHash string, getStyle func(c *models.Commit) style.TextStyle) []string {
pipeSets := GetPipeSets(commits, getStyle)
if len(pipeSets) == 0 {
return nil
}
lines := RenderAux(pipeSets, commits, selectedCommitSha)
lines := RenderAux(pipeSets, commits, selectedCommitHash)
return lines
}
@ -65,7 +65,7 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style
return nil
}
pipes := []*Pipe{{fromPos: 0, toPos: 0, fromSha: "START", toSha: commits[0].Sha, kind: STARTS, style: style.FgDefault}}
pipes := []*Pipe{{fromPos: 0, toPos: 0, fromHash: "START", toHash: commits[0].Hash, kind: STARTS, style: style.FgDefault}}
return lo.Map(commits, func(commit *models.Commit, _ int) []*Pipe {
pipes = getNextPipes(pipes, commit, getStyle)
@ -73,7 +73,7 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style
})
}
func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha string) []string {
func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitHash string) []string {
maxProcs := runtime.GOMAXPROCS(0)
// splitting up the rendering of the graph into multiple goroutines allows us to render the graph in parallel
@ -98,7 +98,7 @@ func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha s
if k > 0 {
prevCommit = commits[k-1]
}
line := renderPipeSet(pipeSet, selectedCommitSha, prevCommit)
line := renderPipeSet(pipeSet, selectedCommitHash, prevCommit)
innerLines = append(innerLines, line)
}
chunks[i] = innerLines
@ -130,7 +130,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
// (this only happens when we're doing `git log --all`). These will be tacked onto the far end.
pos := maxPos + 1
for _, pipe := range currentPipes {
if equalHashes(pipe.toSha, commit.Sha) {
if equalHashes(pipe.toHash, commit.Hash) {
// turns out this commit does have a descendant so we'll place it right under the first instance
pos = pipe.toPos
break
@ -144,27 +144,27 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
if len(commit.Parents) > 0 { // merge commit
newPipes = append(newPipes, &Pipe{
fromPos: pos,
toPos: pos,
fromSha: commit.Sha,
toSha: commit.Parents[0],
kind: STARTS,
style: getStyle(commit),
fromPos: pos,
toPos: pos,
fromHash: commit.Hash,
toHash: commit.Parents[0],
kind: STARTS,
style: getStyle(commit),
})
} else if len(commit.Parents) == 0 { // root commit
newPipes = append(newPipes, &Pipe{
fromPos: pos,
toPos: pos,
fromSha: commit.Sha,
toSha: models.EmptyTreeCommitHash,
kind: STARTS,
style: getStyle(commit),
fromPos: pos,
toPos: pos,
fromHash: commit.Hash,
toHash: models.EmptyTreeCommitHash,
kind: STARTS,
style: getStyle(commit),
})
}
traversedSpotsForContinuingPipes := set.New[int]()
for _, pipe := range currentPipes {
if !equalHashes(pipe.toSha, commit.Sha) {
if !equalHashes(pipe.toHash, commit.Hash) {
traversedSpotsForContinuingPipes.Add(pipe.toPos)
}
}
@ -203,27 +203,27 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
}
for _, pipe := range currentPipes {
if equalHashes(pipe.toSha, commit.Sha) {
if equalHashes(pipe.toHash, commit.Hash) {
// terminating here
newPipes = append(newPipes, &Pipe{
fromPos: pipe.toPos,
toPos: pos,
fromSha: pipe.fromSha,
toSha: pipe.toSha,
kind: TERMINATES,
style: pipe.style,
fromPos: pipe.toPos,
toPos: pos,
fromHash: pipe.fromHash,
toHash: pipe.toHash,
kind: TERMINATES,
style: pipe.style,
})
traverse(pipe.toPos, pos)
} else if pipe.toPos < pos {
// continuing here
availablePos := getNextAvailablePosForContinuingPipe()
newPipes = append(newPipes, &Pipe{
fromPos: pipe.toPos,
toPos: availablePos,
fromSha: pipe.fromSha,
toSha: pipe.toSha,
kind: CONTINUES,
style: pipe.style,
fromPos: pipe.toPos,
toPos: availablePos,
fromHash: pipe.fromHash,
toHash: pipe.toHash,
kind: CONTINUES,
style: pipe.style,
})
traverse(pipe.toPos, availablePos)
}
@ -234,12 +234,12 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
availablePos := getNextAvailablePosForNewPipe()
// need to act as if continuing pipes are going to continue on the same line.
newPipes = append(newPipes, &Pipe{
fromPos: pos,
toPos: availablePos,
fromSha: commit.Sha,
toSha: parent,
kind: STARTS,
style: getStyle(commit),
fromPos: pos,
toPos: availablePos,
fromHash: commit.Hash,
toHash: parent,
kind: STARTS,
style: getStyle(commit),
})
takenSpots.Add(availablePos)
@ -247,7 +247,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
}
for _, pipe := range currentPipes {
if !equalHashes(pipe.toSha, commit.Sha) && pipe.toPos > pos {
if !equalHashes(pipe.toHash, commit.Hash) && pipe.toPos > pos {
// continuing on, potentially moving left to fill in a blank spot
last := pipe.toPos
for i := pipe.toPos; i > pos; i-- {
@ -258,12 +258,12 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
}
}
newPipes = append(newPipes, &Pipe{
fromPos: pipe.toPos,
toPos: last,
fromSha: pipe.fromSha,
toSha: pipe.toSha,
kind: CONTINUES,
style: pipe.style,
fromPos: pipe.toPos,
toPos: last,
fromHash: pipe.fromHash,
toHash: pipe.toHash,
kind: CONTINUES,
style: pipe.style,
})
traverse(pipe.toPos, last)
}
@ -282,7 +282,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
func renderPipeSet(
pipes []*Pipe,
selectedCommitSha string,
selectedCommitHash string,
prevCommit *models.Commit,
) string {
maxPos := 0
@ -329,10 +329,10 @@ func renderPipeSet(
// we don't want to highlight two commits if they're contiguous. We only want
// to highlight multiple things if there's an actual visible pipe involved.
highlight := true
if prevCommit != nil && equalHashes(prevCommit.Sha, selectedCommitSha) {
if prevCommit != nil && equalHashes(prevCommit.Hash, selectedCommitHash) {
highlight = false
for _, pipe := range pipes {
if equalHashes(pipe.fromSha, selectedCommitSha) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) {
if equalHashes(pipe.fromHash, selectedCommitHash) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) {
highlight = true
}
}
@ -341,7 +341,7 @@ func renderPipeSet(
// so we have our commit pos again, now it's time to build the cells.
// we'll handle the one that's sourced from our selected commit last so that it can override the other cells.
selectedPipes, nonSelectedPipes := utils.Partition(pipes, func(pipe *Pipe) bool {
return highlight && equalHashes(pipe.fromSha, selectedCommitSha)
return highlight && equalHashes(pipe.fromHash, selectedCommitHash)
})
for _, pipe := range nonSelectedPipes {
@ -385,7 +385,7 @@ func renderPipeSet(
}
func equalHashes(a, b string) bool {
// if our selectedCommitSha is an empty string we treat that as meaning there is no selected commit sha
// if our selectedCommitHash is an empty string we treat that as meaning there is no selected commit hash
if a == "" || b == "" {
return false
}

View File

@ -24,20 +24,20 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with some merges",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3"}},
{Sha: "3", Parents: []string{"4"}},
{Sha: "4", Parents: []string{"5", "7"}},
{Sha: "7", Parents: []string{"5"}},
{Sha: "5", Parents: []string{"8"}},
{Sha: "8", Parents: []string{"9"}},
{Sha: "9", Parents: []string{"A", "B"}},
{Sha: "B", Parents: []string{"D"}},
{Sha: "D", Parents: []string{"D"}},
{Sha: "A", Parents: []string{"E"}},
{Sha: "E", Parents: []string{"F"}},
{Sha: "F", Parents: []string{"D"}},
{Sha: "D", Parents: []string{"G"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3"}},
{Hash: "3", Parents: []string{"4"}},
{Hash: "4", Parents: []string{"5", "7"}},
{Hash: "7", Parents: []string{"5"}},
{Hash: "5", Parents: []string{"8"}},
{Hash: "8", Parents: []string{"9"}},
{Hash: "9", Parents: []string{"A", "B"}},
{Hash: "B", Parents: []string{"D"}},
{Hash: "D", Parents: []string{"D"}},
{Hash: "A", Parents: []string{"E"}},
{Hash: "E", Parents: []string{"F"}},
{Hash: "F", Parents: []string{"D"}},
{Hash: "D", Parents: []string{"G"}},
},
expectedOutput: `
1
@ -58,12 +58,12 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a path that has room to move to the left",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3", "4"}},
{Sha: "4", Parents: []string{"3", "5"}},
{Sha: "3", Parents: []string{"5"}},
{Sha: "5", Parents: []string{"6"}},
{Sha: "6", Parents: []string{"7"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3", "4"}},
{Hash: "4", Parents: []string{"3", "5"}},
{Hash: "3", Parents: []string{"5"}},
{Hash: "5", Parents: []string{"6"}},
{Hash: "6", Parents: []string{"7"}},
},
expectedOutput: `
1
@ -76,13 +76,13 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a new commit",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3", "4"}},
{Sha: "4", Parents: []string{"3", "5"}},
{Sha: "Z", Parents: []string{"Z"}},
{Sha: "3", Parents: []string{"5"}},
{Sha: "5", Parents: []string{"6"}},
{Sha: "6", Parents: []string{"7"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3", "4"}},
{Hash: "4", Parents: []string{"3", "5"}},
{Hash: "Z", Parents: []string{"Z"}},
{Hash: "3", Parents: []string{"5"}},
{Hash: "5", Parents: []string{"6"}},
{Hash: "6", Parents: []string{"7"}},
},
expectedOutput: `
1
@ -96,12 +96,12 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a path that has room to move to the left and continues",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3", "4"}},
{Sha: "3", Parents: []string{"5", "4"}},
{Sha: "5", Parents: []string{"7", "8"}},
{Sha: "4", Parents: []string{"7"}},
{Sha: "7", Parents: []string{"11"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3", "4"}},
{Hash: "3", Parents: []string{"5", "4"}},
{Hash: "5", Parents: []string{"7", "8"}},
{Hash: "4", Parents: []string{"7"}},
{Hash: "7", Parents: []string{"11"}},
},
expectedOutput: `
1
@ -114,13 +114,13 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a path that has room to move to the left and continues",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3", "4"}},
{Sha: "3", Parents: []string{"5", "4"}},
{Sha: "5", Parents: []string{"7", "8"}},
{Sha: "7", Parents: []string{"4", "A"}},
{Sha: "4", Parents: []string{"B"}},
{Sha: "B", Parents: []string{"C"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3", "4"}},
{Hash: "3", Parents: []string{"5", "4"}},
{Hash: "5", Parents: []string{"7", "8"}},
{Hash: "7", Parents: []string{"4", "A"}},
{Hash: "4", Parents: []string{"B"}},
{Hash: "B", Parents: []string{"C"}},
},
expectedOutput: `
1
@ -134,11 +134,11 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a path that has room to move to the left and continues",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2", "3"}},
{Sha: "3", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"4", "5"}},
{Sha: "4", Parents: []string{"6", "7"}},
{Sha: "6", Parents: []string{"8"}},
{Hash: "1", Parents: []string{"2", "3"}},
{Hash: "3", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"4", "5"}},
{Hash: "4", Parents: []string{"6", "7"}},
{Hash: "6", Parents: []string{"8"}},
},
expectedOutput: `
1
@ -150,11 +150,11 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "new merge path fills gap before continuing path on right",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2", "3", "4", "5"}},
{Sha: "4", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"A"}},
{Sha: "A", Parents: []string{"6", "B"}},
{Sha: "B", Parents: []string{"C"}},
{Hash: "1", Parents: []string{"2", "3", "4", "5"}},
{Hash: "4", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"A"}},
{Hash: "A", Parents: []string{"6", "B"}},
{Hash: "B", Parents: []string{"C"}},
},
expectedOutput: `
1
@ -166,14 +166,14 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a path that has room to move to the left and continues",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3", "4"}},
{Sha: "3", Parents: []string{"5", "4"}},
{Sha: "5", Parents: []string{"7", "8"}},
{Sha: "7", Parents: []string{"4", "A"}},
{Sha: "4", Parents: []string{"B"}},
{Sha: "B", Parents: []string{"C"}},
{Sha: "C", Parents: []string{"D"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3", "4"}},
{Hash: "3", Parents: []string{"5", "4"}},
{Hash: "5", Parents: []string{"7", "8"}},
{Hash: "7", Parents: []string{"4", "A"}},
{Hash: "4", Parents: []string{"B"}},
{Hash: "B", Parents: []string{"C"}},
{Hash: "C", Parents: []string{"D"}},
},
expectedOutput: `
1
@ -188,16 +188,16 @@ func TestRenderCommitGraph(t *testing.T) {
{
name: "with a path that has room to move to the left and continues",
commits: []*models.Commit{
{Sha: "1", Parents: []string{"2"}},
{Sha: "2", Parents: []string{"3", "4"}},
{Sha: "3", Parents: []string{"5", "4"}},
{Sha: "5", Parents: []string{"7", "G"}},
{Sha: "7", Parents: []string{"8", "A"}},
{Sha: "8", Parents: []string{"4", "E"}},
{Sha: "4", Parents: []string{"B"}},
{Sha: "B", Parents: []string{"C"}},
{Sha: "C", Parents: []string{"D"}},
{Sha: "D", Parents: []string{"F"}},
{Hash: "1", Parents: []string{"2"}},
{Hash: "2", Parents: []string{"3", "4"}},
{Hash: "3", Parents: []string{"5", "4"}},
{Hash: "5", Parents: []string{"7", "G"}},
{Hash: "7", Parents: []string{"8", "A"}},
{Hash: "8", Parents: []string{"4", "E"}},
{Hash: "4", Parents: []string{"B"}},
{Hash: "B", Parents: []string{"C"}},
{Hash: "C", Parents: []string{"D"}},
{Hash: "D", Parents: []string{"F"}},
},
expectedOutput: `
1
@ -231,7 +231,7 @@ func TestRenderCommitGraph(t *testing.T) {
output := ""
for i, line := range lines {
description := test.commits[i].Sha
description := test.commits[i].Hash
output += strings.TrimSpace(description+" "+utils.Decolorise(line)) + "\n"
}
t.Log("\nactual: \n" + output)
@ -263,32 +263,32 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "single cell",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: cyan},
{fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: STARTS, style: green},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: cyan},
{fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: STARTS, style: green},
},
prevCommit: &models.Commit{Sha: "a"},
prevCommit: &models.Commit{Hash: "a"},
expectedStr: "◯",
expectedStyles: []style.TextStyle{green},
},
{
name: "single cell, selected",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "selected", kind: TERMINATES, style: cyan},
{fromPos: 0, toPos: 0, fromSha: "selected", toSha: "c", kind: STARTS, style: green},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "selected", kind: TERMINATES, style: cyan},
{fromPos: 0, toPos: 0, fromHash: "selected", toHash: "c", kind: STARTS, style: green},
},
prevCommit: &models.Commit{Sha: "a"},
prevCommit: &models.Commit{Hash: "a"},
expectedStr: "◯",
expectedStyles: []style.TextStyle{highlightStyle},
},
{
name: "terminating hook and starting hook, selected",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "selected", kind: TERMINATES, style: cyan},
{fromPos: 1, toPos: 0, fromSha: "c", toSha: "selected", kind: TERMINATES, style: yellow},
{fromPos: 0, toPos: 0, fromSha: "selected", toSha: "d", kind: STARTS, style: green},
{fromPos: 0, toPos: 1, fromSha: "selected", toSha: "e", kind: STARTS, style: green},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "selected", kind: TERMINATES, style: cyan},
{fromPos: 1, toPos: 0, fromHash: "c", toHash: "selected", kind: TERMINATES, style: yellow},
{fromPos: 0, toPos: 0, fromHash: "selected", toHash: "d", kind: STARTS, style: green},
{fromPos: 0, toPos: 1, fromHash: "selected", toHash: "e", kind: STARTS, style: green},
},
prevCommit: &models.Commit{Sha: "a"},
prevCommit: &models.Commit{Hash: "a"},
expectedStr: "⏣─╮",
expectedStyles: []style.TextStyle{
highlightStyle, highlightStyle, highlightStyle,
@ -297,12 +297,12 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "terminating hook and starting hook, prioritise the terminating one",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: red},
{fromPos: 1, toPos: 0, fromSha: "c", toSha: "b", kind: TERMINATES, style: magenta},
{fromPos: 0, toPos: 0, fromSha: "b", toSha: "d", kind: STARTS, style: green},
{fromPos: 0, toPos: 1, fromSha: "b", toSha: "e", kind: STARTS, style: green},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: red},
{fromPos: 1, toPos: 0, fromHash: "c", toHash: "b", kind: TERMINATES, style: magenta},
{fromPos: 0, toPos: 0, fromHash: "b", toHash: "d", kind: STARTS, style: green},
{fromPos: 0, toPos: 1, fromHash: "b", toHash: "e", kind: STARTS, style: green},
},
prevCommit: &models.Commit{Sha: "a"},
prevCommit: &models.Commit{Hash: "a"},
expectedStr: "⏣─│",
expectedStyles: []style.TextStyle{
green, green, magenta,
@ -311,13 +311,13 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "starting and terminating pipe sharing some space",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromSha: "b1", toSha: "b2", kind: CONTINUES, style: magenta},
{fromPos: 3, toPos: 0, fromSha: "e1", toSha: "a2", kind: TERMINATES, style: green},
{fromPos: 0, toPos: 2, fromSha: "a2", toSha: "c3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromHash: "b1", toHash: "b2", kind: CONTINUES, style: magenta},
{fromPos: 3, toPos: 0, fromHash: "e1", toHash: "a2", kind: TERMINATES, style: green},
{fromPos: 0, toPos: 2, fromHash: "a2", toHash: "c3", kind: STARTS, style: yellow},
},
prevCommit: &models.Commit{Sha: "a1"},
prevCommit: &models.Commit{Hash: "a1"},
expectedStr: "⏣─│─┬─╯",
expectedStyles: []style.TextStyle{
yellow, yellow, magenta, yellow, yellow, green, green,
@ -326,13 +326,13 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "starting and terminating pipe sharing some space, with selection",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "selected", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromSha: "b1", toSha: "b2", kind: CONTINUES, style: magenta},
{fromPos: 3, toPos: 0, fromSha: "e1", toSha: "selected", kind: TERMINATES, style: green},
{fromPos: 0, toPos: 2, fromSha: "selected", toSha: "c3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "selected", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromHash: "b1", toHash: "b2", kind: CONTINUES, style: magenta},
{fromPos: 3, toPos: 0, fromHash: "e1", toHash: "selected", kind: TERMINATES, style: green},
{fromPos: 0, toPos: 2, fromHash: "selected", toHash: "c3", kind: STARTS, style: yellow},
},
prevCommit: &models.Commit{Sha: "a1"},
prevCommit: &models.Commit{Hash: "a1"},
expectedStr: "⏣───╮ ╯",
expectedStyles: []style.TextStyle{
highlightStyle, highlightStyle, highlightStyle, highlightStyle, highlightStyle, nothing, green,
@ -341,12 +341,12 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "many terminating pipes",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 0, fromSha: "b1", toSha: "a2", kind: TERMINATES, style: magenta},
{fromPos: 2, toPos: 0, fromSha: "c1", toSha: "a2", kind: TERMINATES, style: green},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 0, fromHash: "b1", toHash: "a2", kind: TERMINATES, style: magenta},
{fromPos: 2, toPos: 0, fromHash: "c1", toHash: "a2", kind: TERMINATES, style: green},
},
prevCommit: &models.Commit{Sha: "a1"},
prevCommit: &models.Commit{Hash: "a1"},
expectedStr: "◯─┴─╯",
expectedStyles: []style.TextStyle{
yellow, magenta, magenta, green, green,
@ -355,13 +355,13 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "starting pipe passing through",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 3, fromSha: "a2", toSha: "d3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromSha: "b1", toSha: "b3", kind: CONTINUES, style: magenta},
{fromPos: 2, toPos: 2, fromSha: "c1", toSha: "c3", kind: CONTINUES, style: green},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 3, fromHash: "a2", toHash: "d3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromHash: "b1", toHash: "b3", kind: CONTINUES, style: magenta},
{fromPos: 2, toPos: 2, fromHash: "c1", toHash: "c3", kind: CONTINUES, style: green},
},
prevCommit: &models.Commit{Sha: "a1"},
prevCommit: &models.Commit{Hash: "a1"},
expectedStr: "⏣─│─│─╮",
expectedStyles: []style.TextStyle{
yellow, yellow, magenta, yellow, green, yellow, yellow,
@ -370,13 +370,13 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "starting and terminating path crossing continuing path",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 1, fromSha: "a2", toSha: "b3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromSha: "b1", toSha: "a2", kind: CONTINUES, style: green},
{fromPos: 2, toPos: 0, fromSha: "c1", toSha: "a2", kind: TERMINATES, style: magenta},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 1, fromHash: "a2", toHash: "b3", kind: STARTS, style: yellow},
{fromPos: 1, toPos: 1, fromHash: "b1", toHash: "a2", kind: CONTINUES, style: green},
{fromPos: 2, toPos: 0, fromHash: "c1", toHash: "a2", kind: TERMINATES, style: magenta},
},
prevCommit: &models.Commit{Sha: "a1"},
prevCommit: &models.Commit{Hash: "a1"},
expectedStr: "⏣─│─╯",
expectedStyles: []style.TextStyle{
yellow, yellow, green, magenta, magenta,
@ -385,13 +385,13 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "another clash of starting and terminating paths",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 1, fromSha: "a2", toSha: "b3", kind: STARTS, style: yellow},
{fromPos: 2, toPos: 2, fromSha: "c1", toSha: "c3", kind: CONTINUES, style: green},
{fromPos: 3, toPos: 0, fromSha: "d1", toSha: "a2", kind: TERMINATES, style: magenta},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 1, fromHash: "a2", toHash: "b3", kind: STARTS, style: yellow},
{fromPos: 2, toPos: 2, fromHash: "c1", toHash: "c3", kind: CONTINUES, style: green},
{fromPos: 3, toPos: 0, fromHash: "d1", toHash: "a2", kind: TERMINATES, style: magenta},
},
prevCommit: &models.Commit{Sha: "a1"},
prevCommit: &models.Commit{Hash: "a1"},
expectedStr: "⏣─┬─│─╯",
expectedStyles: []style.TextStyle{
yellow, yellow, yellow, magenta, green, magenta, magenta,
@ -400,10 +400,10 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "commit whose previous commit is selected",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow},
{fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow},
},
prevCommit: &models.Commit{Sha: "selected"},
prevCommit: &models.Commit{Hash: "selected"},
expectedStr: "◯",
expectedStyles: []style.TextStyle{
yellow,
@ -412,10 +412,10 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "commit whose previous commit is selected and is a merge commit",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 1, toPos: 1, fromSha: "selected", toSha: "b3", kind: CONTINUES, style: red},
{fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 1, toPos: 1, fromHash: "selected", toHash: "b3", kind: CONTINUES, style: red},
},
prevCommit: &models.Commit{Sha: "selected"},
prevCommit: &models.Commit{Hash: "selected"},
expectedStr: "◯ │",
expectedStyles: []style.TextStyle{
highlightStyle, nothing, highlightStyle,
@ -424,11 +424,11 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "commit whose previous commit is selected and is a merge commit, with continuing pipe inbetween",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 1, toPos: 1, fromSha: "z1", toSha: "z3", kind: CONTINUES, style: green},
{fromPos: 2, toPos: 2, fromSha: "selected", toSha: "b3", kind: CONTINUES, style: red},
{fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 1, toPos: 1, fromHash: "z1", toHash: "z3", kind: CONTINUES, style: green},
{fromPos: 2, toPos: 2, fromHash: "selected", toHash: "b3", kind: CONTINUES, style: red},
},
prevCommit: &models.Commit{Sha: "selected"},
prevCommit: &models.Commit{Hash: "selected"},
expectedStr: "◯ │ │",
expectedStyles: []style.TextStyle{
highlightStyle, nothing, green, nothing, highlightStyle,
@ -437,12 +437,12 @@ func TestRenderPipeSet(t *testing.T) {
{
name: "when previous commit is selected, not a merge commit, and spawns a continuing pipe",
pipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: green},
{fromPos: 0, toPos: 1, fromSha: "a2", toSha: "b3", kind: STARTS, style: green},
{fromPos: 1, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: yellow},
{fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red},
{fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: green},
{fromPos: 0, toPos: 1, fromHash: "a2", toHash: "b3", kind: STARTS, style: green},
{fromPos: 1, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: yellow},
},
prevCommit: &models.Commit{Sha: "selected"},
prevCommit: &models.Commit{Hash: "selected"},
expectedStr: "⏣─╯",
expectedStyles: []style.TextStyle{
highlightStyle, highlightStyle, highlightStyle,
@ -483,43 +483,43 @@ func TestGetNextPipes(t *testing.T) {
}{
{
prevPipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: STARTS, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: STARTS, style: style.FgDefault},
},
commit: &models.Commit{
Sha: "b",
Hash: "b",
Parents: []string{"c"},
},
expected: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: STARTS, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: STARTS, style: style.FgDefault},
},
},
{
prevPipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: STARTS, style: style.FgDefault},
{fromPos: 0, toPos: 1, fromSha: "b", toSha: "d", kind: STARTS, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: STARTS, style: style.FgDefault},
{fromPos: 0, toPos: 1, fromHash: "b", toHash: "d", kind: STARTS, style: style.FgDefault},
},
commit: &models.Commit{
Sha: "d",
Hash: "d",
Parents: []string{"e"},
},
expected: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: CONTINUES, style: style.FgDefault},
{fromPos: 1, toPos: 1, fromSha: "b", toSha: "d", kind: TERMINATES, style: style.FgDefault},
{fromPos: 1, toPos: 1, fromSha: "d", toSha: "e", kind: STARTS, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: CONTINUES, style: style.FgDefault},
{fromPos: 1, toPos: 1, fromHash: "b", toHash: "d", kind: TERMINATES, style: style.FgDefault},
{fromPos: 1, toPos: 1, fromHash: "d", toHash: "e", kind: STARTS, style: style.FgDefault},
},
},
{
prevPipes: []*Pipe{
{fromPos: 0, toPos: 0, fromSha: "a", toSha: "root", kind: TERMINATES, style: style.FgDefault},
{fromPos: 0, toPos: 0, fromHash: "a", toHash: "root", kind: TERMINATES, style: style.FgDefault},
},
commit: &models.Commit{
Sha: "root",
Hash: "root",
Parents: []string{},
},
expected: []*Pipe{
{fromPos: 1, toPos: 1, fromSha: "root", toSha: models.EmptyTreeCommitHash, kind: STARTS, style: style.FgDefault},
{fromPos: 1, toPos: 1, fromHash: "root", toHash: models.EmptyTreeCommitHash, kind: STARTS, style: style.FgDefault},
},
},
}
@ -557,7 +557,7 @@ func BenchmarkRenderCommitGraph(b *testing.B) {
func generateCommits(count int) []*models.Commit {
rnd := rand.New(rand.NewSource(1234))
pool := []*models.Commit{{Sha: "a", AuthorName: "A"}}
pool := []*models.Commit{{Hash: "a", AuthorName: "A"}}
commits := make([]*models.Commit, 0, count)
authorPool := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
for len(commits) < count {
@ -574,12 +574,12 @@ func generateCommits(count int) []*models.Commit {
newParent = pool[j]
} else {
newParent = &models.Commit{
Sha: fmt.Sprintf("%s%d", currentCommit.Sha, j),
Hash: fmt.Sprintf("%s%d", currentCommit.Hash, j),
AuthorName: authorPool[rnd.Intn(len(authorPool))],
}
pool = append(pool, newParent)
}
currentCommit.Parents = append(currentCommit.Parents, newParent.Sha)
currentCommit.Parents = append(currentCommit.Parents, newParent.Hash)
}
commits = append(commits, currentCommit)

View File

@ -12,7 +12,7 @@ import (
"github.com/samber/lo"
)
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string {
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitHashSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string {
var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string
if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
@ -21,8 +21,8 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
}
return lo.Map(commits, func(commit *models.Commit, _ int) []string {
diffed := commit.Sha == diffName
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
diffed := commit.Hash == diffName
cherryPicked := cherryPickedCommitHashSet.Includes(commit.Hash)
return displayFunc(commit,
reflogCommitDisplayAttributes{
cherryPicked: cherryPicked,
@ -35,17 +35,17 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
})
}
func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
func reflogHashColor(cherryPicked, diffed bool) style.TextStyle {
if diffed {
return theme.DiffTerminalColor
}
shaColor := style.FgBlue
hashColor := style.FgBlue
if cherryPicked {
shaColor = theme.CherryPickedCommitTextStyle
hashColor = theme.CherryPickedCommitTextStyle
}
return shaColor
return hashColor
}
type reflogCommitDisplayAttributes struct {
@ -64,7 +64,7 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs ref
}
return []string{
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
reflogHashColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()),
style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)),
theme.DefaultTextColor.Sprint(name),
}
@ -77,7 +77,7 @@ func getDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDispla
}
return []string{
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
reflogHashColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()),
theme.DefaultTextColor.Sprint(name),
}
}

View File

@ -1,6 +1,7 @@
package custom_commands
import (
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
)
@ -19,11 +20,47 @@ func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelp
}
}
type Commit struct {
Hash string
Sha string
Name string
Status models.CommitStatus
Action todo.TodoCommand
Tags []string
ExtraInfo string
AuthorName string
AuthorEmail string
UnixTimestamp int64
Divergence models.Divergence
Parents []string
}
func commitWrapperFromModelCommit(commit *models.Commit) *Commit {
if commit == nil {
return nil
}
return &Commit{
Hash: commit.Hash,
Sha: commit.Hash,
Name: commit.Name,
Status: commit.Status,
Action: commit.Action,
Tags: commit.Tags,
ExtraInfo: commit.ExtraInfo,
AuthorName: commit.AuthorName,
AuthorEmail: commit.AuthorEmail,
UnixTimestamp: commit.UnixTimestamp,
Divergence: commit.Divergence,
Parents: commit.Parents,
}
}
// SessionState captures the current state of the application for use in custom commands
type SessionState struct {
SelectedLocalCommit *models.Commit
SelectedReflogCommit *models.Commit
SelectedSubCommit *models.Commit
SelectedLocalCommit *Commit
SelectedReflogCommit *Commit
SelectedSubCommit *Commit
SelectedFile *models.File
SelectedPath string
SelectedLocalBranch *models.Branch
@ -41,8 +78,8 @@ func (self *SessionStateLoader) call() *SessionState {
return &SessionState{
SelectedFile: self.c.Contexts().Files.GetSelectedFile(),
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
SelectedLocalCommit: self.c.Contexts().LocalCommits.GetSelected(),
SelectedReflogCommit: self.c.Contexts().ReflogCommits.GetSelected(),
SelectedLocalCommit: commitWrapperFromModelCommit(self.c.Contexts().LocalCommits.GetSelected()),
SelectedReflogCommit: commitWrapperFromModelCommit(self.c.Contexts().ReflogCommits.GetSelected()),
SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(),
SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(),
SelectedRemote: self.c.Contexts().Remotes.GetSelected(),
@ -50,7 +87,7 @@ func (self *SessionStateLoader) call() *SessionState {
SelectedStashEntry: self.c.Contexts().Stash.GetSelected(),
SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(),
SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
SelectedSubCommit: self.c.Contexts().SubCommits.GetSelected(),
SelectedSubCommit: commitWrapperFromModelCommit(self.c.Contexts().SubCommits.GetSelected()),
SelectedWorktree: self.c.Contexts().Worktrees.GetSelected(),
CheckedOutBranch: self.refsHelper.GetCheckedOutRef(),
}

View File

@ -245,7 +245,7 @@ type IListPanelState interface {
}
type ListItem interface {
// ID is a SHA when the item is a commit, a filename when the item is a file, 'stash@{4}' when it's a stash entry, 'my_branch' when it's a branch
// ID is a hash when the item is a commit, a filename when the item is a file, 'stash@{4}' when it's a stash entry, 'my_branch' when it's a branch
ID() string
// Description is something we would show in a message e.g. '123as14: push blah' for a commit

View File

@ -355,7 +355,7 @@ func chineseTranslationSet() TranslationSet {
// 实际视图 (actual view) 是附加视图 (extras view),未来,我打算为附加视图提供更多选项卡,但现在,上面的文本只需要提及“命令日志”这个部分
OpenCommandLogMenu: "打开命令日志菜单",
ShowingGitDiff: "显示输出:",
CopyCommitShaToClipboard: "将提交的 SHA 复制到剪贴板",
CopyCommitHashToClipboard: "将提交的 hash 复制到剪贴板",
CopyCommitMessageToClipboard: "将提交消息复制到剪贴板",
CopyBranchNameToClipboard: "将分支名称复制到剪贴板",
CopyPathToClipboard: "将文件名复制到剪贴板",

View File

@ -308,7 +308,7 @@ func dutchTranslationSet() TranslationSet {
SwapDiff: "Keer diff richting om",
ViewDiffingOptions: "Open diff menu",
ShowingGitDiff: "Laat output zien voor:",
CopyCommitShaToClipboard: "Kopieer commit SHA naar klembord",
CopyCommitHashToClipboard: "Kopieer commit hash naar klembord",
CopyCommitMessageToClipboard: "Kopieer commit bericht naar klembord",
CopyBranchNameToClipboard: "Kopieer branch name naar klembord",
CopyPathToClipboard: "Kopieer de bestandsnaam naar het klembord",

View File

@ -571,8 +571,8 @@ type TranslationSet struct {
OpenCommandLogMenuTooltip string
ShowingGitDiff string
CommitDiff string
CopyCommitShaToClipboard string
CommitSha string
CopyCommitHashToClipboard string
CommitHash string
CommitURL string
CopyCommitMessageToClipboard string
CommitMessage string
@ -855,7 +855,7 @@ type Actions struct {
CopyCommitMessageToClipboard string
CopyCommitSubjectToClipboard string
CopyCommitDiffToClipboard string
CopyCommitSHAToClipboard string
CopyCommitHashToClipboard string
CopyCommitURLToClipboard string
CopyCommitAuthorToClipboard string
CopyCommitAttributeToClipboard string
@ -1534,8 +1534,8 @@ func EnglishTranslationSet() TranslationSet {
OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.",
ShowingGitDiff: "Showing output for:",
CommitDiff: "Commit diff",
CopyCommitShaToClipboard: "Copy commit SHA to clipboard",
CommitSha: "Commit SHA",
CopyCommitHashToClipboard: "Copy commit hash to clipboard",
CommitHash: "Commit hash",
CommitURL: "Commit URL",
CopyCommitMessageToClipboard: "Copy commit message to clipboard",
CommitMessage: "Commit message",
@ -1772,7 +1772,7 @@ func EnglishTranslationSet() TranslationSet {
CopyCommitMessageToClipboard: "Copy commit message to clipboard",
CopyCommitSubjectToClipboard: "Copy commit subject to clipboard",
CopyCommitDiffToClipboard: "Copy commit diff to clipboard",
CopyCommitSHAToClipboard: "Copy full commit SHA to clipboard",
CopyCommitHashToClipboard: "Copy full commit hash to clipboard",
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
CopyCommitAttributeToClipboard: "Copy to clipboard",
@ -1875,11 +1875,11 @@ func EnglishTranslationSet() TranslationSet {
},
Log: Log{
EditRebase: "Beginning interactive rebase at '{{.ref}}'",
MoveCommitUp: "Moving TODO down: '{{.shortSha}}'",
MoveCommitDown: "Moving TODO down: '{{.shortSha}}'",
MoveCommitUp: "Moving TODO down: '{{.shortHash}}'",
MoveCommitDown: "Moving TODO down: '{{.shortHash}}'",
CherryPickCommits: "Cherry-picking commits:\n'{{.commitLines}}'",
HandleUndo: "Undoing last conflict resolution",
HandleMidRebaseCommand: "Updating rebase action of commit {{.shortSha}} to '{{.action}}'",
HandleMidRebaseCommand: "Updating rebase action of commit {{.shortHash}} to '{{.action}}'",
RemoveFile: "Deleting path '{{.path}}'",
CopyToClipboard: "Copying '{{.str}}' to clipboard",
Remove: "Removing '{{.filename}}'",

View File

@ -367,8 +367,8 @@ func japaneseTranslationSet() TranslationSet {
OpenCommandLogMenu: "コマンドログメニューを開く",
// LcShowingGitDiff: "Showing output for:",
CommitDiff: "コミットの差分",
CopyCommitShaToClipboard: "コミットのSHAをクリップボードにコピー",
CommitSha: "コミットのSHA",
CopyCommitHashToClipboard: "コミットのhashをクリップボードにコピー",
CommitHash: "コミットのhash",
CommitURL: "コミットのURL",
CopyCommitMessageToClipboard: "コミットメッセージをクリップボードにコピー",
CommitMessage: "コミットメッセージ",
@ -496,7 +496,7 @@ func japaneseTranslationSet() TranslationSet {
CreateAnnotatedTag: "注釈付きタグを作成",
CopyCommitMessageToClipboard: "コミットメッセージをクリップボードにコピー",
CopyCommitDiffToClipboard: "コミットの差分をクリップボードにコピー",
CopyCommitSHAToClipboard: "コミットSHAをクリップボードにコピー",
CopyCommitHashToClipboard: "コミットhashをクリップボードにコピー",
CopyCommitURLToClipboard: "コミットのURLをクリップボードにコピー",
CopyCommitAuthorToClipboard: "コミットの作成者名をクリップボードにコピー",
CopyCommitAttributeToClipboard: "クリップボードにコピー",

View File

@ -361,8 +361,8 @@ func koreanTranslationSet() TranslationSet {
OpenCommandLogMenu: "명령어 로그 메뉴 열기",
ShowingGitDiff: "Showing output for:",
CommitDiff: "커밋의 iff",
CopyCommitShaToClipboard: "커밋 SHA를 클립보드에 복사",
CommitSha: "커밋 SHA",
CopyCommitHashToClipboard: "커밋 해시를 클립보드에 복사",
CommitHash: "커밋 해시",
CommitURL: "커밋 URL",
CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사",
CommitMessage: "커밋 메시지",
@ -486,7 +486,7 @@ func koreanTranslationSet() TranslationSet {
CreateAnnotatedTag: "Create annotated tag",
CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사",
CopyCommitDiffToClipboard: "커밋 diff를 클립보드에 복사",
CopyCommitSHAToClipboard: "커밋 SHA를 클립보드에 복사",
CopyCommitHashToClipboard: "커밋 해시를 클립보드에 복사",
CopyCommitURLToClipboard: "커밋 URL를 클립보드에 복사",
CopyCommitAuthorToClipboard: "커밋 작성자를 클립보드에 복사",
CopyCommitAttributeToClipboard: "클립보드에 복사",

View File

@ -548,8 +548,8 @@ func polishTranslationSet() TranslationSet {
OpenCommandLogMenuTooltip: "Pokaż opcje dla dziennika poleceń, np. pokazywanie/ukrywanie dziennika poleceń i skupienie na dzienniku poleceń.",
ShowingGitDiff: "Pokazuje wynik dla:",
CommitDiff: "Różnice commita",
CopyCommitShaToClipboard: "Kopiuj SHA commita do schowka",
CommitSha: "SHA commita",
CopyCommitHashToClipboard: "Kopiuj hash commita do schowka",
CommitHash: "hash commita",
CommitURL: "URL commita",
CopyCommitMessageToClipboard: "Kopiuj wiadomość commita do schowka",
CommitMessage: "Wiadomość commita",
@ -784,7 +784,7 @@ func polishTranslationSet() TranslationSet {
CopyCommitMessageToClipboard: "Kopiuj wiadomość commita do schowka",
CopyCommitSubjectToClipboard: "Kopiuj temat commita do schowka",
CopyCommitDiffToClipboard: "Kopiuj różnice commita do schowka",
CopyCommitSHAToClipboard: "Kopiuj SHA commita do schowka",
CopyCommitHashToClipboard: "Kopiuj hash commita do schowka",
CopyCommitURLToClipboard: "Kopiuj URL commita do schowka",
CopyCommitAuthorToClipboard: "Kopiuj autora commita do schowka",
CopyCommitAttributeToClipboard: "Kopiuj do schowka",
@ -887,11 +887,11 @@ func polishTranslationSet() TranslationSet {
},
Log: Log{
EditRebase: "Rozpoczynanie interaktywnego rebazowania od '{{.ref}}'",
MoveCommitUp: "Przenoszenie TODO w dół: '{{.shortSha}}'",
MoveCommitDown: "Przenoszenie TODO w dół: '{{.shortSha}}'",
MoveCommitUp: "Przenoszenie TODO w dół: '{{.shortHash}}'",
MoveCommitDown: "Przenoszenie TODO w dół: '{{.shortHash}}'",
CherryPickCommits: "Cherry-picking commitów:\n'{{.commitLines}}'",
HandleUndo: "Cofanie ostatniego rozwiązania konfliktu",
HandleMidRebaseCommand: "Aktualizacja akcji rebazowania commita {{.shortSha}} na '{{.action}}'",
HandleMidRebaseCommand: "Aktualizacja akcji rebazowania commita {{.shortHash}} na '{{.action}}'",
RemoveFile: "Usuwanie ścieżki '{{.path}}'",
CopyToClipboard: "Kopiowanie '{{.str}}' do schowka",
Remove: "Usuwanie '{{.filename}}'",

View File

@ -422,8 +422,8 @@ func RussianTranslationSet() TranslationSet {
OpenCommandLogMenu: "Открыть меню журнала команд",
ShowingGitDiff: "Показывает вывод для:",
CommitDiff: "Разница коммита",
CopyCommitShaToClipboard: "Скопировать SHA коммита в буфер обмена",
CommitSha: "SHA коммита",
CopyCommitHashToClipboard: "Скопировать hash коммита в буфер обмена",
CommitHash: "hash коммита",
CommitURL: "URL коммита",
CopyCommitMessageToClipboard: "Скопировать сообщение коммита в буфер обмена",
CommitMessage: "Полное сообщение коммита",
@ -579,7 +579,7 @@ func RussianTranslationSet() TranslationSet {
CopyCommitMessageToClipboard: "Скопировать сообщение коммита в буфер обмена",
CopyCommitSubjectToClipboard: "Скопировать тему коммита в буфер обмена",
CopyCommitDiffToClipboard: "Скопировать сравнения коммита в буфер обмена",
CopyCommitSHAToClipboard: "Скопировать SHA коммита в буфер обмена",
CopyCommitHashToClipboard: "Скопировать hash коммита в буфер обмена",
CopyCommitURLToClipboard: "Скопировать URL коммита в буфер обмена",
CopyCommitAuthorToClipboard: "Скопировать автора коммита в буфер обмена",
CopyCommitAttributeToClipboard: "Скопировать в буфер обмена",

View File

@ -454,8 +454,8 @@ func traditionalChineseTranslationSet() TranslationSet {
OpenCommandLogMenu: "開啟命令記錄選單",
ShowingGitDiff: "顯示輸出:",
CommitDiff: "提交差異",
CopyCommitShaToClipboard: "複製提交 SHA 到剪貼簿",
CommitSha: "提交 SHA",
CopyCommitHashToClipboard: "複製提交 hash 到剪貼簿",
CommitHash: "提交 hash",
CommitURL: "提交 URL",
CopyCommitMessageToClipboard: "複製提交訊息到剪貼簿",
CommitMessage: "提交訊息",
@ -647,7 +647,7 @@ func traditionalChineseTranslationSet() TranslationSet {
CreateAnnotatedTag: "建立附註標籤",
CopyCommitMessageToClipboard: "將提交訊息複製到剪貼簿",
CopyCommitDiffToClipboard: "將提交差異複製到剪貼簿",
CopyCommitSHAToClipboard: "將提交 SHA 複製到剪貼簿",
CopyCommitHashToClipboard: "將提交 hash 複製到剪貼簿",
CopyCommitURLToClipboard: "將提交 URL 複製到剪貼簿",
CopyCommitAuthorToClipboard: "將提交作者複製到剪貼簿",
CopyCommitAttributeToClipboard: "複製到剪貼簿",

View File

@ -55,3 +55,11 @@ func (self *Git) Version() *git_commands.GitVersion {
}
return version
}
func (self *Git) GetCommitHash(ref string) string {
output, err := self.shell.runCommandWithOutput([]string{"git", "rev-parse", ref})
if err != nil {
log.Fatalf("Could not get commit hash: %v", err)
}
return strings.TrimSpace(output)
}

View File

@ -0,0 +1,37 @@
package custom_commands
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Run a command that accesses properties of a commit",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("my change")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.CustomCommands = []config.CustomCommand{
{
Key: "X",
Context: "commits",
Command: "printf '%s\n%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' '{{ .SelectedLocalCommit.Sha }}' > file.txt",
},
}
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("my change").IsSelected(),
).
Press("X")
hash := t.Git().GetCommitHash("HEAD")
t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s\n%s", hash, hash)))
},
})

View File

@ -97,6 +97,7 @@ var tests = []*components.IntegrationTest{
conflicts.ResolveExternally,
conflicts.ResolveMultipleFiles,
conflicts.UndoChooseHunk,
custom_commands.AccessCommitProperties,
custom_commands.BasicCmdAtRuntime,
custom_commands.BasicCmdFromConfig,
custom_commands.CheckForConflicts,

View File

@ -177,11 +177,11 @@ func SafeTruncate(str string, limit int) string {
const COMMIT_HASH_SHORT_SIZE = 8
func ShortSha(sha string) string {
if len(sha) < COMMIT_HASH_SHORT_SIZE {
return sha
func ShortHash(hash string) string {
if len(hash) < COMMIT_HASH_SHORT_SIZE {
return hash
}
return sha[:COMMIT_HASH_SHORT_SIZE]
return hash[:COMMIT_HASH_SHORT_SIZE]
}
// Returns comma-separated list of paths, with ellipsis if there are more than 3

View File

@ -11,16 +11,16 @@ import (
)
type Todo struct {
Sha string // for todos that have one, e.g. pick, drop, fixup, etc.
Hash string // for todos that have one, e.g. pick, drop, fixup, etc.
Ref string // for update-ref todos
Action todo.TodoCommand
}
// In order to change a TODO in git-rebase-todo, we need to specify the old action,
// because sometimes the same sha appears multiple times in the file (e.g. in a pick
// because sometimes the same hash appears multiple times in the file (e.g. in a pick
// and later in a merge)
type TodoChange struct {
Sha string
Hash string
OldAction todo.TodoCommand
NewAction todo.TodoCommand
}
@ -38,7 +38,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
t := &todos[i]
// This is a nested loop, but it's ok because the number of todos should be small
for _, change := range changes {
if t.Command == change.OldAction && equalShas(t.Commit, change.Sha) {
if t.Command == change.OldAction && equalHash(t.Commit, change.Hash) {
matchCount++
t.Command = change.NewAction
}
@ -53,18 +53,18 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
return WriteRebaseTodoFile(filePath, todos, commentChar)
}
func equalShas(a, b string) bool {
func equalHash(a, b string) bool {
return strings.HasPrefix(a, b) || strings.HasPrefix(b, a)
}
func findTodo(todos []todo.Todo, todoToFind Todo) (int, bool) {
_, idx, ok := lo.FindIndexOf(todos, func(t todo.Todo) bool {
// Comparing just the sha is not enough; we need to compare both the
// action and the sha, as the sha could appear multiple times (e.g. in a
// Comparing just the hash is not enough; we need to compare both the
// action and the hash, as the hash could appear multiple times (e.g. in a
// pick and later in a merge). For update-ref todos we also must compare
// the Ref.
return t.Command == todoToFind.Action &&
equalShas(t.Commit, todoToFind.Sha) &&
equalHash(t.Commit, todoToFind.Hash) &&
t.Ref == todoToFind.Ref
})
return idx, ok
@ -136,7 +136,7 @@ func deleteTodos(todos []todo.Todo, todosToDelete []Todo) ([]todo.Todo, error) {
if !ok {
// Should never happen
return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToDelete.Sha)
return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToDelete.Hash)
}
todos = Remove(todos, idx)
@ -184,7 +184,7 @@ func moveTodoUp(todos []todo.Todo, todoToMove Todo) ([]todo.Todo, error) {
if !ok {
// Should never happen
return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToMove.Sha)
return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToMove.Hash)
}
// The todos are ordered backwards compared to our model commits, so
@ -219,13 +219,13 @@ func moveTodosUp(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) {
return todos, nil
}
func MoveFixupCommitDown(fileName string, originalSha string, fixupSha string, commentChar byte) error {
func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string, commentChar byte) error {
todos, err := ReadRebaseTodoFile(fileName, commentChar)
if err != nil {
return err
}
newTodos, err := moveFixupCommitDown(todos, originalSha, fixupSha)
newTodos, err := moveFixupCommitDown(todos, originalHash, fixupHash)
if err != nil {
return err
}
@ -233,23 +233,23 @@ func MoveFixupCommitDown(fileName string, originalSha string, fixupSha string, c
return WriteRebaseTodoFile(fileName, newTodos, commentChar)
}
func moveFixupCommitDown(todos []todo.Todo, originalSha string, fixupSha string) ([]todo.Todo, error) {
func moveFixupCommitDown(todos []todo.Todo, originalHash string, fixupHash string) ([]todo.Todo, error) {
isOriginal := func(t todo.Todo) bool {
return t.Command == todo.Pick && equalShas(t.Commit, originalSha)
return t.Command == todo.Pick && equalHash(t.Commit, originalHash)
}
isFixup := func(t todo.Todo) bool {
return t.Command == todo.Pick && equalShas(t.Commit, fixupSha)
return t.Command == todo.Pick && equalHash(t.Commit, fixupHash)
}
originalShaCount := lo.CountBy(todos, isOriginal)
if originalShaCount != 1 {
return nil, fmt.Errorf("Expected exactly one original SHA, found %d", originalShaCount)
originalHashCount := lo.CountBy(todos, isOriginal)
if originalHashCount != 1 {
return nil, fmt.Errorf("Expected exactly one original hash, found %d", originalHashCount)
}
fixupShaCount := lo.CountBy(todos, isFixup)
if fixupShaCount != 1 {
return nil, fmt.Errorf("Expected exactly one fixup SHA, found %d", fixupShaCount)
fixupHashCount := lo.CountBy(todos, isFixup)
if fixupHashCount != 1 {
return nil, fmt.Errorf("Expected exactly one fixup hash, found %d", fixupHashCount)
}
_, fixupIndex, _ := lo.FindIndexOf(todos, isFixup)

View File

@ -25,7 +25,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Sha: "5678", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "5678", Action: todo.Pick},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "5678"},
@ -40,7 +40,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Sha: "abcd", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "abcd", Action: todo.Pick},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@ -72,7 +72,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "def0"},
},
todoToMoveDown: Todo{Sha: "5678", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "5678", Action: todo.Pick},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@ -91,7 +91,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Sha: "def0", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "def0", Action: todo.Pick},
expectedErr: "Todo def0 not found in git-rebase-todo",
expectedTodos: []todo.Todo{},
},
@ -102,7 +102,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Sha: "1234", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "1234", Action: todo.Pick},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@ -114,7 +114,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "1234"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveDown: Todo{Sha: "1234", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "1234", Action: todo.Pick},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@ -151,7 +151,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Sha: "5678", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "5678", Action: todo.Pick},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@ -166,7 +166,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Sha: "1234", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "1234", Action: todo.Pick},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "5678"},
@ -198,7 +198,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "def0"},
},
todoToMoveUp: Todo{Sha: "abcd", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "abcd", Action: todo.Pick},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@ -217,7 +217,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Sha: "def0", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "def0", Action: todo.Pick},
expectedErr: "Todo def0 not found in git-rebase-todo",
expectedTodos: []todo.Todo{},
},
@ -228,7 +228,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Sha: "abcd", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "abcd", Action: todo.Pick},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@ -240,7 +240,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Label, Label: "myLabel"},
{Command: todo.Reset, Label: "otherlabel"},
},
todoToMoveUp: Todo{Sha: "5678", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "5678", Action: todo.Pick},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@ -264,8 +264,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
scenarios := []struct {
name string
todos []todo.Todo
originalSha string
fixupSha string
originalHash string
fixupHash string
expectedTodos []todo.Todo
expectedErr error
}{
@ -275,8 +275,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
{Command: todo.Pick, Commit: "original"},
{Command: todo.Pick, Commit: "fixup"},
},
originalSha: "original",
fixupSha: "fixup",
originalHash: "original",
fixupHash: "fixup",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},
{Command: todo.Fixup, Commit: "fixup"},
@ -291,8 +291,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
{Command: todo.Pick, Commit: "other"},
{Command: todo.Pick, Commit: "fixup"},
},
originalSha: "original",
fixupSha: "fixup",
originalHash: "original",
fixupHash: "fixup",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},
{Command: todo.Fixup, Commit: "fixup"},
@ -301,54 +301,54 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
expectedErr: nil,
},
{
name: "More original SHAs than expected",
name: "More original hashes than expected",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},
{Command: todo.Pick, Commit: "original"},
{Command: todo.Pick, Commit: "fixup"},
},
originalSha: "original",
fixupSha: "fixup",
originalHash: "original",
fixupHash: "fixup",
expectedTodos: nil,
expectedErr: errors.New("Expected exactly one original SHA, found 2"),
expectedErr: errors.New("Expected exactly one original hash, found 2"),
},
{
name: "More fixup SHAs than expected",
name: "More fixup hashes than expected",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},
{Command: todo.Pick, Commit: "fixup"},
{Command: todo.Pick, Commit: "fixup"},
},
originalSha: "original",
fixupSha: "fixup",
originalHash: "original",
fixupHash: "fixup",
expectedTodos: nil,
expectedErr: errors.New("Expected exactly one fixup SHA, found 2"),
expectedErr: errors.New("Expected exactly one fixup hash, found 2"),
},
{
name: "No fixup SHAs found",
name: "No fixup hashes found",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},
},
originalSha: "original",
fixupSha: "fixup",
originalHash: "original",
fixupHash: "fixup",
expectedTodos: nil,
expectedErr: errors.New("Expected exactly one fixup SHA, found 0"),
expectedErr: errors.New("Expected exactly one fixup hash, found 0"),
},
{
name: "No original SHAs found",
name: "No original hashes found",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "fixup"},
},
originalSha: "original",
fixupSha: "fixup",
originalHash: "original",
fixupHash: "fixup",
expectedTodos: nil,
expectedErr: errors.New("Expected exactly one original SHA, found 0"),
expectedErr: errors.New("Expected exactly one original hash, found 0"),
},
}
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
actualTodos, actualErr := moveFixupCommitDown(scenario.todos, scenario.originalSha, scenario.fixupSha)
actualTodos, actualErr := moveFixupCommitDown(scenario.todos, scenario.originalHash, scenario.fixupHash)
if scenario.expectedErr == nil {
assert.NoError(t, actualErr)
@ -379,7 +379,7 @@ func TestRebaseCommands_deleteTodos(t *testing.T) {
},
todosToDelete: []Todo{
{Ref: "refs/heads/some_branch", Action: todo.UpdateRef},
{Sha: "abcd", Action: todo.Pick},
{Hash: "abcd", Action: todo.Pick},
},
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@ -394,7 +394,7 @@ func TestRebaseCommands_deleteTodos(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
},
todosToDelete: []Todo{
{Sha: "abcd", Action: todo.Pick},
{Hash: "abcd", Action: todo.Pick},
},
expectedTodos: []todo.Todo{},
expectedErr: errors.New("Todo abcd not found in git-rebase-todo"),

View File

@ -4,7 +4,7 @@
# 1) find a commit that is working fine.
# 2) Create an integration test capturing the fact that it works (Don't commit it). See https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md
# 3) checkout the commit that's known to be failing
# 4) run this script supplying the commit sha / tag name that works and the name of the newly created test
# 4) run this script supplying the commit hash / tag name that works and the name of the newly created test
# usage: scripts/bisect.sh <ref that's broken> <ref that's working> <integration test name>
# e.g. scripts/bisect.sh v0.32.1 mergeConflictsResolvedExternally