Giter VIP home page Giter VIP logo

gitwatch's Introduction

gitwatch

A bash script to watch a file or folder and commit changes to a git repo

What to use it for?

That's really up to you, but here are some examples:

  • config files: some programs auto-write their config files, without waiting for you to click an 'Apply' button; or even if there is such a button, most programs offer you no way of going back to an earlier version of your settings. If you commit your config file(s) to a git repo, you can track changes and go back to older versions. This script makes it convenient, to have all changes recorded automatically.
  • document files: if you use an editor that does not have built-in git support (or maybe if you don't like the git support it has), you can use gitwatch to automatically commit your files when you save them, or combine it with the editor's auto-save feature to fully automatically and regularly track your changes
  • more stuff! If you have any other uses, or can think of ones, please let us know, and we can add them to this list!

Installation

gitwatch can be installed in various ways.

From Source

gitwatch can be installed from source by simply cloning the repository and putting the shell script into your $PATH. The commands below will do that for you if /usr/local/bin is in your $PATH. You may need to invoke install with sudo.

git clone https://github.com/gitwatch/gitwatch.git
cd gitwatch
[sudo] install -b gitwatch.sh /usr/local/bin/gitwatch

Update

If you installed gitwatch from source, you can update it by following the exact same steps (or git pull rather than clone if you kept the repository around).

bpkg

gitwatch can be installed with bpkg. Make sure you have bpkg installed before running the command below. You may need to invoke bpkg with sudo when using the -g flag.

[sudo] bpkg install -g gitwatch/gitwatch

Archlinux

There is an AUR package for Archlinux. Install it with you favorite aur helper.

NixOs

As Module

If you add gitwatch to your flake, and append field gitwatch.modules to your nixosSystem modules, then you can enable services.gitwatch.*:

services.gitwatch.<service name> = {
    enable = true;
    path = "/home/me/my-repo";
    remote = "[email protected]:me/my-repo.git";
    user = "me";
};

This will make NixOS to create systemd service named gitwatch-<service name>. Note that the service does not start before reboot, or alternatively if it is started manually: systemctl start gitwatch-<service name>.

As Package

You can to play around with nix package inside this repository. Call nix run in this repository to run gitwatch script or nix shell to enter shell with gitwatch command available.

Requirements

To run this script, you must have installed and globally available:

Notes for Mac

If running on OS X, you'll need to install the following Homebrew tools:

brew install fswatch
brew install coreutils

What it does

When you start the script, it prepares some variables and checks if the file or directory given as input really exists.

Then it goes into the main loop (which will run forever, until the script is forcefully stopped/killed), which will:

  • watch for changes to the file/directory using inotifywait (inotifywait will block until something happens)
  • wait 2 seconds
  • case file:
    • cd into the directory containing the file (because git likes to operate locally)
    • git add <file>
    • git commit -m "Scripted auto-commit on change (<date>)"
  • case directory:
    • cd into the directory (because git likes to operate locally)
    • git add --all .
    • git commit -m "Scripted auto-commit on change (<date>)"
  • if a remote is defined (with -r) do a push after the commit (a specific branch can be selected with -b)

Notes:

  • the waiting period of 2 sec is added to allow for several changes to be written out completely before committing; depending on how fast the script is executed, this might otherwise cause race conditions when watching a folder
  • currently, folders are always watched recursively

Usage

gitwatch.sh [-r <remote> [-b <branch>]] <file or directory to watch>

It is expected that the watched file/directory are already in a git repository (the script will not create a repository). If a folder is being watched, this will be watched fully recursively; this also means that all files and sub-folders added and removed from the directory will always be added and removed in the next commit. The .git folder will be excluded from the inotifywait call so changes to it will not cause unnecessary triggering of the script.

If you have any large files in your repository that are changing frequently, you might wish to ignore them with a .gitignore file.

Starting on Boot

If you want to have the script auto-started upon boot, the method to do this depends on your operating system and distribution. If you have a GUI dialog to set up startup launches, you might want to use that, so you can more easily find and change the startup script calls later on.

Please also note that if either of the paths involved (script or target) contains spaces or special characters, you need to escape them accordingly; if you don't know how to do that, the internet will help you, or feel free to ask here or contact me directly.

SysVInit

A central place to put startup scripts on Linux is generally /etc/rc.local (to my knowledge; only tested and confirmed on Ubuntu). This file, if it has the +x bit, will be executed upon startup, by the root user account. If you want to start gitwatch from rc.local, the recommended way to call it is:

su -c "/absolute/path/to/script/gitwatch.sh /absolute/path/to/watched/file/or/folder" -l <username> &

The <username> bit should be replaced with your username or that of any other (non-root) user account; it only needs write-access to the git repository of the file/folder you want to watch. The ampersand (&) at the end sends the launched process into the background (this is important if you have other calls in rc.local after the mentioned line, because the gitwatch call does not usually return).

systemd

  • If installed to a path other than /usr/local/bin/gitwatch, modify [email protected] to suit
  • Create dir if it does not exist and copy systemd service file with mkdir -p "$HOME/.config/systemd/user" && cp [email protected] $HOME/.config/systemd/user
  • Start and enable the service for a given path by running systemctl --user --now enable gitwatch@$(systemd-escape "'-r url/to/repository' /path/to/folder").service

Other Articles

On the Gitwatch Wiki

Community Articles

gitwatch's People

Contributors

amit-gshe avatar aseques avatar bmoffit avatar borgstad avatar cheerio-pixel avatar datag avatar dmusican avatar eidolonnight avatar ein-shved avatar elnull avatar gberche-orange avatar harleypig avatar he-sk avatar ishchow avatar jamietanna avatar juanmancebo avatar jwerle avatar kirviq avatar kollienne avatar lehnerpat avatar leoshimo avatar mattkotsenas avatar philt avatar pjanck avatar salanki avatar soraxas avatar t-nil avatar talamus avatar viniciusnevescosta avatar vogler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gitwatch's Issues

Update tests to use bats-core

The tests are based on the original bats but that version is no longer maintained.

I'd like to update these tests, and add some fail tests using the new bats, and using the libraries that are used there.

This would require any submitter to have bats-core and its plugins installed.

It might also require a change to the Github actions setup, I'm not sure.

Syntax error: redirection unexpected

Hi,

I'm getting the following error when starting gitwatch:

sh gitwatch.sh ~/.local/share/gtg/
/usr/local/bin/git
/usr/bin/inotifywait
gitwatch.sh: 133: gitwatch.sh: Syntax error: redirection unexpected

Any hint ?

Cheers,
~ elouann

Looking for maintainer(s) for gitwatch

Hey everyone!

Even though I have been inactive for a good while now, I love seeing that gitwatch is still useful to many people, and not few of you have added changes and fixes in your own forks!

As you may have expected, I have abandoned this project, mostly because I have not been using it myself for years at this point. Currently I don't have the time or interest to maintain or develop this project any further myself.

Therefore, I am looking for a person or small group to take over maintenance (and possibly further development) of gitwatch.

I intend to fully hand over this repository to the person or group, if someone can be found. This includes a transfer of ownership of this repository, so that changes can be made without my involvement.

I do not expect any right to make further decisions for the project after that point. I'd just like to be mentioned as an original contributor somewhere :)

If the license being GPLv3 should pose an obstacle, I'd be open to changing the license to another open source license.

Please let me know in this thread if you're interested in taking over the gitwatch project! :D

Merge Conflicts

At the moment I cannot see an option to tell the script how to deal with merge conflicts. It just crashes.

Would be nice if there where a possibility to (at least) tell that the server always wins or the remote:

https://git-scm.com/docs/merge-strategies

ours
This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree that do not conflict with our side are reflected in the merge result. For a binary file, the entire contents are taken from our side.

This should not be confused with the ours merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring our history contains all that happened in it.

theirs
This is the opposite of ours; note that, unlike ours, there is no theirs merge strategy to confuse this merge option with.

gitwatch does not stop when asked

When I run gitwatch on the commandline, in the foreground, it works. It starts 3 gitwatch processes, and 1 inotifywait process.

When I CTRL-C, the commandline process exits correctly, but the 2 other gitwatch processes (and the inotifywait process) keep running. They also keep working, when I make a change to the watched directory, the change is commited and pushed. This also happens when running with supervisord, using the configuration that is pointed to from the readme.

This gives issues when gitwatch is restarted every now and then. I had git locks appearing in my logs, because after some time I had 6 gitwatch processes running uncontrolled in the background.

I'm using latest gitwatch (directly from todays github), bash 4.2.46, git 2.21.0, all on CentOS 7.

Changes in .git/ are detected erroneously

In my version of bash (4.3.11) on Ubuntu, the script detects events inside the .git/ directory, even though it should ignore them. I figured out that the escaping of the quotation marks in the following line is the problem:

INCOMMAND="$INW --exclude=\"^${TARGETDIR}/.git\" -qqr -e close_write,move,delete,create $TARGETDIR"

The inner quotation characters do not get interpreted by bash - they get passed to inotifywait. I recommend replacing the call of $INCOMMAND with the unescaped command.

Multiple processes is a headache, plan to revert back to single

A while back, a notable update (#14) was made by @Nevik (which I merged in from the devel branch) where instead of running gitwatch as a single non-pipelined process, multiple pipelined processes are generated. This is so that inotifywait can run in monitor mode and pipe updates to gitwatch, instead of starting up a fresh instance of inotifywait after every change. This has a number of advantages to the previous approach; it means that there's likely less overhead, as inotifywait doesn't need to reinitialize itself every time. This might be especially noticeable on a large repository. It also means that we are less likely to miss changes that appear in between instances of inotifywait.

So this change had a lot of good associated with it. However, it means that gitwatch runs in multiple permanent processes (3-4 of them, depending on whether an actual commit process is sleeping or committing), as well as an inotifywait process. This raises difficulties in stopping gitwatch. There's a separate bug report by someone who claims that ctrl-C on the master process isn't killing the rest as it should. I've been unable to duplicate that, but I have regularly experienced other problems. I myself typically run gitwatch as a background process without an associated terminal, which means when I want it to stop, I need to kill it. With the new multiprocess approach, I need to make sure to kill all of the gitwatch processes, and also remember to look for the inotifywait process, because in monitor mode it doesn't die either. This is a pain for me, and a much more major usability challenge for people who don't know the script well.

Are there ways of fixing this? Presumably. I've been doing some research, as I'm not a deep bash expert. It looks like traps could be used to catch signals on one process to kill the rest. I've been experimenting with this some but haven't been all that successful. It would continue to make the script more complicated, as we'd have to make sure to capture the pids for each process spawned to make sure we can correctly kill them when one of them goes. And none of the approaches would be resistant to a kill -9.

I am therefore planning to revert gitwatch back to a single process script, where inotifywait does not run in monitor mode, and restarts after each change. At least for my use cases, I was not personally experiencing any performance difficulties with that anyway (though maybe someone else was). That said, I wanted to post this here to give anyone who wished a chance to respond; I'll wait a few weeks before doing this.

Fix exclusion regexp (pending reaction from inotify-win devs)

The problem with the regexp not working as discussed in #18 has to do with how inotify-win matches pathnames against the exclusion regexp (which is different from Linux inotifywait).

I've brought this up in thekid/inotify-win#11 and we can discuss further steps once the devs there have responded about whether they want to improve compatibility with Linux inotifywait.

more portable --exclude

It seems http://linux.die.net/man/1/inotifywait specifies --exclude rather than --exclude= but this might not be an issue.

However, related to this is specifying the .git folder to exclude. At least on inotify-win you can simply do --exclude .git and it works. I'll try to test on linux when I can but I've not setup my new linux vm yet.

Some testing to graduate current commits in devel branch

We need some testing to make sure the current commits in our devel branch are working properly.

Since I only have a very limited use-case for gitwatch myself at the moment, testing is very tedious for me (and limited to contrived examples, which may not find any unexpected problems).

I'd appreciate it if other people who have been using the devel branch or are willing to do so would report back their experiences in this issue.

@PhilT, random poke. I know it's been ages (and I've not been able to work on gitwatch or test it with inotiy-win), but if you're still using gitwatch and/or can test it, I'd really love your feedback :)

