Bug 434330 - jgit blame does not display origin commits for merge conflict lines while git does
Summary: jgit blame does not display origin commits for merge conflict lines while git...
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 4.0   Edit
Hardware: PC Linux
: P3 major with 2 votes (vote)
Target Milestone: 5.6   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-07 10:06 EDT by Martin Ross CLA
Modified: 2019-11-27 02:03 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Ross CLA 2014-05-07 10:06:48 EDT
git blame has a very useful feature where when you have a merge conflict it will show the annotation of lines from the merge source and the merge destination. 

e.g. See below for a single line file with conflicts on that line
00000000 (Not Committed Yet 2014-05-07 09:58:47 -0400 1) <<<<<<< HEAD
f2b76502 (m.ross            2014-05-07 09:52:29 -0400 2) Origin - Change on master branch
00000000 (Not Committed Yet 2014-05-07 09:58:47 -0400 3) =======
1be63005 (m.ross            2014-05-07 09:50:33 -0400 4) Origin -- conflicting change from branch
00000000 (Not Committed Yet 2014-05-07 09:58:47 -0400 5) >>>>>>> newbranch

Unfortunately jgit blame shows the following for the same file

00000000 (Not Committed Yet 2014-05-07 09:58:47 -0400 1) <<<<<<< HEAD
f2b76502 (m.ross            2014-05-07 09:52:29 -0400 2) Origin - Change on master branch
00000000 (Not Committed Yet 2014-05-07 09:58:47 -0400 3) =======
1be63005 (m.ross            2014-05-07 09:50:33 -0400 4) Origin -- conflicting change from branch
00000000 (Not Committed Yet 2014-05-07 09:58:47 -0400 5) >>>>>>> newbranch

To reproduce

git init newrepo
echo Origin > file
git add file
git commit -a -m "First commit"
git branch newbranch
git checkout newbranch
echo " Origin -- conflicting change from branch" > file
git commit -a -m "Conflicting commit on branch"
git checkout master
echo " Origin - - Change on master branch" > file
git commit -a -m "Conflicting commit on master branch"
git merge newbranch
git blame
jgit.sh blame
Comment 1 Andrey Hsiao CLA 2015-07-19 12:40:40 EDT
Hello,

Has this issue been resolved, or is there any plan for this?

Thanks
Comment 2 Christian Halstrick CLA 2015-07-20 04:30:11 EDT
?? Something must be wrong in the bug description. When I compare what you pasted as "git blame" and "jgit blame" output .... then these outputs are identical. Cut and paste error?

And when I run your test script (I had to modify it a bit) I see differences only in what metadata is presented for each line. The content lines itself are the same. 

Could you explain what you are missing?

Thats what I tried and where I get same results. Am I overlooking something or 'cut'-ing too much?

> git init newrepo
Initialized empty Git repository in /tmp/y/newrepo/.git/
> cd newrepo
> echo Origin > file
> git add file
> git commit -a -m "First commit"
[master (root-commit) 5fcaa9a] First commit
 1 file changed, 1 insertion(+)
 create mode 100644 file
> git branch newbranch
> git checkout newbranch
Switched to branch 'newbranch'
> echo " Origin -- conflicting change from branch" > file
> git commit -a -m "Conflicting commit on branch"
[newbranch 689ca03] Conflicting commit on branch
 1 file changed, 1 insertion(+), 1 deletion(-)
> git checkout master
Switched to branch 'master'
> echo " Origin - - Change on master branch" > file
> git commit -a -m "Conflicting commit on master branch"
[master 6b7f033] Conflicting commit on master branch
 1 file changed, 1 insertion(+), 1 deletion(-)
> git merge newbranch
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
> git blame -s file | cut -d' ' -f2- >gitBlameOutput
> jgit.sh blame -s file | cut -c10- >jgitBlameOutput
2015-07-20 10:29:01 DEBUG FS:433 - readpipe [git, config, --system, --edit],/usr/local/bin
2015-07-20 10:29:01 DEBUG FS:451 - readpipe may return '/usr/local/etc/gitconfig'
2015-07-20 10:29:01 DEBUG FS:452 - (ignoring remaing output:
> diff gitBlameOutput jgitBlameOutput
>
Comment 3 Martin Ross CLA 2015-07-20 16:27:38 EDT
Sorry..

The jgit blame file from above is
         (Not Committed Yet          1) <<<<<<< HEAD
         (Not Committed Yet          2)  Origin - - Change on master branch
         (Not Committed Yet          3) =======
         (Not Committed Yet          4) Origin -- conflicting change from branch
         (Not Committed Yet          5) >>>>>>> newbranch

while the git blame file
00000000 (Not Committed Yet 2015-07-20 16:26:27 -0400 1) <<<<<<< HEAD
9f1f5a82 (m.ross            2015-07-20 16:10:36 -0400 2)  Origin - - Change on master branch
00000000 (Not Committed Yet 2015-07-20 16:26:27 -0400 3) =======
4a2a4361 (m.ross            2015-07-20 16:10:04 -0400 4) Origin -- conflicting change from branch
00000000 (Not Committed Yet 2015-07-20 16:26:27 -0400 5) >>>>>>> newbranch

I will check against the latest as this was 3.3.2
Comment 4 Martin Ross CLA 2015-07-20 16:42:46 EDT
Running with jgit version 4.0.1.201506240215-r there is the same problem

2015-07-20 16:41:20 DEBUG FS:435 - readpipe [git, config, --system, --edit],/usr/local/bin
2015-07-20 16:41:20 DEBUG FS:453 - readpipe may return '/usr/local/etc/gitconfig'
2015-07-20 16:41:20 DEBUG FS:454 - (ignoring remaing output:
         (Not Committed Yet          1) <<<<<<< HEAD
         (Not Committed Yet          2)  Origin - - Change on master branch
         (Not Committed Yet          3) =======
         (Not Committed Yet          4) Origin -- conflicting change from branch
         (Not Committed Yet          5) >>>>>>> newbranch


The use case here is that resolving merges without this is much more difficult since you can't look at the author or time under jgit while you can in regular git.
Comment 5 Christian Halstrick CLA 2015-07-21 03:36:37 EDT
Ok, got it. You are missing commit-id and author&timestamp information in front of the lines. I agree, that looks like a bug. Have you seen it once working in JGit?
Comment 6 Martin Ross CLA 2015-07-21 08:25:56 EDT
It works post commit for simple cases (See below).  The real reason this is a major issue is that Show Annotations in EGit for eclipse is pretty useless since most of the time you care about origin of lines of code when trying to resolve conflicts in the same file.

git add file
git commit
[master ee3f2ca] Merge branch 'newbranch'
jgit blame file
ee3f2ca6 (m.ross   2015-07-21 08:23:12 -0400 1) <<<<<<< HEAD
9f1f5a82 (m.ross   2015-07-20 16:10:36 -0400 2)  Origin - - Change on master branch
ee3f2ca6 (m.ross   2015-07-21 08:23:12 -0400 3) =======
4a2a4361 (m.ross   2015-07-20 16:10:04 -0400 4) Origin -- conflicting change from branch
ee3f2ca6 (m.ross   2015-07-21 08:23:12 -0400 5) >>>>>>> newbranch


git blame file
ee3f2ca6 (m.ross 2015-07-21 08:23:12 -0400 1) <<<<<<< HEAD
9f1f5a82 (m.ross 2015-07-20 16:10:36 -0400 2)  Origin - - Change on master branch
ee3f2ca6 (m.ross 2015-07-21 08:23:12 -0400 3) =======
4a2a4361 (m.ross 2015-07-20 16:10:04 -0400 4) Origin -- conflicting change from branch
ee3f2ca6 (m.ross 2015-07-21 08:23:12 -0400 5) >>>>>>> newbranch
Comment 7 Andrius Semionovas CLA 2019-07-24 08:40:12 EDT
Bug still exists in 5.4.0. Workaround for using jgit as a library. However, you will lose merge state:

        //commit all files
        for ((filename, _) in mergeResult.conflicts) {
            git.add().addFilepattern(filename).call()
        }
        git.commit().setMessage("Temp commit for proper blaming").call()

        //blame as wanted
        for ((filename, _) in mergeResult.conflicts) {
            val blameResult = git.blame().setFilePath(filename).call()
        }

        //Do not forget to reset
        git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD^").call()
Comment 8 Eclipse Genie CLA 2019-08-06 12:37:47 EDT
New Gerrit change created: https://git.eclipse.org/r/147130
Comment 9 Thomas Wolf CLA 2019-08-06 13:27:09 EDT
(In reply to Eclipse Genie from comment #8)
> New Gerrit change created: https://git.eclipse.org/r/147130

This change should fix the real problem here, which is that lines 2 and 4 are not identified to come from the merge parents.

The missing timestamp (and zero commit Id) on the "Not Committed Yet" lines is dealt with in https://git.eclipse.org/r/#/c/147131/ .
Comment 10 Eclipse Genie CLA 2019-11-26 23:26:33 EST
Gerrit change https://git.eclipse.org/r/147130 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=59f9d206c954b5633f5978723bd0a2e7db31c2e8