Skip to contentSkip to conversation

Why is TreeWalk.forPath(...) returning null

DISCUSSION Farrukh Najmi 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

My "git status" command shows:

# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: xml/minDB/SubmitObjectsRequest_CMSScheme.xml

The file above was committed and then modified. I want to use jgit to find the comitted version of that file.

When I do the following code I get a null treeWalk? Why is that? What should I specify for path instead?

           String path = "xml/minDB/SubmitObjectsRequest_CMSScheme.xml";
           String versionName = Constants.HEAD;

           Commit commit = repository.mapCommit(versionName);

           if (commit == null) {
               log.trace("Did not find Commit. versionName:" + 
versionName);
           } else {
               ObjectId[] ids = {commit.getTree().getId()};
               TreeWalk treeWalk = TreeWalk.forPath(repository, path, ids);
           }

Thanks.

Signature · 4 lines
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
#1 lore raw
Quoted 15 lines · Farrukh Najmi

My "git status" command shows:

# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: xml/minDB/SubmitObjectsRequest_CMSScheme.xml

The file above was committed and then modified. I want to use jgit to find the comitted version of that file.

When I do the following code I get a null treeWalk? Why is that? What should I specify for path instead?

Quoted 12 lines
           String path = "xml/minDB/SubmitObjectsRequest_CMSScheme.xml";
           String versionName = Constants.HEAD;

           Commit commit = repository.mapCommit(versionName);

           if (commit == null) {
               log.trace("Did not find Commit. versionName:" +  
versionName);
           } else {
               ObjectId[] ids = {commit.getTree().getId()};
               TreeWalk treeWalk = TreeWalk.forPath(repository, path, ids);
           }

Huh. That should have worked.

TreeWalk.forPath returns null if the path doesn't get found. So it sounds like jgit isn't matching the path. Its a pretty simple operation, I'm not sure why its failing here. I'd run it through a debugger to try and see why the TreeWalk didn't match your path.

Your code is logically the same as:

git rev-parse HEAD:$path

so it should find the blob if Git would have found it.

Signature · 1 line
Shawn.
#2 lore raw
Quoted 35 lines · Shawn O. Pearce
Quoted 12 lines · Farrukh Najmi

My "git status" command shows:

# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: xml/minDB/SubmitObjectsRequest_CMSScheme.xml

The file above was committed and then modified. I want to use jgit to find the comitted version of that file.

When I do the following code I get a null treeWalk? Why is that? What should I specify for path instead?

Quoted 13 lines
           String path = "xml/minDB/SubmitObjectsRequest_CMSScheme.xml";
           String versionName = Constants.HEAD;

           Commit commit = repository.mapCommit(versionName);

           if (commit == null) {
               log.trace("Did not find Commit. versionName:" +  
versionName);
           } else {
               ObjectId[] ids = {commit.getTree().getId()};
               TreeWalk treeWalk = TreeWalk.forPath(repository, path, ids);
           }

Huh. That should have worked.

TreeWalk.forPath returns null if the path doesn't get found. So it sounds like jgit isn't matching the path. Its a pretty simple operation, I'm not sure why its failing here. I'd run it through a debugger to try and see why the TreeWalk didn't match your path.

Quoted 7 lines

Your code is logically the same as:

git rev-parse HEAD:$path

so it should find the blob if Git would have found it.

My bad. I had a type in the path in my junit test :-[ Its working as expected. Thanks.

Signature · 4 lines
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com