mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	prevent staging directory containing files with inline merge conflicts
This commit is contained in:
		| @@ -16,26 +16,30 @@ type FileChangeNode struct { | ||||
| } | ||||
|  | ||||
| func (s *FileChangeNode) GetHasUnstagedChanges() bool { | ||||
| 	if s.IsLeaf() { | ||||
| 		return s.File.HasUnstagedChanges | ||||
| 	} | ||||
|  | ||||
| 	for _, child := range s.Children { | ||||
| 		if child.GetHasUnstagedChanges() { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| 	return s.AnyFile(func(file *File) bool { return file.HasUnstagedChanges }) | ||||
| } | ||||
|  | ||||
| func (s *FileChangeNode) GetHasStagedChanges() bool { | ||||
| 	if s.IsLeaf() { | ||||
| 		return s.File.HasStagedChanges | ||||
| 	return s.AnyFile(func(file *File) bool { return file.HasStagedChanges }) | ||||
| } | ||||
|  | ||||
| func (s *FileChangeNode) GetHasInlineMergeConflicts() bool { | ||||
| 	return s.AnyFile(func(file *File) bool { return file.HasInlineMergeConflicts }) | ||||
| } | ||||
|  | ||||
| func (s *FileChangeNode) AnyFile(test func(file *File) bool) bool { | ||||
| 	return s.Any(func(node *FileChangeNode) bool { | ||||
| 		return node.IsLeaf() && test(node.File) | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (s *FileChangeNode) Any(test func(node *FileChangeNode) bool) bool { | ||||
| 	if test(s) { | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| 	for _, child := range s.Children { | ||||
| 		if child.GetHasStagedChanges() { | ||||
| 		if test(child) { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -225,8 +225,6 @@ func (gui *Gui) handleFilePress() error { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// need to stage or unstage depending on situation. If we have a merge conflict we can't do anything | ||||
|  | ||||
| 	if node.IsLeaf() { | ||||
| 		file := node.File | ||||
|  | ||||
| @@ -244,6 +242,12 @@ func (gui *Gui) handleFilePress() error { | ||||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
| 		// if any files within have inline merge conflicts we can't stage or unstage, | ||||
| 		// or it'll end up with those >>>>>> lines actually staged | ||||
| 		if node.GetHasInlineMergeConflicts() { | ||||
| 			return gui.createErrorPanel(gui.Tr.ErrStageDirWithInlineMergeConflicts) | ||||
| 		} | ||||
|  | ||||
| 		if node.GetHasUnstagedChanges() { | ||||
| 			if err := gui.GitCommand.StageFile(node.Path); err != nil { | ||||
| 				return gui.surfaceError(err) | ||||
|   | ||||
| @@ -437,6 +437,7 @@ type TranslationSet struct { | ||||
| 	CommitMessageCopiedToClipboard      string | ||||
| 	LcCopiedToClipboard                 string | ||||
| 	ErrCannotEditDirectory              string | ||||
| 	ErrStageDirWithInlineMergeConflicts string | ||||
| } | ||||
|  | ||||
| const englishReleaseNotes = `## lazygit 0.26 Release Notes | ||||
| @@ -997,5 +998,6 @@ func englishTranslationSet() TranslationSet { | ||||
| 		CommitMessageCopiedToClipboard:      "Commit message copied to clipboard", | ||||
| 		LcCopiedToClipboard:                 "copied to clipboard", | ||||
| 		ErrCannotEditDirectory:              "Cannot edit directory: you can only edit individual files", | ||||
| 		ErrStageDirWithInlineMergeConflicts: "Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first", | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user