Skip to content

Instantly share code, notes, and snippets.

@kristofmeixner
Created July 12, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristofmeixner/bac394c035b0a98b338202d3e8705768 to your computer and use it in GitHub Desktop.
Save kristofmeixner/bac394c035b0a98b338202d3e8705768 to your computer and use it in GitHub Desktop.
Saving query files in the queries branch
Git git = new Git(repository);
String pid = query.getPid().getIdentifier();
PersonIdent personIdent = new PersonIdent("Jane Doe","doe@gmail.com");
String message = "Created query file for PID=" + pid;
// Building the SHA1 hash for the PID
String fileName = DigestUtils.sha1Hex(pid) + ".query";
// Retrieving the queries branch
git.checkout().setName("refs/heads/queries").call();
Path filePath = Paths.get(getWorkingTreeDir(), fileName);
Properties properties = writeQueryToProperties(query);
properties.store(Files.newBufferedWriter(filePath), "");
// Adding the metadata file to the repository
git.add().addFilepattern(fileName).call();
// Committing the metadata file
git.commit().setMessage(message).setAuthor(personIdent).call();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment