Actually this does not work.
Setting the autocrlf value after the repository has been cloned does
not influence the push command. So pushing creates line ending
changes.
Also reset does not do anything because JGit sees windows style line
endings and says they're good since cloning was done with
autocrlf=true.
What I did in the end was instead of calling the cloneRepository
method I went the long way:
Git git = Git.init().setDirectory(repositoryDir).call();
RemoteAddCommand remoteAdd = git.remoteAdd();
remoteAdd.setName(remote);
remoteAdd.setUri(new URIish(repositoryUri));
remoteAdd.call();
// By the way the RemoteAddCommand cannot be chained.
git.fetch()
.setRemote(remote)
.setCredentialsProvider(credentialsProvider)
.call();
// Need to set this so that no line-ending differences occur
git.getRepository().getConfig()
.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_AUTOCRLF, false);
git.checkout...
Gabriel
On 5/6/2016 8:30 AM, Gabriel Titerlea
wrote:
Thank you,
I can work with this.
However it would be nice to be able to set static options on the
Repository class so that this setting can be applied before
cloning a repository.
In my case I have to do a reset after cloning because cloning is
done with autocrlf=true.
Git git = Git.cloneRepository()
.setCloneAllBranches(true)
.setURI(URI)
.setDirectory(DIR)
.setCredentialsProvider(CD)
.call();
StoredConfig config = git.getRepository().getConfig();
config.setBoolean("core", null, "autocrlf", false);
git.reset()
.setMode(ResetType.HARD)
.call();
git.clean()
.setCleanDirectories(true)
.call();
Gabriel
On 5/6/2016 12:23 AM, Matthias Sohn
wrote:
Get the repository's config and set the
core.autocrlf option to false
StoredConfig config = Repository.getConfig();
config.setBoolean("core", null, "autocrlf", false);
config.save();
-Matthias
|