Check for ionotify in path

I have noticed that this script doesn't make sure that it cannot find the ionotifywait in the $PATH variable so that we can be sure that it's available for use, and if not alert the user. Possibly do this in a secondary script so that it doesn't have to be run on every use.

Running gitwatch for a time frame

Excellent tool. I'm thinking of setting a cron job to run gitwatch, but I wonder if it is possible to run it for a time frame (rather than forever :).

Add --usage/-h/--help switches

By now a usage/help page is probably quite useful; since there are more things to be added in the future (greater per-use customizability), this is a must.

Why I have 3 instances of gitwatch process when I run it?

Hi,
I run gitwatch(great thing, thanks) and I wanted to ask why i have 3 instances of gitwatch runnnig?

Here's my processes:

23538 pts/8 S+ 0:00 bash /home/red/bin/gitwatch.sh /home/red/RANGE/workshops/diamodification/transformator
23552 pts/8 S+ 0:00 bash /home/red/bin/gitwatch.sh /home/red/RANGE/workshops/diamodification/transformator
23553 pts/8 S+ 0:00 bash /home/red/bin/gitwatch.sh /home/red/RANGE/workshops/diamodification/transformator

Add option to include a (truncated) diff in the commit message

As implemented in a one-shot version at ibrahima/gitwatch@0163ec5, and pointed out by @ibrahima in the comments on that commit, it could be nice for some use cases to have the chance to include the diff in the commit message.

