Commit f71e897ffae3529fa7a71f7ce3ed071288fd1975
1 parent
290edb0058
Apply DRY principles in git invocations
Showing 1 changed file with 6 additions and 10 deletions Side-by-side Diff
antigen.zsh
... | ... | @@ -181,33 +181,29 @@ antigen-update () { |
181 | 181 | # Get the clone's directory as per the given repo url and branch. |
182 | 182 | local url="$1" |
183 | 183 | local clone_dir="$(-antigen-get-clone-dir $url)" |
184 | + Git () { eval git --git-dir=$clone_dir/.git --work-tree=$clone_dir "$@" } | |
184 | 185 | |
185 | 186 | # Clone if it doesn't already exist. |
186 | 187 | if [[ ! -d $clone_dir ]]; then |
187 | 188 | git clone "${url%|*}" "$clone_dir" |
188 | 189 | elif $update; then |
189 | 190 | # Save current revision. |
190 | - old_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | |
191 | - rev-parse HEAD)" | |
191 | + old_rev="$(Git rev-parse HEAD)" | |
192 | 192 | # Pull changes if update requested. |
193 | - git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | |
194 | - pull | |
193 | + Git pull | |
195 | 194 | # Get the new revision. |
196 | - new_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | |
197 | - rev-parse HEAD)" | |
195 | + new_rev="$(Git rev-parse HEAD)" | |
198 | 196 | fi |
199 | 197 | |
200 | 198 | # If its a specific branch that we want, checkout that branch. |
201 | 199 | if [[ $url == *\|* ]]; then |
202 | - git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | |
203 | - checkout "${url#*|}" | |
200 | + Git checkout "${url#*|}" | |
204 | 201 | fi |
205 | 202 | |
206 | 203 | if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then |
207 | 204 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. |
208 | 205 | if $verbose; then |
209 | - git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | |
210 | - log --oneline --reverse --no-merges --stat '@{1}..' | |
206 | + Git log --oneline --reverse --no-merges --stat '@{1}..' | |
211 | 207 | fi |
212 | 208 | fi |
213 | 209 |