Commit Graph

58 Commits

Author SHA1 Message Date
GEV
39360083bb feature: add added/removed line counts to diff view (#2194) 2026-03-16 13:14:57 +08:00
Sina Hinderks
b84b79322f fix: stage/discard/unstage hunk (#1996)
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.
2025-12-20 11:38:06 +08:00
leo
e2feac3624 refactor: rewrite TextDiffContext and fix the issue that text diff view does not navigate to the first change chunk after select a different commit with the same file
Signed-off-by: leo <longshuang@msn.cn>
2025-12-03 18:20:32 +08:00
leo
c1a01b2fc7 code_style: refactor datas used by text diff result
Signed-off-by: leo <longshuang@msn.cn>
2025-12-01 19:56:59 +08:00
leo
c76b770408 refactor: diff command parameters generation
Signed-off-by: leo <longshuang@msn.cn>
2025-11-27 15:03:33 +08:00
leo
4fcb12bbf7 fix: use --ignore-space-change instead of --ignore-all-space when Ignore All Whitespace Changes option is enabled (#1752)
Signed-off-by: leo <longshuang@msn.cn>
2025-11-27 14:51:22 +08:00
leo
c187480a9d enhance: do not return to UIThread while calculating git outputs
Signed-off-by: leo <longshuang@msn.cn>
2025-11-25 15:31:38 +08:00
leo
4419b734a5 enhance: always turn off --color=<when> and --ext-diff when calling git diff in SourceGit (#1922)
Signed-off-by: leo <longshuang@msn.cn>
2025-11-19 10:28:51 +08:00
leo
9be50eb892 enhance: do not create temp string for large output of some git command
Signed-off-by: leo <longshuang@msn.cn>
2025-09-01 14:19:17 +08:00
leo
6511d15c01 refactor: rewrite text diff view
- 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>
2025-08-19 15:53:03 +08:00
Nathan Baulch
5c9d96fe7a refactor: streamline certain string operations (#1540) 2025-07-07 17:36:41 +08:00
Nathan Baulch
3583527026 code_style: general cleanup (#1525) 2025-07-05 15:58:16 +08:00
leo
40765826ce code_review: PR #1492
- 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>
2025-07-03 17:30:06 +08:00
Nathan Baulch
463e304491 feature: async (#1492)
* Async command methods
* Async `Task.Run` where possible
* Remove redundant `Task.Run` in `Sure` methods
* Remove leftover braces and reformat
* Async event handlers as needed
2025-07-03 15:38:39 +08:00
leo
054bbf7e0c enhance: do not override core.autocrlf configure while reading file diff (#1278)
Signed-off-by: leo <longshuang@msn.cn>
2025-05-06 09:39:03 +08:00
leo
825b74c2a3 refactor: use String.AsSpan(int, int) instead of String.AsSpan().Slice(int, int)
Signed-off-by: leo <longshuang@msn.cn>
2025-04-29 09:44:06 +08:00
leo
f72f1894c3 feature: supports to enable --ignore-cr-at-eol in diff by default
Signed-off-by: leo <longshuang@msn.cn>
2025-04-23 15:34:21 +08:00
leo
9a6c671a96 refactor: --ignore-cr-at-eol is not necessary when --ignore-all-space is enabled
Signed-off-by: leo <longshuang@msn.cn>
2025-04-22 16:50:46 +08:00
qiufengshe
9f18cbca5b minimize temporary strings for better performance (#1224)
* minimize temporary strings for better performance

* minimize temporary strings for better performance

(cherry picked from commit c9e6a8d4c2d7b5fe03ee13af0a79c5334c23b1c0)
2025-04-22 10:23:20 +08:00
leo
db46de0261 enhance: append character U+26D4 to line when \ No newline at end of file is found in git diff output (#1197)
Signed-off-by: leo <longshuang@msn.cn>
2025-04-16 11:41:40 +08:00
leo
03216fc31e code_style: run dotnet format and re-order codes
Signed-off-by: leo <longshuang@msn.cn>
2025-04-15 16:30:50 +08:00
leo
be3f418680 fix: no diff content shows with new files (#1193)
Signed-off-by: leo <longshuang@msn.cn>
2025-04-15 11:03:34 +08:00
leo
e89dbd8f43 code_review: PR #1177
- 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>
2025-04-14 16:06:52 +08:00
Massimo
81820e7034 refactor: improve diff handling for EOL changes and enhance text diff… (#1177)
* 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>
2025-04-14 15:18:45 +08:00
GadflyFang
7f8372f6b5 enhance: Handle file mode changes for new/deleted file (#1040) 2025-03-03 10:38:58 +08:00
leo
15d3ad355d code_review: PR #703
* 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>
2024-12-08 21:02:30 +08:00
Göran W
655d71b0bc Add navigation and highlighting of change-blocks in Text Diff (#616, #717) (#703)
* 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
2024-12-08 17:50:33 +08:00
leo
58eeeab67b enhance: set core.autocrlf to false when run git diff to get detail changes of selected file (#761) 2024-11-28 19:36:23 +08:00
leo
cd137e222c feature: enable --no-ext-diff for git diff command
Signed-off-by: leo <longshuang@msn.cn>
2024-11-16 09:26:13 +08:00
leo
050b1d1188 enhance: supports issue link in keywords (#678)
Signed-off-by: leo <longshuang@msn.cn>
2024-11-11 12:16:29 +08:00
leo
dcf5093406 enhance: avoid that diff view refresh more than one times
Signed-off-by: leo <longshuang@msn.cn>
2024-11-04 18:21:07 +08:00
leo
3da52208ba enhance: force enable --patch option 2024-10-17 19:20:14 +08:00
leo
d2a005c532 feature: add a button in diff view to ignore all whitespace changes (--ignore-all-space) 2024-09-30 11:34:09 +08:00
leo
ec6fe25e87 code_style: run dotnet format 2024-07-31 16:26:58 +08:00
leo
40d5a7c7f3 code_style: run dotnet format to apply rules 2024-07-23 13:58:57 +08:00
leo
b7e0e38de3 feature: stage/unstage hunk (#265) 2024-07-17 16:56:16 +08:00
leo
1040bbe4d2 feature: add buttons to increase/decrease visible lines in text diff view (#145) 2024-05-27 10:29:15 +08:00
leo
ab26bb83e9 refactor: re-design toolbar of Views.DiffView 2024-04-14 12:27:09 +08:00
leo
7b5534a267 code_style: run dotnet format to apply rules defined in .editorconfig 2024-04-13 19:24:45 +08:00
Gadfly
a249eed1ac feat: show git file mode change if exist 2024-04-12 21:38:36 +08:00
leo
96d4150d26 project: reorganize the structure of the project.
* 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.
2024-04-02 20:00:33 +08:00
Enner Pérez
a1a14f8858 Project Location 2024-03-20 02:38:28 -05:00
leo
18aaa0a143 style: add .editorconfig for code formatting. see issu #25 2024-03-18 09:37:06 +08:00
Enner Pérez
c0a079de41 Source Generated Regex 2024-03-16 04:09:27 -05:00
leo
cd2ecb109a enhance: diff with LFS filtered files 2024-03-14 10:55:25 +08:00
leo
59b7fd8c61 optimize: better supports for LFS object 2024-03-07 17:04:57 +08:00
leo
671e46f8b3 feature<TextDiffView>: supports line staging/unstaging in working copy diff view 2024-02-28 14:55:11 +08:00
leo
2a62596999 refactor<*>: rewrite all with AvaloniaUI 2024-02-06 15:08:37 +08:00
Jai
663f3237c0 Merge pull request !19 from Jai/fix/copy-content-order
* optimix<Diff>: performance optimization
* fix<DiffViewer>: incorrect order when copying file contents
2021-08-11 11:16:00 +00:00
leo
2cf7192ec4 cleanup<*>: run vs code cleanup to format codestyle and remove unused references 2021-08-05 15:54:00 +08:00