simonthum / git-sync

Safe and simple one-script git synchronization
773 stars 99 forks source link

git-sync-on-inotify can let certain changes slip through #23

Closed Dieterbe closed 2 years ago

Dieterbe commented 2 years ago

1) notifywait prints the first file modified (example : touch foo.1 foo.2, $changedFile will be "foo.1") so if you write to multiple files simultaneously, if the first file is in .gitignore, the git-sync will be skipped and the change to the other (non ignored files) will be "forgotten about". 2) any changes that happen in between two calls of notifywait (e.g. while GIT_SYNC_COMMAND is running, or while the ignore check is running) are unnoticed and "forgotten about"

the first issue can be solved by running inotifywait -m and processing all events - or leaving the gitignore related work up to GIT_SYNC_COMMAND.

the second can be solved by running inotifywait without a timeout, so it catches everything, and concurrently - in another thread - implement the timeout (e.g. with a sleep) to periodically trigger the sync. But I'm not sure how to do this all in bash in a way that we don't concurrently run two syncs (one due to an inotifywait event and one due to a timeout), doing this in something like Go would make more sense... maybe we should just document the shortcomings for the bash version, and defer to another program for more advanced/fewer edge cases. I'm sure they exist but i'll need to search around a bit.

Dieterbe commented 2 years ago

maybe we should just document the shortcomings for the bash version, and defer to another program for more advanced/fewer edge cases. I'm sure they exist but i'll need to search around a bit.

https://github.com/cortesi/modd seems to work well in my tests, and in particular seems to handle both of the above cases as expected. I use this modd.conf:

** +noignore {
    prep: /home/dieter/scripts/git-sync
}
simonthum commented 2 years ago

Hi, nice catch! I guess the shortcomings should be addressed and documented, maybe @IvanMalison can whip something up?

I think most - but not all - cases could be catched by adding e.g. a one second delay before git scans for changes. What do you think?

simonthum commented 2 years ago

To close this I propose to move both solutions to a new /contrib directory. If there are any concerns please speak up.

Dieterbe commented 2 years ago

I don't think a delay will fix this. I recommend documenting the shortcomings until there is a fix. I don't plan to work on this as I switched to modd.

simonthum commented 2 years ago

Yes, I'll document the shortcomings and move. Is your modd.conf still valid and are you OK with putting it under contrib?

simonthum commented 2 years ago

I pushed the move to contrib/, please have a look.

As an aside, I think git-sync-on-inotify with GIT_SYNC_INTERVAL will be OK and in some cases better. I have documented the state of affairs so users can make an informed choice.

simonthum commented 2 years ago

@IvanMalison you might also want to have a look!

Dieterbe commented 2 years ago

Is your modd.conf still valid and are you OK with putting it under contrib?

yeah i still use the same config as i shared earlier. works fine for me. cheers!

simonthum commented 2 years ago

Thanks for letting me know! BTW I dropped the noignore as it was a bit of a foggy option to me.