Introducing GitWatch4J
Published 08/14/2024
📝 You can view the GitWatch4J source code here
One benefit of these website posts being markdown, is I can manage my post database using Git. To make it easier I figured I would use a watcher style service to monitor the files, then auto commit.
This type of program exists in many flavors, I decided to rewrite it in Java.
The core loop of the program works the same as GitWatch.
- Watch the directory provided
- On any new files:
- wait 2 seconds…
git add [file]git commit -m "Cleanup"
To make editing easier for programs that auto-save, I’ve included a -delay parameter that waits until the file has last been modified at least 10 minutes ago before commit.
If you’d like this program for Java I’ve released my version here, but I recommend you use the GitWatch project if you need something for production as this has only been tested on Konloch.com.
Requirements
- Git
- Java 8 or greater
Notes
If you add a new folder while the Git Watch service is running you will have to restart it to monitor files inside that folder.