git-repo-watcher开源项目

我要开发同款
匿名用户2021年11月09日
22阅读
开发技术SHELL
所属分类终端/远程登录、应用工具
授权协议MIT License

作品详情

GitRepoWatcher

Asimplebashscripttowatchagitrepositoryandpullupstreamchangesifavailable.

RequirementsBashwithVersion>3TestedonUbuntu,Debian,MacOS,WindowsGitShell,WindowsSubsystemforLinux(WSL)

Basically,itwillworkanywhereyoucaninstallBash.

Ifsomethingdoesn'twork,pleaseletmeknow.

Usage

Youonlyneedthepathtoyourgitrepositorytostart.

Thiswillstartawatcherthatlooksforchangesevery10seconds:

./git-repo-watcher-d"/path/to/your/repository"

Thetimeintervalcanbechangedbypassingitto-i:

./git-repo-watcher-d"/path/to/your/repository"-i60#seconds

Makesureyourlocalrepositoryistrackingaremotebranch,otherwisethescriptwillfail.

Customizations

Youcanaddyourownlogictothefile: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"Privaterepositories

Thescriptworkswithprivaterepositories.

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"&disownWindows10

TheeasiestwayistoinstallGitShell,whichalsocomeswithbash.Theonlythingyouhavetoconsiderarethefileseparators.TheUnixformatshouldbeusedhere:

C:\YourGitRepository→/C/YourGitRepository

ItisalittlemoredifficultwithWSL.ThismustfirstbeinstalledandconfiguredviatheWindowsStore.Thefilestructureisalsoslightlydifferent:

C:\YourGitRepository→/mnt/c/YourGitRepository

Tests

Thetestsuitegit-repo-watcher-testsisusingthetestframeworkshunit2,itwillbedownloadedautomaticallytoyour/tmpfolder.Thescripthasnootherdependenciesandrequiresnointernetconnection.

Thetestscreateseveraltestgitrepositoriesinthefolder:/tmp/git-repo-watcher.

Agitusershouldbeconfigured,otherwisethetestswillfail.Withthefollowinglineyoucancheckifthisisthecase:

gitconfig--list

Youcanconfigureitasfollows:

gitconfig--globaluser.email"your@email.com"gitconfig--globaluser.name"YourName"
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论