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.
- Move some data-only code from `Views` to `ViewModels`
- Remove unnecessary attributes
- This commit also contains a feature request #1722
Signed-off-by: leo <longshuang@msn.cn>
- Remove all synchronous method in commands
- `Command.ReadToEndAsync` now is protected method
- Rename `ResultAsync` to `GetResultAsync`
- Call `ConfigureAwait(false)` when there's no context
Signed-off-by: leo <longshuang@msn.cn>
- use `Command.ReadToEnd` instead of `Command.Exec` to avoid git trims line endings.
- use `StringBuilder.Append('\n')` instead of `StringBuilder.AppendLine()` to restore original line endings (we split the original diff output by `\n` not `\r')
- there's no need to show file content (the `StreamReader.ReadLine()` will trim line endings)
Signed-off-by: leo <longshuang@msn.cn>
* refactor: improve diff handling for EOL changes and enhance text diff display
- Updated `Diff.cs` to streamline whitespace handling in diff arguments.
- Enhanced `DiffContext.cs` to check for EOL changes when old and new hashes differ, creating a text diff if necessary.
- Added support for showing end-of-line symbols in `TextDiffView.axaml.cs` options.
* localization: update translations to include EOF handling in ignore whitespace messages
- Modified the ignore whitespace text in multiple language files to specify that EOF changes are also ignored.
- Ensured consistency across all localization files for the patch application feature.
* revert: Typo in DiffResult comment
* revert: update diff arguments to ignore CR at EOL in whitespace handling (like before changes)
* revert: update translations to remove EOF references in Text.Apply.IgnoreWS and fixed typo in Text.Diff.IgnoreWhitespace (EOF => EOL)
---------
Co-authored-by: mpagani <massimo.pagani@unitec-group.com>
* change the name of this feature to `Enable Block-Navigation`
* change the icon of the toggle button used to enable this feature
* use a new class `BlockNavigation` to hold all the data about this feature
* create `BlockNavigation` data only when it is enabled
Signed-off-by: leo <longshuang@msn.cn>
* Corrected misspelled local variable nextHigh(t)light
* Implemented change-block navigation
* Modified behavior of the Prev/Next Change buttons in DiffView toolbar.
* Well-defined change-blocks are pre-calculated and can be navigated between.
* Current change-block is highlighted in the Diff panel(s).
* Prev/next at start/end of range (re-)scrolls to first/last change-block
(I.e when unset, or already at first/last change-block, or at the only one.)
* Current change-block is unset in RefreshContent().
* Added safeguards for edge cases
* Added indicator of current/total change-blocks in DiffView toolbar
* Added new Icon and String (en-US) for Highlighted Diff Navigation
* Added Preference and ToggleButton for diff navigation style
* remove dotnet-tool.json because the project does not rely on any dotnet tools.
* remove Directory.Build.props because the solution has only one project.
* move src/SourceGit to src. It's not needed to put all sources into a subfolder of src since there's only one project.