-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix blame when opened from an initial diff view (#1135)
When running "tig show 529182c -- README.adoc", blames were started on HEAD instead of 529182c. Fix this by reading the commit line of the displayed diff. This also works when multiple commits are shown ("tig show --all"). Using %(commit) instead of parsing the commit line did unfortunately not work because, because %(commit) can contain the wrong SHA for when returning from a blame view to a stash view, see test/blame/stash-test. Sadly, stashes don't contain commit lines, so we need to find out their SHAs in another way. Once we fix %(commit), we can use it, but for now this commit adds a workaround to use the old "view->vid", which seems to be set in the cases where display the output from "git stash show". Also, when blame is requested on a context line, use the current commit rather than its parent. This does not change behavior since a context line can never be blamed on the current commit, but this is consistent with the stage view, which only uses HEAD for deletions and the index for others. [ja: add test and commit message] Co-authored-by: Thomas Koutcher <thomas.koutcher@online.fr>
- Loading branch information
Showing
3 changed files
with
95 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
|
||
. libtest.sh | ||
. libgit.sh | ||
|
||
steps ' | ||
:save-display initial-diff.screen | ||
:20 # Move to a deleted line. | ||
:view-blame | ||
:scroll-right | ||
:save-display blame-deleted-line.screen | ||
' | ||
|
||
in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz" | ||
|
||
test_tig show a1dcf1a | ||
|
||
sed -i.old -n /asInstanceOf/p *.screen | ||
|
||
assert_equals 'initial-diff.screen' <<EOF | ||
- val global = js.Dynamic.global.asInstanceOf[js.Dictionary] | ||
+ val global = js.Dynamic.global.asInstanceOf[js.Dictionary[js.Any]] | ||
EOF | ||
|
||
# Make sure that we find the commit that introduce the deleted line. | ||
assert_equals 'blame-deleted-line.screen' <<EOF | ||
0500 17x val global = js.Dynamic.global.asInstanceOf[js.Dictionary] | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
|
||
. libtest.sh | ||
. libgit.sh | ||
|
||
tigrc <<EOF | ||
set blame-view = text | ||
EOF | ||
|
||
steps ' | ||
:view-stash | ||
:view-diff | ||
:move-last-line | ||
:move-up | ||
:save-display diff.screen | ||
:view-blame | ||
:save-display blame1.screen | ||
:view-close | ||
:view-blame | ||
:save-display blame2.screen | ||
' | ||
|
||
git_init | ||
|
||
test_setup_work_dir() | ||
{ | ||
echo "original line" > file | ||
git add file | ||
git commit -m "Initial commit" | ||
echo "changed line" > file | ||
git stash | ||
} | ||
|
||
LINES=3 test_tig | ||
|
||
assert_equals 'diff.screen' <<EOF | ||
-original line | ||
[diff] Changes to 'file' - line 9 of 10 90% | ||
EOF | ||
|
||
assert_equals 'blame1.screen' <<EOF | ||
original line | ||
[blame] file - line 1 of 1 100% | ||
EOF | ||
|
||
assert_equals 'blame2.screen' <<EOF | ||
original line | ||
[blame] file - line 1 of 1 100% | ||
EOF |