-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into refactor-better-encapsulation
- Loading branch information
Showing
14 changed files
with
263 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
pkg/integration/tests/patch_building/move_to_earlier_commit_no_keep_empty.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package patch_building | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var MoveToEarlierCommitNoKeepEmpty = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Move a patch from a commit to an earlier commit, for older git versions that don't keep the empty commit", | ||
ExtraCmdArgs: "", | ||
Skip: false, | ||
GitVersion: Before("2.26.0"), | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.CreateDir("dir") | ||
shell.CreateFileAndAdd("dir/file1", "file1 content") | ||
shell.CreateFileAndAdd("dir/file2", "file2 content") | ||
shell.Commit("first commit") | ||
|
||
shell.CreateFileAndAdd("unrelated-file", "") | ||
shell.Commit("destination commit") | ||
|
||
shell.UpdateFileAndAdd("dir/file1", "file1 content with old changes") | ||
shell.DeleteFileAndAdd("dir/file2") | ||
shell.CreateFileAndAdd("dir/file3", "file3 content") | ||
shell.Commit("commit to move from") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Commits(). | ||
Focus(). | ||
Lines( | ||
Contains("commit to move from").IsSelected(), | ||
Contains("destination commit"), | ||
Contains("first commit"), | ||
). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("dir").IsSelected(), | ||
Contains(" M file1"), | ||
Contains(" D file2"), | ||
Contains(" A file3"), | ||
). | ||
PressPrimaryAction(). | ||
PressEscape() | ||
|
||
t.Views().Information().Content(Contains("building patch")) | ||
|
||
t.Views().Commits(). | ||
IsFocused(). | ||
SelectNextItem() | ||
|
||
t.Common().SelectPatchOption(Contains("move patch to selected commit")) | ||
|
||
t.Views().Commits(). | ||
IsFocused(). | ||
Lines( | ||
Contains("destination commit"), | ||
Contains("first commit").IsSelected(), | ||
). | ||
SelectPreviousItem(). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("dir").IsSelected(), | ||
Contains(" M file1"), | ||
Contains(" D file2"), | ||
Contains(" A file3"), | ||
Contains("A unrelated-file"), | ||
). | ||
PressEscape() | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package yaml_utils | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// takes a yaml document in bytes, a path to a key, and a value to set. The value must be a scalar. | ||
func UpdateYaml(yamlBytes []byte, path []string, value string) ([]byte, error) { | ||
// Parse the YAML file. | ||
var node yaml.Node | ||
err := yaml.Unmarshal(yamlBytes, &node) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse YAML: %w", err) | ||
} | ||
|
||
body := node.Content[0] | ||
|
||
updateYamlNode(body, path, value) | ||
|
||
// Convert the updated YAML node back to YAML bytes. | ||
updatedYAMLBytes, err := yaml.Marshal(body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to convert YAML node to bytes: %w", err) | ||
} | ||
|
||
return updatedYAMLBytes, nil | ||
} | ||
|
||
// Recursive function to update the YAML node. | ||
func updateYamlNode(node *yaml.Node, path []string, value string) { | ||
if len(path) == 0 { | ||
node.Value = value | ||
return | ||
} | ||
|
||
key := path[0] | ||
for i := 0; i < len(node.Content)-1; i += 2 { | ||
if node.Content[i].Value == key { | ||
updateYamlNode(node.Content[i+1], path[1:], value) | ||
return | ||
} | ||
} | ||
|
||
// if the key doesn't exist, we'll add it | ||
node.Content = append(node.Content, &yaml.Node{ | ||
Kind: yaml.ScalarNode, | ||
Value: key, | ||
}, &yaml.Node{ | ||
Kind: yaml.ScalarNode, | ||
Value: value, | ||
}) | ||
} |
Oops, something went wrong.