Leaving out things like file name, and truncating it to the standard 80-char max length of git "short" commit messages, that should go neatly with changes that usually only change one file.

The option might also catch the case of multiple files having been changed and not including the actual diff in that case but instead something like "Multiple files changed, diff omitted."

Having warning in usage about .gitignore in big folders will be ncie to have

I tried (with some success) to use this script for backing up settings and projects created by Cinelerra-GG (Linux non-linear video editor). Settings were all small and easy to put in git.

But when I tried to use gitwatch on big folder with both projects (*.xml) and media files (big mp4s) it tried by default to check in everything (obviously ...if you are git user). I put gitignore in my folder(s) and now it behave nicely.

Still, I think few words about such situation in help text we see when we run script w/o any arguments will be nice to have.

Exclude swap files

The title is self-explanatory : I'd like to be able to exclude swap files from push, because it makes a lot of unwanted commits.

I tried adding

--exclude="^${TARGETDIR}/*.swp"

or changing to

--exclude="^${TARGETDIR}/.git|^${TARGETDIR}/.swp"

But it doesn't seem to work, maybe the regexp is wrong?

it just hangs on me

I tried several things I will show one of them,

I have a folder that made a git inside so:

cd gitfolder
git init
git add .
git commit

then I did gitwatch gitfolder
and it just hangs there and any changes I do does get commited!

