A Rust implementation of the original gitwatch script - with a few additional features.
Features
- Watch a local Git repository and automatically commit changes
- Optionally push to a remote
- Use a custom commit message or generate one via a script
- Configure a debounce time to limit commit frequency
Usage
Basic usage:
I use gitwatch to watch my local notes repository and generate commit messages using aichat.
The example folder contains a small repository demonstrating this use case:
Configuration
❯ gitwatch watch --help
Watch a repository and commit changes
Usage: gitwatch watch [OPTIONS] [REPOSITORY]
Arguments:
[REPOSITORY] Path to the Git repository to monitor for changes [default: .]
Options:
-m, --commit-message <MESSAGE>
Static commit message to use for all commits
--commit-message-script <SCRIPT>
Path to executable script that generates commit messages.
The path can be absolute or relative to the repository.
The script is executed with the repository as working directory
and must output the message to stdout.
--commit-on-start <COMMIT_ON_START>
Automatically commit any existing changes on start [default: true] [possible values: true, false]
--debounce-seconds <DEBOUNCE_SECONDS>
Number of seconds to wait before processing multiple changes to the same file.
Higher values reduce commit frequency but group more changes together. [default: 1]
--dry-run
Run without performing actual Git operations (staging, committing, etc.)
-i, --ignore-regex <IGNORE_REGEX>
Regular expression pattern for files to exclude from watching.
Matching is performed against repository-relative file paths.
Note: the .git folder & gitignored files are ignored by default.
Example: "\.tmp$" to ignore temporary files.
--log-level <LOG_LEVEL>
Set the log level [default: info] [possible values: trace, debug, info, warn, error]
-r, --remote <REMOTE>
Name of the remote to push to (if specified).
Example: "origin".
--retries <RETRIES>
Number of retry attempts when errors occur.
Use -1 for infinite retries. [default: 3]
-w, --watch <WATCH>
Enable continuous monitoring of filesystem changes.
Set to false for one-time commit of current changes. [default: true] [possible values: true, false]
-h, --help
Print help
Config file
Most options can also be configured in a gitwatch.yml file located at the root of the watched repository.
See docs/gitwatch.example.yaml for reference.
Tips
If you've enabled gpgsign globally, you might want to disable it for the watched repositories, since gitwatch uses your regular git user to create the commits.
- Add an include to a custom
.gitconfigfile to your local gitconfig:# cd /path/to/repo - Create a .gitconfig file (which can be committed):
Create a systemd user service file gitwatch@.service:
[Unit]
Description=Watch a Git repository and automatically commit changes
[Service]
ExecStart=/usr/local/bin/gitwatch watch %I
ExecStop=/bin/true
[Install]
WantedBy=default.target
I recommend you use it in combination with a config file, then you only need to pass the repo dir as argument:
There's also a Nix module, which provides a home-manager service:
inputs = {
gitwatch-rs.url = "github:croissong/gitwatch-rs";
};
...
imports = [ inputs.gitwatch-rs.modules.gitwatch ];
services.gitwatch = {
notes = {
repo_path = "${config.home.homeDirectory}/notes/";
args = [ "--log-level=debug" ];
extraPackages = with pkgs; [
bash
coreutils
git
aichat
];
};
}
Installation
A flake.nix is available for Nix:
inputs = {
gitwatch-rs.url = "github:croissong/gitwatch-rs";
};
# Reference the package as `inputs.gitwatch-rs.packages.<system>.default`
}
# TODO: Add AUR package installation instructions
# TODO: Add Ubuntu package installation instructions
Install from crates.io:
Docker images are published to the ghcr.io/croissong/gitwatch-rs:
Precompiled binaries are available for Linux and macOS from releases.
Shell completion
Shell completion scripts for bash, zsh, fish & more can be generated via:
Credits
This is a Rust implementation of the original gitwatch bash script.
Contributing
Contributions are welcome! Feel free to submit a Pull Request.
See CONTRIBUTING.md for development hints.