git add --patch hunk edition: How to remove context lines?

411 views Asked by At

I am currently presented with the following situation:

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -10130,7 +10160,22 @@ function myGreatFunc(param1, param2

             let a = funcA(b, c);
             if(funcB(a, d.a.a) >= e) {
-                if(d.b === undefined
+                let f = c * parseInt(g.a[b].a);
+                if(h !== null
+                 && (h.a.a >= c
+                  && h.a.b === b
+                  || funcA(h.a.b, h.a.a) >= a
+                 )
+                ) f = 0;
+/*                if(b === 'a'
+                 && c === 1
+                 && d.a.name === 'b'
+                 && (d.c.a.includes('c')
+                  || d.c.a.includes('d')
+                 )
+                ) console.log('e', f);*/
+
+/*                if(d.b === undefined
                  || d.b.a > c * parseInt(g.a[b].a)
                  || d.b.a === c * parseInt(g.a[b].a)
                   && d.b.b < a

The goal is to remove all comments.

The problem here lies in the end of the hunk, which only includes the start of a block comment, and not its end. It thus keeps the last 3 lines as context, while I also want them removed.

Attempt n°1

Keeping the original context lines, so from-file-range does not need being modified

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -10130,7 +10160,11 @@ function myGreatFunc(param1, param2

             let a = funcA(b, c);
             if(funcB(a, d.a.a) >= e) {
-                if(d.b === undefined
+                let f = c * parseInt(g.a[b].a);
+                if(h !== null
+                 && (h.a.a >= c
+                  && h.a.b === b
+                  || funcA(h.a.b, h.a.a) >= a
+                 )
+                ) f = 0;
+
-                 || d.b.a > c * parseInt(g.a[b].a)
-                 || d.b.a === c * parseInt(g.a[b].a)
-                  && d.b.b < a

Note: The leading space for each of the context lines attempted to be removed has correctly been replaced (as opposed to merely preprended), with -.

Attempt n°2

Removing the original context lines

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -10130,4 +10160,11 @@ function myGreatFunc(param1, param2

             let a = funcA(b, c);
             if(funcB(a, d.a.a) >= e) {
-                if(d.b === undefined
+                let f = c * parseInt(g.a[b].a);
+                if(h !== null
+                 && (h.a.a >= c
+                  && h.a.b === b
+                  || funcA(h.a.b, h.a.a) >= a
+                 )
+                ) f = 0;
+

Results

Both attempts were met with:

error: patch failed: myFile.html:10130
error: myFile.html: patch does not apply
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?

Notes

Using git version 2.22.0.windows.1

How to edit that hunk to achieve the sought-after result?

0

There are 0 answers