Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Cannot retrieve file from SHA-1 string
Cannot retrieve file from SHA-1 string [message #842420] Thu, 12 April 2012 09:26 Go to next message
Riccardo Casazza is currently offline Riccardo CasazzaFriend
Messages: 3
Registered: April 2012
Junior Member
Hi,

if I want to retrieve the content of a specific version of a file from a git repository, given the SHA-1 code, I could type in the bash console:

$ cd /path/to/repository
$ git show 7c66f31affb6861abafd9b5217f06ebdd25bc5d8


and I have the content of the file in the version I'm asking for.
I'm trying to do the same in java with jgit api:

FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(path).readEnvironment().findGitDir().build();

ObjectId object= repo.resolve("7c66f31affb6861abafd9b5217f06ebdd25bc5d8");

String result = new String(repo.open(object).getCachedBytes(), "UTF-8");


but I have a "Missing unknown 7c66f31affb6861abafd9b5217f06ebdd25bc5d8" exception in return

Where am I wrong?
Re: Cannot retrieve file from SHA-1 string [message #848441 is a reply to message #842420] Wed, 18 April 2012 08:16 Go to previous messageGo to next message
Riccardo Casazza is currently offline Riccardo CasazzaFriend
Messages: 3
Registered: April 2012
Junior Member
Hi,
no answers, maybe I posted my question in the wrong forum?

Thanks,
Riccardo
Re: Cannot retrieve file from SHA-1 string [message #848944 is a reply to message #842420] Wed, 18 April 2012 18:29 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Riccardo Casazza skrev 2012-04-12 11.26:
> Hi,
>
> if I want to retrieve the content of a specific version of a file from a git repository, given the SHA-1 code, I could type in the bash console:
>
>
> $ cd /path/to/repository
> $ git show 7c66f31affb6861abafd9b5217f06ebdd25bc5d8
>
>
> and I have the content of the file in the version I'm asking for.
> I'm trying to do the same in java with jgit api:
>
>
> FileRepositoryBuilder builder = new FileRepositoryBuilder();
> Repository repo = builder.setGitDir(path).readEnvironment().findGitDir().build();

Set the path to the
path = "/path/to/repository/.git" unless /path/to/repository is a bare repo

Since you already set gitDir, findGitDir has no effect.

> ObjectId object= repo.resolve("7c66f31affb6861abafd9b5217f06ebdd25bc5d8");
>
> String result = new String(repo.open(object).getCachedBytes(), "UTF-8");
>
>
> but I have a "Missing unknown 7c66f31affb6861abafd9b5217f06ebdd25bc5d8" exception in return
>
> Where am I wrong?
Re: Cannot retrieve file from SHA-1 string [message #849809 is a reply to message #848944] Thu, 19 April 2012 13:19 Go to previous messageGo to next message
Riccardo Casazza is currently offline Riccardo CasazzaFriend
Messages: 3
Registered: April 2012
Junior Member
Well, it works!

Tnx

R.
Re: Cannot retrieve file from SHA-1 string [message #1082351 is a reply to message #849809] Thu, 08 August 2013 12:54 Go to previous message
sha p is currently offline sha pFriend
Messages: 2
Registered: August 2013
Junior Member
could you please let me know how it fixed ?
Even i have the same problem and stuck here.

thank you.
~Sha
Previous Topic:JGit lacking full support for https?
Next Topic:Clone a Git repository is slow
Goto Forum:
  


Current Time: Thu Mar 28 23:36:23 GMT 2024

Powered by FUDForum. Page generated in 0.02591 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top