any guidance or is this project dead?

add separate working dir support

i was writing similar script like you have, and was thinking what to name it, so i found your tool instead :)

however, i intended to use separate .git dir from monitored dir: http://stackoverflow.com/a/3987863
as my code rsynced data from source dir to work dir using --exlude patterns, and doing git add -A . and git commit.

and with that pattern, the .git dir would be deleted with each rsync call.

so i was thinking maybe you want to add also such behaviour, having .git dir elsewhere and have support of some kind of blacklisting what files to track.

Bidirectional sync support

This tool seems to to half of what I'm currently looking for: I want to keep a folder and a git repository sync and accept changes vice-versa.

So what I miss is a polling of a remote repository, pulling changes, merging changes besides pushing any local updates back to upstream.

Any plans for this?

Missing: How to Exclude Files

Hi!

I wonder how I can exclude certain files to get committed which are already part of .gitignore.

The Readme does not mention anything like this and I don't want to patch gitwatch.sh to exclude my files hardcoded.

Command line parameters or just silently taking .gitignore into account would be very helpful.

Open to adding a delay option?

This might sound crazy, and it might increase the complexity of the script, so I can completely understand if your answer is no.

I'm looking for an auto commit option but only after a file has been untouched for maybe 30 minutes.

Why? My workflow is that I manage some notebooks in git. I usually commit and manually push them. Sometimes I write meaningful commit messages. But, and here's the kicker, sometimes I forget. In the case where I forget to commit and push, I want the scrip to kick in.

I'm thinking to write my own script for this, but of course if I could use an existing script that would make my life a lot easier! :-)

gitwatch consumes a lot of /dev/pts

We started noticing issues related to /dev/pts consumption. Which results in users not being able to launch new shell.

Users reported that shell is not created when they ssh into devserver:

> ssh devpod
...
Pushed a login request to your device...
Success. Logging you in...
PTY allocation request failed on channel 0
^C%                                                                                                                                                                                                                                                                                                                                                                                   Time: 31

Also vscode remote fails to start new shell:

The terminal process failed to launch: A native exception occurred during launch (forkpty(3) failed.).

We did a little investigation and it found that gitwatch forks a lot and each fork creates a new dev/pts/X:

