Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] How to fetch a specific commit with JGit

let me know if this works for you

On Mon, Feb 13, 2017 at 4:39 PM, Alaa Nassef <alan.125@xxxxxxxxx> wrote:
Thanks a million

On Mon, Feb 13, 2017 at 4:52 PM, Matthias Sohn <matthias.sohn@xxxxxxxxx> wrote:
On Mon, Feb 13, 2017 at 3:11 PM, Alaa Nassef <alan.125@xxxxxxxxx> wrote:
Hello Matthias,

Can you please tell me how can I make use of that, since it's not supported in porcelain FetchCommand. I'm using latest JGit 4.6. Thanks in advance

try to set the config parameter  uploadpack.allowreachablesha1inwant:

StoredConfig config = repository.getConfig();
config.setString("uploadpack", null, "allowreachablesha1inwant", true);
config.save();

and then run FetchCommand. 

As Chris already explained the server also needs to allow this. If the server is based on JGit set the same config option on the server.

 
On Mon, Feb 13, 2017 at 3:46 PM, Matthias Sohn <matthias.sohn@xxxxxxxxx> wrote:
On Mon, Feb 13, 2017 at 10:29 AM, Halstrick, Christian <christian.halstrick@xxxxxxx> wrote:

Server side: I once asked the question whether it is allowed to fetch SHA1’s here: http://git.661346.n2.nabble.com/Can-I-fetch-an-arbitrary-commit-by-sha1-td7619396.html . The answer was at that time that the server side decides whether this is allowed or not.  I think native git server side has learned more options regarding this. See https://git-scm.com/docs/git-config#git-config-uploadpackallowReachableSHA1InWant .

 

When I work e.g. with github I still see that I am not allowed to fetch any SHA1 which is known to the service side repo. See the log from my native git command line experiment and see how native git refuses the fetch

 

Client side: But since there are servers which do allow a fetch of SHA1 we should allow to talk to this servers from jgit. In the example you see below native git allows a “git fetch origin a29d652966d835393dfc98e7d266d1e4c8d184f7:newBranch” if the commit is already present in the local repo. It will create newBranch and let it point to that commit. But JGit behaves differently and disallows the fetch. We should fix JGit to behave like native git.


JGit supports uploadpack.allowreachablesha1inwant since 4.1, see
 
-Matthias

 

======================================================

> git --version

git version 2.10.2

> git clone https://github.com/chalstrick/dondalfi.git

Cloning into 'dondalfi'...

...

> git clone https://github.com/chalstrick/dondalfi.git dondalfi2

Cloning into 'dondalfi2'...

...

> cd dondalfi

> touch b

> git add  b

> git commit -m add_b

[master a29d652] add_b

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 b

> echo 2 >b

> git commit –a -m mod_b

[master 17b07fd] mod_b

1 file changed, 1 insertion(+)

> git log -2

commit 17b07fdb4c177d40a9b09b9cf012581b07d3f53d

Author: Christian Halstrick <christian.halstrick@xxxxxxx>

Date:   Mon Feb 13 10:08:41 2017 +0100

 

    mod_b

 

commit a29d652966d835393dfc98e7d266d1e4c8d184f7

Author: Christian Halstrick <christian.halstrick@xxxxxxx>

Date:   Mon Feb 13 10:08:13 2017 +0100

 

    add_b

> git push origin HEAD:testFetch

Counting objects: 6, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (4/4), done.

Writing objects: 100% (6/6), 504 bytes | 0 bytes/s, done.

Total 6 (delta 2), reused 2 (delta 0)

remote: Resolving deltas: 100% (2/2), completed with 1 local objects.

To https://github.com/chalstrick/dondalfi.git

* [new branch]      HEAD -> testFetch

> cd ../dondalfi2/

> git fetch origin a29d652966d835393dfc98e7d266d1e4c8d184f7:newBranch

error: no such remote ref a29d652966d835393dfc98e7d266d1e4c8d184f7

> git fetch origin

remote: Counting objects: 4, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0

Unpacking objects: 100% (4/4), done.

From https://github.com/chalstrick/dondalfi

* [new branch]      testFetch  -> origin/testFetch

> git fetch origin a29d652966d835393dfc98e7d266d1e4c8d184f7:newBranch

From https://github.com/chalstrick/dondalfi

* [new ref]         a29d652966d835393dfc98e7d266d1e4c8d184f7 -> newBranch

 

 

From: <jgit-dev-bounces@xxxxxxxxxxx> on behalf of Alaa Nassef <alan.125@xxxxxxxxx>
Date: Monday, 13 February 2017 at 07:41
To: "jgit-dev@xxxxxxxxxxx" <jgit-dev@xxxxxxxxxxx>
Subject: [jgit-dev] How to fetch a specific commit with JGit

 

I already asked this question on StackOverflow, but I need to confirm if there's a way to do that. In Git, it's possible to fetch specific commit (along with its ancestors of course) using the commit's SHA, so calling git fetch origin 57eab609d9efda3b8ee370582c3762c0e721033d:HEAD is perfectly normal. However, trying to do so with JGit fails, since FetchProcess tries to match the source of the passed RefSpec with the advertisedRefs, which are only the branches and tags.

 

Is there any way I can fetch a specific commit from a remote repository?


_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jgit-dev






Back to the top