Skip to content

Commit

Permalink
Merge remote-tracking branch 'davidtwco/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ev0rtex committed Feb 11, 2018
2 parents ca02c48 + 8d6d341 commit 00acbb2
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions base/utils/git.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ __zplug::utils::git::checkout()
local repo="$1"
local -a do_not_checkout
local -A tags
local lock_name

tags[at]="$(__zplug::core::core::run_interfaces 'at' "$repo")"
tags[dir]="$(__zplug::core::core::run_interfaces 'dir' "$repo")"
Expand Down Expand Up @@ -116,20 +115,25 @@ __zplug::utils::git::checkout()
return 0
fi

lock_name="${(j:/:)${(s:/:)tags[dir]}[-2, -1]}"
if (( $_zplug_checkout_locks[(I)${lock_name}] )); then
# Check if the repository is already checked out
# with the branch we are looking for.
if __zplug::utils::git::have_checked_out "$tags[at]"; then
return 0
fi

# Acquire lock
_zplug_checkout_locks+=( $lock_name )
# Check if the repo is already locked by another process, and
# pretend to return success. This happens most likely to oh-my-zsh
# where multiple plugins refer to the same repo, and only one
# checkout is needed for that repo. The original variable-based
# lock would not work because parallel checkout commands run in
# multiple sub processes and they cannot share variables.
if __zplug::utils::git::is_git_locked "$tags[dir]"; then
return 0
fi

git checkout -q "$tags[at]" \
2> >(__zplug::log::capture::error) >/dev/null

# Release lock
_zplug_checkout_locks=( ${_zplug_checkout_lock:#${lock_name}} )

if (( $status != 0 )); then
__zplug::io::print::f \
--die \
Expand All @@ -146,6 +150,16 @@ __zplug::utils::git::have_cloned()
[[ "$(git rev-parse HEAD 2>/dev/null)" != "HEAD" ]]
}

__zplug::utils::git::have_checked_out()
{
[[ "$(git rev-parse --abbrev-ref HEAD)" == "$1" ]]
}

__zplug::utils::git::is_git_locked()
{
[[ -e "$1/.git/index.lock" || -e "$1/.git/HEAD.lock" ]]
}

# TODO:
# - __zplug::utils::git::fetch
# - __zplug::utils::git::pull
Expand Down

0 comments on commit 00acbb2

Please sign in to comment.