When using CR/LF as newline on Windows, there were extra empty lines
shown in diffs.
Commit b84b79 fixed a regression (#1996) by keeping CRs as content of
diff lines instead of removing them. Additionally since commit 796f88
(#1543) the output for diffs uses the default newline depending on
platform, that's CR/LF on Windows.
As consequence on Windows with files containing CR/LF as newlines the
content (ending in CR) and the default newline CR/LF resulted in CR CR
LF, which is interpreted as two line breaks instead of one.
So b84b79 introduced itself a regression that's fixed in this commit by
partially reverting commit 796f88.
This fixes#2001.
- Do not use `add .` since it may run very slowly
- Rename `UnstageChangesForAmend` command to `UpdateIndexInfo` and force using UTF-8 (without BOM) encoding for inputs
- Remove unused commands
Signed-off-by: leo <longshuang@msn.cn>
There is a regression bug regarding staging, discarding, and unstaging
hunks. Depending on the data, these actions may be ignored or only
partially executed.
The following script generates a repository in the current directory
(named after the current directory) with four examples. Save the script
as `create-hunk-regression.sh`, make it executable with `chmod +x
create-hunk-regression.sh`, and start it with
`./create-hunk-regression.sh`. (Tested on Linux, should also work on
Windows.)
```bash
#!/usr/bin/env bash
set -e
dir=$(basename $(pwd))
rm -rf "$dir"
git init -b main "$dir" && cd "$dir"
echo -n '1n2n3n4n' | tr 'rn' '\r\n' > cannot-stage-hunks.txt
echo -n '2rn3rn' | tr 'rn' '\r\n' > partially-stages-hunks.txt
echo -n 'test1rnrnrnrntest3rn' | tr 'rn' '\r\n' > partially-stages-or-discards-hunk.txt
echo -n '1rn2rn3rn4rn' | tr 'rn' '\r\n' > cannot-unstage-hunks.txt
git add .
git commit -m 'initial commit'
echo -n '1rn2n3n4rn' | tr 'rn' '\r\n' > cannot-stage-hunks.txt
echo -n '1rn2rn3rn4rn' | tr 'rn' '\r\n' > partially-stages-hunks.txt
echo -n 'test1rnrntest2rnrntest3rn' | tr 'rn' '\r\n' > partially-stages-or-discards-hunk.txt
echo -n '1n2rn3rn4n' | tr 'rn' '\r\n' > cannot-unstage-hunks.txt
git add cannot-unstage-hunks.txt
```
For the examples to fully work you should configure Git/SourceGit the
following way:
- set `core.autocrlf` to `false`
- do not enable `--ignore-cr-at-eol` in diff
- do not ignore wwhitespace changes
This regression was introduced in commit 5c9d96, where breaking up the
diff into lines was changed from explicitly doing it to using the stream
function `ReadLineAsync`. Whereas the explicit code handled CR and LF
correctly, the stream function handles CR, CR/LF and LF the same way, so
that for Windows newlines (CR/LF) the CR will be lost.
The fix for this regression is going back to the explicit code and
ignoring `ReadLineAsync` for reading diffs.
This should fix at least partially issues #1950 and #1995.