Waiting for coverage results... If this message persists check your coverage integration. Go to coverage settings
Up to quality standards.
.vscode
pkg/gui/controllers
pkg/gui/patch_exploring
pkg/integration/tests/patch_building
pkg/integration/tests/staging
.vscode/tasks.json
pkg/gui/controllers/patch_explorer_controller.go
Diff coverage
@@ -223,13 +223,13 @@ func (self *PatchExplorerController) HandleNextLineRange() error {
223} 224 225func (self *PatchExplorerController) HandlePrevHunk() error { 226self.context.GetState().CycleHunk(false) 227 228return nil 229} 230 231func (self *PatchExplorerController) HandleNextHunk() error { 232self.context.GetState().CycleHunk(true) 233 234return nil 235}223} 224 225func (self *PatchExplorerController) HandlePrevHunk() error { 226self.context.GetState().SelectPreviousHunk() Not covered227 228return nil 229} 230 231func (self *PatchExplorerController) HandleNextHunk() error { 232self.context.GetState().SelectNextHunk() 1 hits233 234return nil 235}pkg/gui/patch_exploring/state.go
Diff coverage
@@ -125,6 +125,11 @@ func (s *State) ToggleSelectHunk() {
125s.selectMode = LINE 126} else { 127s.selectMode = HUNK 128} 129} 125s.selectMode = LINE 126} else { 127s.selectMode = HUNK 128 1 hits129// If we are not currently on a change line, select the next one (or the 1 hits130// previous one if there is no next one): 1 hits131s.selectedLineIdx = s.viewLineIndices[s.patch.GetNextChangeIdx( 1 hits132s.patchLineIndices[s.selectedLineIdx])] 1 hits133} 134} @@ -203,25 +208,49 @@ func (s *State) DragSelectLine(newSelectedLineIdx int) {
203 204func (s *State) CycleSelection(forward bool) { 205if s.SelectingHunk() { 206s.CycleHunk(forward) 207} else { 208s.CycleLine(forward) 209} 210} 211 212func (s *State) CycleHunk(forward bool) { 213change := 1 214if !forward { 215change = -1 216} 217 218hunkIdx := s.patch.HunkContainingLine(s.patchLineIndices[s.selectedLineIdx]) 219if hunkIdx != -1 { 220newHunkIdx := hunkIdx + change 221if newHunkIdx >= 0 && newHunkIdx < s.patch.HunkCount() { 222start := s.patch.HunkStartIdx(newHunkIdx) 223s.selectedLineIdx = s.viewLineIndices[s.patch.GetNextChangeIdx(start)] 224} 225} 226} 208 209func (s *State) CycleSelection(forward bool) { 210if s.SelectingHunk() { 211if forward { 2 hits212s.SelectNextHunk() 1 hits213} else { 2 hits214s.SelectPreviousHunk() 1 hits215} 1 hits216} else { 217s.CycleLine(forward) 218} 219} 220 221func (s *State) SelectPreviousHunk() { 1 hits222patchLines := s.patch.Lines() 1 hits223patchLineIdx := s.patchLineIndices[s.selectedLineIdx] 1 hits224nextNonChangeLine := patchLineIdx 1 hits225for nextNonChangeLine >= 0 && patchLines[nextNonChangeLine].IsChange() { 2 hits226nextNonChangeLine-- 1 hits227} 228nextChangeLine := nextNonChangeLine 1 hits229for nextChangeLine >= 0 && !patchLines[nextChangeLine].IsChange() { 2 hits230nextChangeLine-- 1 hits231} 1 hits232if nextChangeLine >= 0 { 2 hits233// Now we found a previous hunk, but we're on its last line. Skip to the beginning. 1 hits234for nextChangeLine > 0 && patchLines[nextChangeLine-1].IsChange() { 2 hits235nextChangeLine-- 1 hits236} 237s.selectedLineIdx = s.viewLineIndices[nextChangeLine] 1 hits238} 239} 240 241func (s *State) SelectNextHunk() { 1 hits242patchLines := s.patch.Lines() 1 hits243patchLineIdx := s.patchLineIndices[s.selectedLineIdx] 1 hits244nextNonChangeLine := patchLineIdx 1 hits245for nextNonChangeLine < len(patchLines) && patchLines[nextNonChangeLine].IsChange() { 2 hits246nextNonChangeLine++ 1 hits247} 1 hits248nextChangeLine := nextNonChangeLine 1 hits249for nextChangeLine < len(patchLines) && !patchLines[nextChangeLine].IsChange() { 2 hits250nextChangeLine++ 1 hits251} 1 hits252if nextChangeLine < len(patchLines) { 2 hits253s.selectedLineIdx = s.viewLineIndices[nextChangeLine] 1 hits254} 255} @@ -259,11 +288,34 @@ func (s *State) CurrentHunkBounds() (int, int) {
259return start, end 260} 261 262func (s *State) SelectedViewRange() (int, int) { 263switch s.selectMode { 264case HUNK: 265start, end := s.CurrentHunkBounds() 266return s.viewLineIndices[start], s.viewLineIndices[end] 267case RANGE: 268if s.rangeStartLineIdx > s.selectedLineIdx { 269return s.selectedLineIdx, s.rangeStartLineIdx288return start, end 289} 290 291func (s *State) selectionRangeForCurrentBlockOfChanges() (int, int) { 1 hits292patchLines := s.patch.Lines() 1 hits293patchLineIdx := s.patchLineIndices[s.selectedLineIdx] 1 hits294 1 hits295patchStart := patchLineIdx 1 hits296for patchStart > 0 && patchLines[patchStart-1].IsChange() { 2 hits297patchStart-- 1 hits298} 1 hits299 300patchEnd := patchLineIdx 1 hits301for patchEnd < len(patchLines)-1 && patchLines[patchEnd+1].IsChange() { 2 hits302patchEnd++ 1 hits303} 1 hits304 305viewStart, viewEnd := s.viewLineIndices[patchStart], s.viewLineIndices[patchEnd] 1 hits306 1 hits307// Increase viewEnd in case the last patch line is wrapped to more than one view line. 1 hits308for viewEnd < len(s.patchLineIndices)-1 && s.patchLineIndices[viewEnd] == s.patchLineIndices[viewEnd+1] { 1 hits309viewEnd++ Not covered310} Not covered311 312return viewStart, viewEnd 1 hits313} 314 315func (s *State) SelectedViewRange() (int, int) { 316switch s.selectMode { 317case HUNK: 318return s.selectionRangeForCurrentBlockOfChanges() 1 hits 319case RANGE: 320if s.rangeStartLineIdx > s.selectedLineIdx { 321return s.selectedLineIdx, s.rangeStartLineIdxpkg/integration/tests/patch_building/specific_selection.go
Diff coverage
@@ -55,31 +55,13 @@ var SpecificSelection = NewIntegrationTest(NewIntegrationTestArgs{
55). 56Press(keys.Main.ToggleSelectHunk). 57SelectedLines( 58Contains(`@@ -1,6 +1,6 @@`), 59Contains(`-1a`), 60Contains(`+aa`), 61Contains(` 1b`), 62Contains(`-1c`), 63Contains(`+cc`), 64Contains(` 1d`), 65Contains(` 1e`), 66Contains(` 1f`), 67). 68PressPrimaryAction(). 69SelectedLines( 70Contains(`@@ -17,9 +17,9 @@`), 71Contains(` 1q`), 72Contains(` 1r`), 73Contains(` 1s`), 74Contains(`-1t`), 75Contains(`-1u`), 76Contains(`-1v`), 77Contains(`+tt`), 78Contains(`+uu`), 79Contains(`+vv`), 80Contains(` 1w`), 81Contains(` 1x`), 82Contains(` 1y`), 83). 84Tap(func() { 85t.Views().Information().Content(Contains("Building patch"))55). 56Press(keys.Main.ToggleSelectHunk). 57SelectedLines( 58Contains(`-1a`), 59Contains(`+aa`), 60). 61PressPrimaryAction(). 62SelectedLines( 63Contains(`-1c`), 1 hits64Contains(`+cc`), 1 hits 65). 66Tap(func() { 67t.Views().Information().Content(Contains("Building patch"))@@ -154,8 +136,7 @@ var SpecificSelection = NewIntegrationTest(NewIntegrationTestArgs{
154Contains(`-1a`), 155Contains(`+aa`), 156Contains(` 1b`), 157Contains(`-1c`), 158Contains(`+cc`), 159Contains(` 1d`), 160Contains(` 1e`), 161Contains(` 1f`),136Contains(`-1a`), 137Contains(`+aa`), 138Contains(` 1b`), 139Contains(` 1c`), 1 hits 140Contains(` 1d`), 141Contains(` 1e`), 142Contains(` 1f`),pkg/integration/tests/staging/diff_context_change.go
pkg/integration/tests/staging/stage_hunks.go
Diff coverage
@@ -11,11 +11,10 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
11Skip: false, 12SetupConfig: func(config *config.AppConfig) {}, 13SetupRepo: func(shell *Shell) { 14// need to be working with a few lines so that git perceives it as two separate hunks 15shell.CreateFileAndAdd("file1", "1a\n2a\n3a\n4a\n5a\n6a\n7a\n8a\n9a\n10a\n11a\n12a\n13a\n14a\n15a") 16shell.Commit("one") 17 18shell.UpdateFile("file1", "1a\n2a\n3b\n4a\n5a\n6a\n7a\n8a\n9a\n10a\n11a\n12a\n13b\n14a\n15a") 19 20// hunk looks like: 21// diff --git a/file1 b/file111Skip: false, 12SetupConfig: func(config *config.AppConfig) {}, 13SetupRepo: func(shell *Shell) { 14shell.CreateFileAndAdd("file1", "1a\n2a\n3a\n4a\n5a\n6a\n7a\n8a") 1 hits 15shell.Commit("one") 16 17shell.UpdateFile("file1", "1a\n2a\n3b\n4a\n5a\n6b\n7a\n8a") 1 hits18 19// hunk looks like: 20// diff --git a/file1 b/file1@@ -29,15 +28,10 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
29// +3b 30// 4a 31// 5a 32// 6a 33// @@ -10,6 +10,6 @@ 34// 10a 35// 11a 36// 12a 37// -13a 38// +13b 39// 14a 40// 15a 41// \ No newline at end of file 42}, 43Run: func(t *TestDriver, keys config.KeybindingConfig) {28// +3b 29// 4a 30// 5a 31// -6a 1 hits32// +6b 1 hits33// 7a 1 hits34// 8a 1 hits 35// \ No newline at end of file 36}, 37Run: func(t *TestDriver, keys config.KeybindingConfig) {@@ -55,43 +49,23 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
55). 56Press(keys.Universal.NextBlock). 57SelectedLines( 58Contains("-13a"), 59). 60Press(keys.Main.ToggleSelectHunk). 61SelectedLines( 62Contains("@@ -10,6 +10,6 @@"), 63Contains(" 10a"), 64Contains(" 11a"), 65Contains(" 12a"), 66Contains("-13a"), 67Contains("+13b"), 68Contains(" 14a"), 69Contains(" 15a"), 70Contains(`\ No newline at end of file`), 71). 72// when in hunk mode, pressing up/down moves us up/down by a hunk 73SelectPreviousItem(). 74SelectedLines( 75Contains(`@@ -1,6 +1,6 @@`), 76Contains(` 1a`), 77Contains(` 2a`), 78Contains(`-3a`), 79Contains(`+3b`), 80Contains(` 4a`), 81Contains(` 5a`), 82Contains(` 6a`), 83). 84SelectNextItem(). 85SelectedLines( 86Contains("@@ -10,6 +10,6 @@"), 87Contains(" 10a"), 88Contains(" 11a"), 89Contains(" 12a"), 90Contains("-13a"), 91Contains("+13b"), 92Contains(" 14a"), 93Contains(" 15a"), 94Contains(`\ No newline at end of file`), 95). 96// stage the second hunk 97PressPrimaryAction().49). 50Press(keys.Universal.NextBlock). 51SelectedLines( 52Contains("-6a"), 1 hits53). 54Press(keys.Main.ToggleSelectHunk). 55SelectedLines( 56Contains("-6a"), 1 hits57Contains("+6b"), 1 hits 58). 59// when in hunk mode, pressing up/down moves us up/down by a hunk 60SelectPreviousItem(). 61SelectedLines( 62Contains(`-3a`), 63Contains(`+3b`), 64). 65SelectNextItem(). 66SelectedLines( 67Contains("-6a"), 1 hits68Contains("+6b"), 1 hits 69). 70// stage the second hunk 71PressPrimaryAction().@@ -102,8 +76,8 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
102Tap(func() { 103t.Views().StagingSecondary(). 104ContainsLines( 105Contains("-13a"), 106Contains("+13b"), 107) 108}). 109Press(keys.Universal.TogglePanel)76Tap(func() { 77t.Views().StagingSecondary(). 78ContainsLines( 79Contains("-6a"), 1 hits80Contains("+6b"), 1 hits81) 82}). 83Press(keys.Universal.TogglePanel)@@ -112,11 +86,11 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
112IsFocused(). 113// after toggling panel, we're back to only having selected a single line 114SelectedLines( 115Contains("-13a"), 116). 117PressPrimaryAction(). 118SelectedLines( 119Contains("+13b"), 120). 121PressPrimaryAction(). 122IsEmpty()86IsFocused(). 87// after toggling panel, we're back to only having selected a single line 88SelectedLines( 89Contains("-6a"), 1 hits90). 91PressPrimaryAction(). 92SelectedLines( 93Contains("+6b"), 1 hits94). 95PressPrimaryAction(). 96IsEmpty()@@ -128,14 +102,8 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
128). 129Press(keys.Main.ToggleSelectHunk). 130SelectedLines( 131Contains(`@@ -1,6 +1,6 @@`), 132Contains(` 1a`), 133Contains(` 2a`), 134Contains(`-3a`), 135Contains(`+3b`), 136Contains(` 4a`), 137Contains(` 5a`), 138Contains(` 6a`), 139). 140Press(keys.Universal.Remove). 141Tap(func() {102). 103Press(keys.Main.ToggleSelectHunk). 104SelectedLines( 105Contains(`-3a`), 106Contains(`+3b`), 107). 108Press(keys.Universal.Remove). 109Tap(func() {@@ -143,15 +111,8 @@ var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
143}). 144Content(DoesNotContain("-3a").DoesNotContain("+3b")). 145SelectedLines( 146Contains("@@ -10,6 +10,6 @@"), 147Contains(" 10a"), 148Contains(" 11a"), 149Contains(" 12a"), 150Contains("-13a"), 151Contains("+13b"), 152Contains(" 14a"), 153Contains(" 15a"), 154Contains(`\ No newline at end of file`), 155) 156}, 157})111}). 112Content(DoesNotContain("-3a").DoesNotContain("+3b")). 113SelectedLines( 114Contains("-6a"), 115Contains("+6b"), 116) 117}, 118})