-
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.
The command replaces the existing `pull` command. In addition to existing logic, it allows - checkouting of remote branches - using pattern matching for branches allocation `43` error code is introduced to handle logical constraints. #10
- Loading branch information
Showing
12 changed files
with
120 additions
and
43 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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
--up-to-one-branch(){ | ||
local BRANCHES=(${@}) | ||
if [[ ${#BRANCHES[@]} > 1 ]]; then | ||
echo "The following branches are found:" | ||
for branch in ${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 | ||
fi | ||
fi | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env bats | ||
|
||
load addons-common | ||
load addons-fake | ||
|
||
teardown() { | ||
clean-fake | ||
} | ||
|
||
@test "'obtain-work': raise 45 error if branch name pattern in not set" { | ||
check git-elegant obtain-work | ||
[[ "$status" -eq 45 ]] | ||
[[ "${lines[@]}" =~ "Please provide a branch name or its part." ]] | ||
} | ||
|
||
@test "'obtain-work': use found local branch when given pattern matches only one local branch" { | ||
fake-pass git "for-each-ref --format='%(refname:strip=2)' refs/heads/*" "master\nfoo" | ||
fake-pass git "checkout foo" | ||
fake-pass git pull | ||
|
||
check git-elegant obtain-work fo | ||
[[ "$status" -eq 0 ]] | ||
} | ||
|
||
@test "'obtain-work': raise 43 error when given pattern matches several local branches" { | ||
fake-pass git "for-each-ref --format='%(refname:strip=2)' refs/heads/*" "master\nfoo\nfo2\nfo3" | ||
|
||
check git-elegant obtain-work fo | ||
[[ "$status" -eq 43 ]] | ||
[[ "${lines[@]}" =~ "Please re-run the command with concrete branch name from the list above!" ]] | ||
} | ||
|
||
@test "'obtain-work': use found remote branch when given pattern matches only one remote branch" { | ||
fake-pass git "for-each-ref --format='%(refname:strip=2)' refs/heads/*" | ||
fake-pass git "fetch --all" | ||
fake-pass git "for-each-ref --format='%(refname:strip=3)' refs/remotes/**" "rremote\nmaster" | ||
fake-pass git "checkout rremote" | ||
|
||
check git-elegant obtain-work rr | ||
[[ "$status" -eq 0 ]] | ||
} | ||
|
||
@test "'obtain-work': raise 43 error when given pattern matches several remote branches" { | ||
fake-pass git "for-each-ref --format='%(refname:strip=2)' refs/heads/*" | ||
fake-pass git "fetch --all" | ||
fake-pass git "for-each-ref --format='%(refname:strip=3)' refs/remotes/**" "rremote\nmaster\nbarr" | ||
|
||
check git-elegant obtain-work rr | ||
[[ "$status" -eq 43 ]] | ||
[[ "${lines[@]}" =~ "Please re-run the command with concrete branch name from the list above!" ]] | ||
} | ||
|
||
@test "'obtain-work': raise 43 error when given pattern matches zero remote branches" { | ||
fake-pass git "for-each-ref --format='%(refname:strip=2)' refs/heads/*" | ||
fake-pass git "fetch --all" | ||
fake-pass git "for-each-ref --format='%(refname:strip=3)' refs/remotes/**" "rremote\nmaster\nbarr" | ||
|
||
check git-elegant obtain-work aa | ||
[[ "$status" -eq 43 ]] | ||
[[ "${lines[@]}" =~ "There are no either remove or local branches which match 'aa' pattern." ]] | ||
} |
This file was deleted.
Oops, something went wrong.
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