user:~$ lsof /dev/pts/*
COMMAND      PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gitwatch  861529 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
gitwatch  861529 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
gitwatch  861529 user   30u   CHR  136,7      0t0   10 /dev/pts/7
gitwatch  861529 user   35u   CHR    5,2      0t0    2 /dev/pts/ptmx
gitwatch  861529 user   37u   CHR  136,4      0t0    7 /dev/pts/4
gitwatch  861529 user   44u   CHR    5,2      0t0    2 /dev/pts/ptmx
gitwatch  861529 user   45u   CHR 136,11      0t0   14 /dev/pts/11
git.real  960591 user    0u   CHR  136,7      0t0   10 /dev/pts/7
git.real  960591 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real  960591 user   23u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real  960591 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
less      960592 user    1u   CHR  136,7      0t0   10 /dev/pts/7
less      960592 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
less      960592 user   23u   CHR    5,2      0t0    2 /dev/pts/ptmx
less      960592 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1024979 user    0u   CHR  136,4      0t0    7 /dev/pts/4
git.real 1024979 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1024979 user   23u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1024979 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1024979 user   35u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1024979 user   78u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1024980 user    1u   CHR  136,4      0t0    7 /dev/pts/4
less     1024980 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1024980 user   23u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1024980 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1024980 user   35u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1024980 user   78u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user    0u   CHR 136,11      0t0   14 /dev/pts/11
git.real 1069330 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user   24u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user   35u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user   36u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user   44u   CHR    5,2      0t0    2 /dev/pts/ptmx
git.real 1069330 user   86u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user    1u   CHR 136,11      0t0   14 /dev/pts/11
less     1069331 user   22u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user   24u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user   29u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user   35u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user   36u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user   44u   CHR    5,2      0t0    2 /dev/pts/ptmx
less     1069331 user   86u   CHR    5,2      0t0    2 /dev/pts/ptmx
bash     1563497 user    0u   CHR  136,0      0t0    3 /dev/pts/0
bash     1563497 user    1u   CHR  136,0      0t0    3 /dev/pts/0
bash     1563497 user    2u   CHR  136,0      0t0    3 /dev/pts/0
bash     1563497 user  255u   CHR  136,0      0t0    3 /dev/pts/0
lsof     1575069 user    0u   CHR  136,0      0t0    3 /dev/pts/0
lsof     1575069 user    1u   CHR  136,0      0t0    3 /dev/pts/0
lsof     1575069 user    2u   CHR  136,0      0t0    3 /dev/pts/0

Is there solution to mitigate this? I've read in #76 that you had single process implementation, is it still maintained?

Fix inotifywait usage to use one process, not re-create new ones all the time

Gitwatch currently spawns a new inotifywait process every time it waits for changes, not making use of the command's "continuous" option. This might cause an unnecessary amount of load when big folders (i.e. with many files) are watched recursively, because when inotifywait starts, it needs to establish inode watchers for each file in the watched scope.

A more efficient way to do it might be to launch one inotifywait process with the continuous option, and pipe its output into the script as demonstrated by @datag in datag/confcan@bcff79b, specifically on lines 76 through 95

Fix exclusion regex git files & directories

When I try to add files which filename starts with .git or git inotifywait does not work.

Environment

$uname -r
5.3.0-46-generic
$cat /etc/issue
Ubuntu 18.04.3 LTS \n \l
$inotifywait --help|head -1
inotifywait 3.14

Test 1(current exclusion regex)

$mkdir /tmp/inwtest
$inotifywait -qmr -e close_write,move,delete,create --exclude .git /tmp/inwtest &
$mkdir /tmp/inwtest/.git
$touch /tmp/inwtest/.git/file
$touch /tmp/inwtest/{gitwatch.sh,.gitignore}
#no output

Test 2(proposed exclusion regex)

$mkdir /tmp/inwtest
$inotifywait -qmr -e close_write,move,delete,create --exclude '/.*/(\.git/|\.git$)' /tmp/inwtest &
$mkdir /tmp/inwtest/.git
$touch /tmp/inwtest/.git/file
$touch /tmp/inwtest/{gitwatch.sh,.gitignore}
/tmp/inwtest/ CREATE gitwatch.sh
/tmp/inwtest/ CLOSE_WRITE,CLOSE gitwatch.sh
/tmp/inwtest/ CREATE .gitignore
/tmp/inwtest/ CLOSE_WRITE,CLOSE .gitignore

Add `dirname` and `basename` functions (util)

As @datag pointed out in #11, it's neat to use bash builtins to reformat the paths, instead of the external commands dirname and basename.

