Asimplebashscripttowatchagitrepositoryandpullupstreamchangesifavailable.
RequirementsBashwithVersion>3TestedonUbuntu,Debian,MacOS,WindowsGitShell,WindowsSubsystemforLinux(WSL)Basically,itwillworkanywhereyoucaninstallBash.
Ifsomethingdoesn'twork,pleaseletmeknow.
UsageYouonlyneedthepathtoyourgitrepositorytostart.
Thiswillstartawatcherthatlooksforchangesevery10seconds:
./git-repo-watcher-d"/path/to/your/repository"Thetimeintervalcanbechangedbypassingitto-i:
./git-repo-watcher-d"/path/to/your/repository"-i60#secondsMakesureyourlocalrepositoryistrackingaremotebranch,otherwisethescriptwillfail.
CustomizationsYoucanaddyourownlogictothefile:git-repo-watcher-hooks
Forexample,youcanstartyourbuildprocessincaseofchanges:
#$1-Gitrepositoryname#$2-Branchname#$3-Commitdetailschange_pulled(){echo"Startingbuildforcommit:$@"./your-build-script.sh}Ifyouhavemorethanonerepositoryyoucanpassacopyofthegit-repo-watcher-hooksfilelikeso:
./git-repo-watcher-d"/path/to/your/repository"-h"/path/to/your/hooks-file"PrivaterepositoriesThescriptworkswithprivaterepositories.
Firstconfigureapasswordcachewithgitconfig--globalcredential.helper"cache--timeout=60".Makesurethetimeoutisgreaterthanthetimeintervalgiventothescript.Botharegivenasseconds.Theprogramwillexecutegitfetchandaskforyourlogindata.Thescriptitselfdoesnotstorepasswords!
Ifyouwantittoruninthebackgroundasadaemonprocess,youhavetoexecutegitfetchbeforehand.
Examplecode:
cd"/path/to/your/repository"gitconfig--globalcredential.helper"cache--timeout=60"gitfetch#Checkingexitcodeif[[$?-eq1]];thenecho"Wrongpassword!">&2exit1fi#Disownprocess./git-repo-watcher-d"/path/to/your/repository">"/path/to/your/logfile.log"&disownWindows10TheeasiestwayistoinstallGitShell,whichalsocomeswithbash.Theonlythingyouhavetoconsiderarethefileseparators.TheUnixformatshouldbeusedhere:
C:\YourGitRepository→/C/YourGitRepository
ItisalittlemoredifficultwithWSL.ThismustfirstbeinstalledandconfiguredviatheWindowsStore.Thefilestructureisalsoslightlydifferent:
C:\YourGitRepository→/mnt/c/YourGitRepository
TestsThetestsuitegit-repo-watcher-testsisusingthetestframeworkshunit2,itwillbedownloadedautomaticallytoyour/tmpfolder.Thescripthasnootherdependenciesandrequiresnointernetconnection.
Thetestscreateseveraltestgitrepositoriesinthefolder:/tmp/git-repo-watcher.
Agitusershouldbeconfigured,otherwisethetestswillfail.Withthefollowinglineyoucancheckifthisisthecase:
gitconfig--listYoucanconfigureitasfollows:
gitconfig--globaluser.email"your@email.com"gitconfig--globaluser.name"YourName"
评论