Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » How to check status of local branch with respect to remote branch in a lightweight way?
How to check status of local branch with respect to remote branch in a lightweight way? [message #1219939] Fri, 06 December 2013 23:43 Go to next message
Jarek Odzga is currently offline Jarek Odzga
Messages: 2
Registered: December 2013
Junior Member
Hi,

I am trying to implement a polling of remote branch to discover that my local branch need to be updated.

I am initializing git repo this way:

    val cloneCmd = Git.cloneRepository()
    cloneCmd.setDirectory(repoDir)
      .setURI(gitLocation)
      .setNoCheckout(false)
      .setBranch("live")
      .call()


and then I can manually update it:
    git.pull().call()


I am planning to implement polling remote repo (lets say every 15s), but I don't want to call pull() that often, because pull() is blocking other parts of app that use local branch. I'd like to check (often) somehow that local branch is behind and only then call pull().

How can I do that?

BTW, I want to use this mechanism to serve HTTP "directly from git repo". Obviously I have to "lock" traffic for a time of pull(). It is ok for my use case if this happens occasionally, but doing this every 15s is not acceptable.

Any help would be appreciated.
Re: How to check status of local branch with respect to remote branch in a lightweight way? [message #1220223 is a reply to message #1219939] Tue, 10 December 2013 13:16 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger Herrmann
Messages: 563
Registered: July 2009
Senior Member
pull actually does two things: it fetches commits from a remote and then
merges them into the current branch.
What you likely want is use
git.fetch().call()
to obtain changes from the remote (if any).
Then you can compare the local/current branch with its remote tacking
branch. BranchTrackingStatus.of() is there to help you with this.

HTH
Rüdiger

On 07.12.2013 20:02, Jarek Odzga wrote:
> Hi,
>
> I am trying to implement a polling of remote branch to discover that my
> local branch need to be updated.
>
> I am initializing git repo this way:
>
>
> val cloneCmd = Git.cloneRepository()
> cloneCmd.setDirectory(repoDir)
> .setURI(gitLocation)
> .setNoCheckout(false)
> .setBranch("live")
> .call()
>
>
> and then I can manually update it:
>
> git.pull().call()
>
>
> I am planning to implement polling remote repo (lets say every 15s), but
> I don't want to call pull() that often, because pull() is blocking other
> parts of app that use local branch. I'd like to check (often) somehow
> that local branch is behind and only then call pull().
>
> How can I do that?
>
> BTW, I want to use this mechanism to serve HTTP "directly from git
> repo". Obviously I have to "lock" traffic for a time of pull(). It is ok
> for my use case if this happens occasionally, but doing this every 15s
> is not acceptable.
>
> Any help would be appreciated.
>


--
Rüdiger Herrmann
http://codeaffine.com
Re: How to check status of local branch with respect to remote branch in a lightweight way? [message #1220270 is a reply to message #1220223] Tue, 10 December 2013 18:32 Go to previous messageGo to next message
Jarek Odzga is currently offline Jarek Odzga
Messages: 2
Registered: December 2013
Junior Member
Thanks!
This is exactly what I was looking for.
Re: How to check status of local branch with respect to remote branch in a lightweight way? [message #1220653 is a reply to message #1220223] Thu, 12 December 2013 21:48 Go to previous messageGo to next message
na na is currently offline na na
Messages: 8
Registered: November 2013
Junior Member
Rüdiger Herrmann wrote on Tue, 10 December 2013 14:16
pull actually does two things: it fetches commits from a remote and then
merges them into the current branch.
What you likely want is use
git.fetch().call()
to obtain changes from the remote (if any).
Then you can compare the local/current branch with its remote tacking
branch. BranchTrackingStatus.of() is there to help you with this.



While pull does two things isn't the fetch part the costly one? After all I thought fetch not only updates the local "remote" refs but also downloads the data as well. Eventually that's what you get using the CLI.
Re: How to check status of local branch with respect to remote branch in a lightweight way? [message #1220787 is a reply to message #1220653] Fri, 13 December 2013 15:22 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger Herrmann
Messages: 563
Registered: July 2009
Senior Member
you might be right. Depending on how far your local repository is
behind, fetch might be costly.
If you aren't interested in the details, you can dry-run the fetch
command. IIRC, that would give you the object-id of the remote commit
and you could compare that to your local object-id.

On 12.12.2013 22:48, na na wrote:
> Rüdiger Herrmann wrote on Tue, 10 December 2013 14:16
>> pull actually does two things: it fetches commits from a remote and
>> then merges them into the current branch.
>> What you likely want is use
>> git.fetch().call()
>> to obtain changes from the remote (if any).
>> Then you can compare the local/current branch with its remote tacking
>> branch. BranchTrackingStatus.of() is there to help you with this.
>
>
> While pull does two things isn't the fetch part the costly one? After
> all I thought fetch not only updates the local "remote" refs but also
> downloads the data as well. Eventually that's what you get using the CLI.
>
--
Rüdiger Herrmann
http://codeaffine.com
Re: How to check status of local branch with respect to remote branch in a lightweight way? [message #1221521 is a reply to message #1220787] Tue, 17 December 2013 21:57 Go to previous message
na na is currently offline na na
Messages: 8
Registered: November 2013
Junior Member
Rüdiger Herrmann wrote on Fri, 13 December 2013 16:22
you might be right. Depending on how far your local repository is
behind, fetch might be costly.
If you aren't interested in the details, you can dry-run the fetch
command. IIRC, that would give you the object-id of the remote commit
and you could compare that to your local object-id.


I totally forgot about the dry-run option...Wink
Previous Topic:Could Not Initialize NSS
Next Topic:remove a folder from git control
Goto Forum:
  


Current Time: Mon Sep 22 02:28:59 GMT 2014

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

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