25fcf0c265c682f092ce49a6849e5e09b38dffa9

Author
slavaGanzin <slava.ganzin@gmail.com>
Committer
slavaGanzin <slava.ganzin@gmail.com>
Date

Message

git-auto-fetch: README.md

Diff

 1diff --git a/plugins/git-auto-fetch/README.md b/plugins/git-auto-fetch/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..7f5eac49d8257d16a5d7c61df4239930da9b81a1
 4--- /dev/null
 5+++ b/plugins/git-auto-fetch/README.md
 6@@ -0,0 +1,22 @@
 7+# Git auto fetch
 8+
 9+Automatically fetches all changes from all remotes every time you cd into yout git-initialized project.
10+
11+####Usage
12+Add ```git-auto-fetch``` to the plugins array in your zshrc file:
13+```shell
14+plugins=(... git-auto-fetch)
15+```
16+
17+Every time you change directory to your git project all remotes will be fetched in background. Log of ```git fetch --all``` will be saved into .git/FETCH_LOG
18+
19+####Toggle auto fetch per folder
20+If you are using mobile connection or for any other reason you can disable git-auto-fetch for any folder:
21+
22+```shell
23+$ cd to/your/project
24+$ git-auto-fetch
25+disabled
26+$ git-auto-fetch
27+enabled
28+```
29diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
30index cbf6984a0b7afec461eeb881ca7399a4454229d9..87535b251c28568c715ee598d7f2a41d85f9f791 100644
31--- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
32+++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
33@@ -1,5 +1,15 @@
34 function git_fetch_on_chpwd {
35-  ([[ -d .git ]] && git fetch --all &>! ./.git/FETCH_LOG &)
36+  ([[ -d .git ]] && [[ ! -f ".git/NO_AUTO_FETCH" ]] && git fetch --all &>! .git/FETCH_LOG &)
37+}
38+
39+function git-auto-fetch {
40+  [[ ! -d .git ]] && return
41+  if [[ -f ".git/NO_AUTO_FETCH" ]]; then
42+    rm ".git/NO_AUTO_FETCH" && echo "disabled"
43+  else
44+    touch ".git/NO_AUTO_FETCH" && echo "enabled"
45+  fi
46 }
47 chpwd_functions+=(git_fetch_on_chpwd)
48 git_fetch_on_chpwd
49+unset git_fetch_on_chpwd