2012-10-09 4 views
17

Je joue autour de JGit, je pourrais supprimer avec succès une télécommande de certains référentiels (git remote rm origin), comment puis-je faire un git remote add origin http://github.com/user/repo?Ajouter à distance via JGit

Pour supprimer, je fais ce qui suit:

StoredConfig config = git.getRepository().getConfig(); 
config.unsetSection("remote", "origin"); 
config.save(); 

Mais il n'y a pas une option comme #setSection(String, String).

Merci d'avance.

Répondre

31

Infogérance fonctionner de cette façon:

Git git = new Git(localRepository); 
StoredConfig config = git.getRepository().getConfig(); 
config.setString("remote", "origin", "url", "http://github.com/user/repo"); 
config.save(); 

Et aparently il fonctionne comme un patron.

+0

Qu'est-ce que git ici? –

+1

Une instance de 'Git'. – caarlos0

0

Il y a des classes d'ajouter de nouvelles:

RemoteAddCommand remoteAddCommand = git.remoteAdd(); 
    remoteAddCommand.setName("origin"); 
    remoteAddCommand.setUri(new URIish("http://github.com/user/repo")); 
    remoteAddCommand.call(); 

Il y a un RemoteSetUrlCommand aussi.

Questions connexes