Skip to content

Instantly share code, notes, and snippets.

@takezoe
Created May 1, 2018 07:29
Show Gist options
  • Save takezoe/3cf4166385351eb8ed8f809b90cbf41d to your computer and use it in GitHub Desktop.
Save takezoe/3cf4166385351eb8ed8f809b90cbf41d to your computer and use it in GitHub Desktop.
package com.github.takezoe.gitmesh.repository
import java.io.File
import org.apache.commons.io.FileUtils
import org.eclipse.jgit.api.Git
object GitSyncTest extends App {
val repo1 = new File("/tmp/repo1")
val repo2 = new File("/tmp/repo2")
if(repo1.exists()){
FileUtils.forceDelete(repo1)
}
if(repo2.exists()){
FileUtils.forceDelete(repo2)
}
val git1 = Git.init().setDirectory(repo1).call()
val file1 = new File(repo1, "README.txt")
FileUtils.write(file1, "test", "UTF-8")
git1.add().addFilepattern(".").call()
git1.commit().setMessage("Create README.txt").call()
val git2 = Git.cloneRepository().setDirectory(repo2).setURI(repo1.toURI.toString).setBare(true).call()
val file2 = new File(repo1, "test.txt")
FileUtils.write(file2, "test", "UTF-8")
git1.add().addFilepattern(".").call()
git1.commit().setMessage("Create test.txt").call()
git1.push().setRemote(repo2.toURI.toString).setPushAll().call()
git1.close()
git2.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment