-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a full or partial branch name when run
accept-work
Now `accept-work` can use either full or partial branch name. It's because `obtain-work` is used as a checkout mechanism for the given name. This update has changed the previous implementation of `obtain-work`: 1. It works with remote branches only. 2. A local branch name is configurable. #173
- Loading branch information
Showing
6 changed files
with
51 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
--up-to-one-branch(){ | ||
local BRANCHES=(${@}) | ||
if [[ ${#BRANCHES[@]} > 1 ]]; then | ||
default() { | ||
local PATTERN=${1} | ||
_error-if-empty "${PATTERN}" "Please provide a branch name or its part." | ||
boxtee git fetch --all | ||
local REMOTE_BRANCHES=( | ||
$(git for-each-ref --format='%(refname:strip=2)' refs/remotes/** | grep "${PATTERN}") | ||
) | ||
if [[ ${#REMOTE_BRANCHES[@]} > 1 ]]; then | ||
echo "The following branches are found:" | ||
for branch in ${BRANCHES[@]}; do | ||
for branch in ${REMOTE_BRANCHES[@]}; do | ||
echo " - ${branch}" | ||
done | ||
box "Please re-run the command with concrete branch name from the list above!" | ||
exit 43 | ||
fi | ||
} | ||
|
||
default() { | ||
local PATTERN=${1} | ||
_error-if-empty "${PATTERN}" "Please provide a branch name or its part." | ||
local LOCAL_BRANCHES=($(git for-each-ref --format='%(refname:strip=2)' refs/heads/* | grep "${PATTERN}")) | ||
--up-to-one-branch ${LOCAL_BRANCHES[@]} | ||
if [[ ${#LOCAL_BRANCHES[@]} = 1 ]]; then | ||
boxtee git checkout ${LOCAL_BRANCHES[0]} | ||
boxtee git pull | ||
else | ||
boxtee git fetch --all | ||
local REMOTE_BRANCHES=($(git for-each-ref --format='%(refname:strip=3)' refs/remotes/** | grep "${PATTERN}")) | ||
--up-to-one-branch ${REMOTE_BRANCHES[@]} | ||
if [[ ${#REMOTE_BRANCHES[@]} = 1 ]]; then | ||
boxtee git checkout ${REMOTE_BRANCHES[0]} | ||
else | ||
box "There are no either remove or local branches which match '${PATTERN}' pattern." | ||
exit 43 | ||
if [[ ${#REMOTE_BRANCHES[@]} = 1 ]]; then | ||
local REMOTE=${REMOTE_BRANCHES[0]} | ||
local LOCAL=${2} | ||
if [[ -z ${LOCAL} ]]; then | ||
LOCAL=$(branch-from-remote-reference ${REMOTE}) | ||
fi | ||
boxtee git checkout -B ${LOCAL} ${REMOTE} | ||
else | ||
box "There is no branch that matches the '${PATTERN}' pattern." | ||
exit 43 | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters