Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Idiomatic way of saving a file
Idiomatic way of saving a file [message #1851478] Wed, 06 April 2022 08:03
Eclipse UserFriend
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: Sun May 18 15:06:24 EDT 2025

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

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

Back to the top