However, the bash builtin code for these transformations is rather ugly, so they should be placed in so-named functions.

Additionally, the implementation of dirname @datag first suggested does not cover all cases of input strings, sometimes wrongly returning empty string, so that also needs to be figured out.

Consider adding GitHub topics?

I found this repo through this post although I did try searching GitHub for scripts like this. I wonder if you'd be open to adding some GitHub topics to the repo? Maybe git, autocommit, something else? Might help other folks find the repo more easily. 🧡

Fix -b switch to affect which remote branch is used -- local should always be active

The -b switch currently produces a push line like git push <remote> <branch>. This is rather pointless, since commits will always be made to the active (checked out) branch.

The behaviour of the switch should thus be modified to affect the remote branch only, i.e. git push <remote> <active branch>:<branch> where <active branch> is filled in automatically by the script.

Plan to make releases?

Any plan to make 'releases' of gitwatch? This would allow people to subscribe to be notified when a new release is available, since updating seems to be a manual system currently...

Suggestion

You should make for the users can download git file when it changes

Not all relevant events are detected

Asking inotifywait without event create does not detect directory creation and none of the files created within it (at least on my system (which uses inotify-tools-3.13).

Also, you may add the event move_self (or just move to get to/from) to detect files moved out of the watched directory. E.g., watched directory is /foo/ and you move file /foo/bar into /tmp/.

Deletion of gitwatch folder at ~/

Great tool! Once I have installed the tool, can I delete the ~/gitwatch folder? I suppose the tool at /usr/local/bin/ is all what is needed. Sorry for the newbie question. Thanks!

Add possibility to `git repack` after a certain number of commits

Depending on the use-case, there might be relatively many commits happening with many changes that blow up the repo quite a bit. A git repack -ad (and possibly other switches) will help here, making use of delta compression by looking at the blobs in the history as one big thing, and not just adding new hunks as they come in.

This could be done with a cronjob, but sometimes it might be convenient to just have the gitwatch script itself do the repack after every so many commits.

This feature should be implemented with a command-line switch and an optional number of commits after which will be repacked.

Script stops checking after several hours

Hi.

I have git watch watch a directory that doesn't get much usage, maybe every few days a new file will be placed in that directory. I have found that after about a day or so git watch and inotifywait are still running but any new files don't get picked up. I have to kill the process and restart, and even then any added files don't get added until the next file is added.

Add "verbose" switch

Add a -v switch that makes the script act verbosely (mostly used for debugging of course), outputting things like which push remote and branch were selected (if any), if the target is recognized as a file or folder, etc.

Too many commits?

When the “remote” option is set, is there a possibility that GitHub & friends (GitLab etc.) might not like the large rate of commits happening? I use this for documents and whenever I’m working on and I can easily reach 100 or more commits in one day, some in quick succession. Is there some sort of cap or limit to pushes or is it all fine?
This might be a stupid question, but i’d just like to be sure, because I don’t think normal software development reaches these levels (at least per individual).
Thanks. Great tool by the way!

git add -u

Perhaps it is ideal to add in a

git add -u

so that the system will also automatically delete files as well as add them.

Unable to run gitwatch as a service (on aws bitnami instance)

I am able to run gitwatch in background when terminal is open and when i close it gitwatch getting stopped and i am not sure to make it work, i tried the steps given for ubuntu systemd, but its giving me the following error,

bitnami@ip-*-*-*-*:/usr/bin$ mkdir -p "$HOME/.config/systemd/user" && cp [email protected] $HOME/.config/systemd/user
cp: cannot stat '[email protected]': No such file or directory

any thoughts and suggestions will be much appreciated.

Outstanding Pull Requests

Hi there,

It looks like there are a lot of outstanding pull requests. Is it possible to merge them where appropriate? It would be great to get a "master" version of this project with all the changes in it.

Spaces in paths aren't supported

Running gitwatch on a path with spaces in it breaks the script.

Example:

$ pwd
/home/theuser/some directory
$ gitwatch file.txt
/home/theuser/bin/gitwatch.sh: line 153: cd: /home/theuser/some: No such file or directory
Couldn't watch /home/theuser/some: No such file or directory
/home/gustav/bin/gitwatch: line 178: cd: /home/theuser/some: No such file or directory
fatal: /home/theuser/some: '/home/theuser/some' is outside repository
...

Then follows an endless loop of failed watches and adds.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.