Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Blame the previous revision under its own name
| -rw-r--r-- | source/ui-blame.c | 10 | |
| -rwxr-xr-x | tests/t0104-tree.sh | 21 |
2 files changed, 27 insertions, 4 deletions
diff --git a/source/ui-blame.c b/source/ui-blame.c index eef8602..46d1654 100644 --- a/source/ui-blame.c +++ b/source/ui-blame.c @@ -127,6 +127,7 @@ static char *suspect_detail(struct blame_origin *suspect) static void emit_entry_hash(struct blame_entry *ent) { struct blame_origin *suspect = ent->suspect; + struct blame_origin *previous = suspect->previous; struct object_id *oid = &suspect->commit->object.oid; const char *detail = suspect_detail(suspect); @@ -137,13 +138,14 @@ static void emit_entry_hash(struct blame_entry *ent) ); html("</span>"); - if (!repo_parse_commit(the_repository, suspect->commit) && suspect->commit->parents) { - struct commit *parent = suspect->commit->parents->item; - + // git records the parent along with the path the file had there, + // which a rename changes, and records none for the commit that + // created the file. + if (previous) { html(" "); cgit_blame_link( "^", "Blame the previous revision", NULL, ctx.qry.head, - oid_to_hex(&parent->object.oid), suspect->path + oid_to_hex(&previous->commit->object.oid), previous->path ); } diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index 754b3e1..9d6e542 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -95,6 +95,27 @@ test_expect_success 'the folder crumbs of a blame page lead to the tree' ' grep "path: <a href=./nested/tree/.>root</a>/<a href=./nested/tree/a.>a</a>/<a href=./nested/tree/a/b.>b</a>/<a href=./nested/blame/a/b/file.txt.>file.txt</a>" tmp ' +# A commit's lines link to the file as the parent had it, under the name it +# had there, and the commit that created the file has nothing to link to. +test_expect_success 'blame links a commit to the file before it' ' + mkrepo repos/renamed 1 && + ( + cd repos/renamed && + test_seq 1 10 >a.txt && + git add a.txt && + git commit -m "add a.txt" && + git mv a.txt b.txt && + test_seq 1 9 >b.txt && + echo ten >>b.txt && + git commit -am "rename a.txt" + ) && + cgitrc_repo renamedrc renamed enable-blame=1 && + cgit_rc renamedrc "url=renamed/blame/b.txt" >tmp && + added=$(git -C repos/renamed rev-parse HEAD~1) && + grep "title=.Blame the previous revision. href=./renamed/blame/a.txt?id=$added.>^</a>" tmp && + test $(grep -c "Blame the previous revision" tmp) = 1 +' + test_expect_success 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >tmp' test_expect_success 'verify a+b link' ' |
