git - Get latest committed branch(name) details in JGit -


how determine latest committed branch in git repository? want clone updated branch instead of cloning branches despite of whether merged master (default branch) or not.

lsremotecommand remotecommand = git.lsremoterepository(); collection <ref> refs = remotecommand.setcredentialsprovider(new usernamepasswordcredentialsprovider(username, password))                     .setheads(true)                     .setremote(uri)                     .call();  (ref ref : refs) {     system.out.println("ref: " + ref.getname()); }   //cloning repo clonecommand clonecommand = git.clonerepository(); result = clonecommand.seturi(uri.trim())  .setdirectory(localpath).setbranchestoclone(branchlist) .setbranch("refs/heads/branchname") .setcredentialsprovider(new usernamepasswordcredentialsprovider(username,password)).call(); 

can me on this?

i afraid have clone entire repository branches find out newest branch.

the lsremotecommand lists branch names , id's of commits point to, not timestamp of commit.

git's 'everything local' design requires clone repository before examining contents. note: using git/jgit's low-level commands/apis possible fetch head commit of branch examination, contradicts design.

once have cloned repository (without initial checkout) can iterate on branches, load respective head commit , see 1 newest.

the example below clone repository branches , lists branches find out @ time respective head commits made:

git git = git.clonerepository().seturi( ... ).setnocheckout( true ).setcloneallbranches( true ).call(); list<ref> branches = git.branchlist().setlistmode( listmode.remote ).call(); try( revwalk walk = new revwalk( git.getrepository() ) ) {   for( ref branch : branches ) {     revcommit commit = walk.parsecommit( branch.getobjectid() );     system.out.println( "time committed: " + commit.getcommitterident().getwhen() );     system.out.println( "time authored: " + commit.getauthorident().getwhen() );   } } 

now know newest branch, can checkout branch.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -