Open ilyagr opened 6 days ago
I think pretending that the file had newlines is my preference. This will only matter if the user edits the conflicts manually, in which case the file was probably meant to end in a newline anyway.
There is one alternative on my mind, but I don't like it:
The fish shell prints ⏎\n
when a command's output does not end in a newline:
$ echo -n aa
aa⏎
$ # Next command here
We could in principle use a trick like that (either with ⏎\n
or with \nJJ: NO NEWLINE\n
), but I'm not sure it's worth it. Also, we then lose the ability to represent a file that ends with ⏎\n
. It's also a curious question what to do if a conflict not at the end of file includes ⏎\n
.
Mercurial adds "\ No newline at end of file" in diffs. We could copy that. I'm fine with either that or adding just a newline as you suggested.
I like the idea of using the existing label syntax; that avoids introducing any more ambiguity with change contents that isn’t already present. The two sides could disagree on the presence of the newline, right? If putting it at the end of the label line attached to the relevant text is too subtle, maybe another label line could be added?
IIUC the main idea in the thread so far is to only render the lack of a newline, but not necessarily be able to operate on it in a principled fashion?
Shouldn't the lack of a newline be encoded in the conflict marker syntax itself? It seems syntactically important. Wouldn't you want to preserve the invariant that you can reconstruct any of the file sides directly from the conflicted contents, rather than having to consult an out-of-band store?
UPDATE: I decided to promote this to a separate issue, https://github.com/martinvonz/jj/issues/3975.
Wouldn't you want to preserve the invariant that you can reconstruct any of the file sides directly from the conflicted contents, rather than having to consult an out-of-band store?
This issue has been nerd-sniping me for a while; in addition to trailing newlines, it's also a matter of encoding conflict markers inside files
TODO: find link. I remember discussing it with Martin recently in some PR, haven't found it yet. TLDR: jj
currently can't handle conflicts in out own tutorial.md
because of
In the shortest term, I'll probably ignore both issues and just add newlines to the end of files.
However, I think I finally figured out a syntax that will work, will not require a complicated parser, and even be somewhat readable. Before computing conflicts (and only if a file is conflicted), we'd encode file contents as follows:
JJ Verbatim Line:<<<<<<<<<<<
blahblah
JJ EOF: No newline at the end of file
JJ Verbatim Line:<<<<<<<<<<<
JJ Verbatim Line:JJ Verbatim Line:<<<<<<<<<<<
blahblah
JJ Verbatim Line:JJ EOF: No newline at the end of file
blah
JJ Verbatim Line:JJ EOF: No newline at the end of file
JJ EOF: No newline at the end of file
Fun, huh?
This relies on conflict markers having to start at the beginning of the line. If we ever have a notion of conflicts that happen in the middle of lines, we'd need a different syntax, of course. I think that would be nice, but also would probably need a whole different UI to be usable; I'm not sure it can be very usable in the terminal or as a text file.
Actual Result
If the file is subsequently edited,
jj
cannot parse the conflict correctly.Expected Behavior
I'd materialize the conflict as though the files ended in newlines, if we decide this is acceptable. We could perhaps notify the user about this in the labels:
If this is not acceptable, I'm not sure what is best to do.