Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Idiomatic way of saving a file
Idiomatic way of saving a file [message #1851478] Wed, 06 April 2022 12:03
Kirill Yankov is currently offline Kirill YankovFriend
Messages: 1
Registered: April 2022
Junior Member
Hello everyone,

I am trying to create a new file (or update an exiting one) with jgit,
so the easiest way is just to first write file contents using standard java IO
File myFile = new File(repository.getDirectory().getParent(), "testfile");
                if(!myFile.createNewFile()) {
                    throw new IOException("Could not create file " + myFile);
                }
//... then write bytes to the file

and then
 add
and
commit
it.

I am just wondering if the same is possible using only JGit API? Maybe through ObjectInserter (can't find on how to properly do a commit with low level api)?

I am looking for something like
Array[byte] content = ???
String filePath = ???

Git git = Git.open(repoPath);
Repository repo = git.getRepository;
repo.addOrUpdateFileContent(filePath, content);
git.commit().call();



Thank you for help!
Previous Topic:Idiomatic way to check for bare repos while cloning
Next Topic:JGit exception java.security.spec.InvalidKeySpecException only when running unit test
Goto Forum:
  


Current Time: Fri Apr 26 00:45:48 GMT 2024

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

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

Back to the top