Skip to content

Interactive staging errors out #4233

@tristan-unity

Description

@tristan-unity

Describe the bug
The interactive staging, where you can stage by chunks/lines does not appear to work.

To Reproduce
Steps to reproduce the behavior:

  1. Create an empty repository git init.
  2. Create a file containing two lines.
line one
line two
  1. Commit the file.
  2. Edit the file.
line one and something
line two
line three
  1. Select the file and press enter to go the staging view.
  2. Select the first chunk line one and something.
  3. Stage the chunk

Screenshots

Image

Screen.Recording.2025-02-04.at.6.36.57.pm.mov

Version info:

~/g/lazygit-interactive-staging-repro (master)> lazygit --version
commit=, build date=, build source=homebrew, version=0.45.2, os=darwin, arch=arm64, git version=2.48.1
~/g/lazygit-interactive-staging-repro (master)> git --version
git version 2.48.1

Additional context
OS: MacOS
Terminal Emulator: Ghostty
Shell: fish

I have used git add -p to stage the first chunk.

~/g/lazygit-interactive-staging-repro (master)> git diff
diff --git a/test.txt b/test.txt
index e5c5c55..9b53c18 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
-line one
+line one and something
 line two
+line three

~/g/lazygit-interactive-staging-repro (master)> git add -p test.txt
diff --git a/test.txt b/test.txt
index e5c5c55..9b53c18 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
-line one
+line one and something
 line two
+line three
(1/1) Stage this hunk [y,n,q,a,d,s,e,p,?]? e

~/g/lazygit-interactive-staging-repro (master)> git diff --cached
diff --git a/test.txt b/test.txt
index e5c5c55..92186d0 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,2 @@
-line one
+line one and something
 line two

I then used git diff --cached > p.patch to make patch that should be similar to what I imagine lazygit is using.

~/g/lazygit-interactive-staging-repro (master)> git diff --cached > p.patch
~/g/lazygit-interactive-staging-repro (master)> cat p.patch
diff --git a/test.txt b/test.txt
index e5c5c55..92186d0 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,2 @@
-line one
+line one and something
 line two

I then reset the staging area with git restore --staged test.txt.

~/g/lazygit-interactive-staging-repro (master)> git restore --staged test.txt
~/g/lazygit-interactive-staging-repro (master)> git diff
diff --git a/test.txt b/test.txt
index e5c5c55..9b53c18 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
-line one
+line one and something
 line two
+line three

Finally I used git apply --cached p.patch and the patch was applied succesfully.

~/g/lazygit-interactive-staging-repro (master)> git apply --cached p.patch
~/g/lazygit-interactive-staging-repro (master)> git diff
diff --git a/test.txt b/test.txt
index 92186d0..9b53c18 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
 line one and something
 line two
+line three

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions