Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 338760

Summary: [server] /git/diff REST API does not give any diff on staged files
Product: [ECD] Orion Reporter: libing wang <libingw>
Component: ClientAssignee: Tomasz Zarna <tomasz.zarna>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2    
Version: 0.2   
Target Milestone: 0.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 338225    

Description libing wang CLA 2011-03-02 18:54:48 EST
If a file is staged (e.g using git add to stage an existing file) , the /dit/diff REST API does not tell the diff.
Steps to reproduce :
1. Change a file in working directory.
2. use "git add" cmd to stage it
3. In Orion navigator table , go to the containing folder , and click on more-->Git status, this will open the gitstatus page.
4.The file is in the staged area.
5. Click on that file , there is no diff.
6. Change that file again 
7.Refresh the git status page , there are two items displaying. One in the unstaged area and one in the staged area.

Expected result:
For the one in the unstaged area , we should see the result is the same as "git diff" does.
For the one in the stage area , we should see result is the same as "git diff --cached " does.

I think the /git/diff should allow a parameter so that we make sure the the diff is based on "what against what" .

In order to achieve this , /git/index API may have to change as well.
Comment 1 Tomasz Zarna CLA 2011-03-03 06:56:35 EST
I was hoping I will get away with not providing "git diff --cached" as least until I finish bug 338203 ;) But on the other hand, I'm happy someone is using the API, so I'm switching to this task.

btw, I don't think this is a real "blocker"[1] it's more a bug blocking bug 338225 from being fully functional. Anyway, I'm on it.

[1] https://bugs.eclipse.org/bugs/page.cgi?id=fields.html#bug_severity
Comment 2 libing wang CLA 2011-03-03 08:28:45 EST
To make the 2 levels of diff clear , I would like to give the following use case and flow from a user's perspective.

1."fileA" is already in my local repo and has one line content "line1\n".
2. I add the second line so that the content is  "line1\nline2\n"  
3. Now I go to the git status page I should see "fileA" listed in the unstaged area.
4.I click on "fileA" , I can see the diff is "line1\nline2\n" VS "line1\n".
5.I use "git add fileA"
6.Go to git status page and refresh , now I see "fileA" i nthe staged area.
7.I click on "fileA" , I should stille see the diff as "line1\nline2\n" VS "line1\n".
8. I changed "fileA" again by adding "line3" , now the file content is "line1\nline2\nline3\n".
9.Go to git status page and refresh , now I see "fileA" in both staged and unstaged area.
10. I click on fileA in the unstaged area , I should see the diff as "line1\nline2\nline3\n" VS "line1\nline2\n".

I assume , the git/index will give me "line1\nline2\n" in step 7. I am wondering if we need another API git/HEAD to get "line1\n" because the diff in step 7 is "index VS HEAD".
Comment 3 Tomasz Zarna CLA 2011-03-04 05:37:42 EST
Fixed with 67b050dbe57015704f682e70bfb3bbd1b8364626. /git/status will now return different /git/diff URI for staged files (changed and removed). If you follow that link you will get the same result as "git diff --cached -- {path}" in a git CLI would return.

I'm going back to bug 338203. One of the things I'm gonna implement there is an ability to retrieve a file content for a given commit.