Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How to retrieve user.name from StoredConfig using jgit?
How to retrieve user.name from StoredConfig using jgit? [message #1830491] Mon, 27 July 2020 19:12 Go to next message
Srinivas Reddy is currently offline Srinivas ReddyFriend
Messages: 2
Registered: July 2020
Junior Member
Hi,

I am trying to retrieve user name from StoredConfig using

StoredConfig storedConfig = repository.getConfig();
String userName = storedConfig.getString("user", "null", "name"); //returns null

when i debug the object, I see the value under baseConfig.
storedConfig
  state
  baseconfig
     state
       value
         entryList
            user.name = "value"

I tried storedConfig.getSubSections("user") but returns no results.

Is there any other way to retrieve user.name from storedConfig?
Re: How to retrieve user.name from StoredConfig using jgit? [message #1830497 is a reply to message #1830491] Mon, 27 July 2020 20:50 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 576
Registered: August 2016
Senior Member
Use
String userName = storedConfig.getString("user", null, "name"); 

(No quotes around null.)

Or, if you want to also honor environment variables GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL
UserConfig config = storedConfig.get(UserConfig.KEY);
String author = config.getAuthorName();
String authorEmail = config.getAuthorEmail()
Re: How to retrieve user.name from StoredConfig using jgit? [message #1830499 is a reply to message #1830497] Mon, 27 July 2020 21:03 Go to previous message
Srinivas Reddy is currently offline Srinivas ReddyFriend
Messages: 2
Registered: July 2020
Junior Member
Thomas Wolf wrote on Mon, 27 July 2020 20:50
Use
String userName = storedConfig.getString("user", null, "name"); 

(No quotes around null.)

Or, if you want to also honor environment variables GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL
UserConfig config = storedConfig.get(UserConfig.KEY);
String author = config.getAuthorName();
String authorEmail = config.getAuthorEmail()


Thank you so much. you saved my day. I had been struggling since last 3 hours.

Great. Thanks Again. It worked perfectly !!!
Previous Topic:Error in in respositories from Bitbucket
Next Topic:Commit and Push in a single click
Goto Forum:
  


Current Time: Thu Apr 18 03:38:42 GMT 2024

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

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

Back to the top