Giter VIP home page Giter VIP logo

Comments (15)

philjackson avatar philjackson commented on May 14, 2024

It's because there's a mix of unix and DOS newlines. Pretty easy to fix... I think.

*edit: or perhaps not.

from magit.

baudtack avatar baudtack commented on May 14, 2024

I'm going to try to take a look at it tonight if I have time. I'm assuming it's just some sort of escaping issue, but I only looked at the code for about 30 seconds.

from magit.

baudtack avatar baudtack commented on May 14, 2024

I tried to figure this out but couldn't. I tried using shell-quote-argument in magit-insert-current-line but that had no effect. I had difficulty following the flow of the program so that may not be where the problem is. It's seriously driving me insane though.

from magit.

baudtack avatar baudtack commented on May 14, 2024

Someone tagged this as "windows" It's not a windows problem. I'm having this problem on Linux where the original files were created in Windows with dos line endings.

from magit.

lindi2 avatar lindi2 commented on May 14, 2024

Steps to reproduce:

  1. git init
  2. echo hello > hello.txt
  3. git add hello.txt
  4. git commit -a -m 'hello'
  5. unix2dos hello.txt
  6. emacs
  7. M-x magit-status RET
  8. try to hit "v" at the hunk

Expected results:
8) hunk is reverted

Actual results:
8) magit says "git failed"

More info:

  1. Remarkably the problem stops occuring if I run

strace -p $(pidof emacs) -o emacs.strace -f -s4096

and then hit "v" again. Can you reproduce this?

from magit.

lindi2 avatar lindi2 commented on May 14, 2024

If I strace only git I see

15060 read(0, "diff --git a/hello.txt b/hello.txt\n", 8192) = 35
15060 read(0, "index ce01362..ef0493b 100644\n", 12277) = 30
15060 read(0, "--- a/hello.txt\n", 12247) = 16
15060 read(0, "+++ b/hello.txt\n", 12231) = 16
15060 read(0, "@@ -1 +1 @@\n", 12215) = 12
15060 read(0, "-hello\n", 12203) = 7
15060 read(0, "+hello\n", 12196) = 7
15060 read(0, "\n", 12189) = 1
15060 read(0, "", 12188)

which obviously lacks the \r. If I strace both emacs and git I see

15279 read(0, "diff --git a/hello.txt b/hello.txt\nindex ce01362..ef0493b 100644\n--- a/hello.txt\n+++ b/hello.txt\n@@ -1 +1 @@\n-hello\n+hello\r\n", 8192) = 124
15279 read(0, "", 12188)

which includes the "\r".

from magit.

lindi2 avatar lindi2 commented on May 14, 2024

The issue seems to be that the git subprocess has a terminal and stty -F /dev/pts/10 -a shows that "icrnl" is set. This means that \r gets converted to \n.

Why is git run in a terminal?

from magit.

lindi2 avatar lindi2 commented on May 14, 2024

You can pull a proposed fix from the issue-20 branch at

http://iki.fi/lindi/git/magit.git

From d8c938a812748b638e4ba6c30f7058e3920287b4 Mon Sep 17 00:00:00 2001
From: Timo Juhani Lindfors 
Date: Tue, 14 Sep 2010 22:33:02 +0300
Subject: [PATCH] Don't use a pty with git processes that take input from magit since
 that would set the terminal option icrnl which would modify the
 input. In particular \r would get converted to \n (issue #20).

---
 magit.el |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/magit.el b/magit.el
index 057c9c8..5f271fa 100644
--- a/magit.el
+++ b/magit.el
@@ -1465,7 +1465,10 @@ FUNC should leave point at the end of the modified region"
           (with-current-buffer input
         (setq default-directory dir)
         (setq magit-process
-              (apply 'magit-start-process cmd buf cmd args))
+              ;; Don't use a pty, because it would set icrnl
+              ;; which would modify the input (issue #20).
+              (let ((process-connection-type nil))
+            (apply 'magit-start-process cmd buf cmd args)))
         (set-process-filter magit-process 'magit-process-filter)
         (process-send-region magit-process
                      (point-min) (point-max))
-- 
1.7.1

from magit.

baudtack avatar baudtack commented on May 14, 2024

Tested and works great! So awesome. This has been driving me crazy for months but I haven't been able to get around to trying to figure it out. Hope this gets integrated into the mainline soon!

from magit.

philjackson avatar philjackson commented on May 14, 2024

Thanks for your work, chaps.

from magit.

baudtack avatar baudtack commented on May 14, 2024

Is there any ETA on this patch being merged?

from magit.

baudtack avatar baudtack commented on May 14, 2024

Sorry to keep harping on this. Any ETA on merging?

from magit.

philjackson avatar philjackson commented on May 14, 2024

I've applied lindi's patch. Thanks again.

from magit.

baudtack avatar baudtack commented on May 14, 2024

Oh frabjous day! Callooh! Callay! Makes me so happy!

from magit.

arvidj avatar arvidj commented on May 14, 2024

Good job, thank you!

from magit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.