Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Enforcing autocrlf=false

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

On Thu, May 5, 2016 at 4:45 PM, Gabriel Titerlea <gabriel_titerlea@xxxxxxx> wrote:
Hello,

I am using JGit in an environment where I cannot modify the global .gitconfig file.
(application is given to users who may or may not have git installed and may be on windows or linux).

I would like to set the core.autocrlf value to false programatically (overriding the value from the .gitconfig file).
Is that possible?

Thanks,
Gabriel

_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jgit-dev




Back to the top