Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6417d76
SC2148 - shebang
leventyalcin Jul 22, 2019
3c20de7
SC2034: remove unused var, SC1090: ignore
leventyalcin Jul 22, 2019
be541bd
SC2086: double-quote
leventyalcin Jul 22, 2019
fb04d93
SC2236: -n instead ! -z
leventyalcin Jul 22, 2019
326588a
SC2181: if-cmd
leventyalcin Jul 22, 2019
5c9eb9e
SC2016:disable, due to no need to expand and more readable with this way
leventyalcin Jul 22, 2019
51d2a12
SC2001, SC2181
leventyalcin Jul 22, 2019
b6a8e4e
SC2086: double-qoute
leventyalcin Jul 22, 2019
0486b7e
SC2236: Use -n instead of ! -z.
leventyalcin Jul 22, 2019
7a33f9c
SC2086: weird one
leventyalcin Jul 22, 2019
7f5f252
SC2236: Use -n instead of ! -z
leventyalcin Jul 22, 2019
eb046ef
SC2086: Double-quote
leventyalcin Jul 22, 2019
924d255
SC2155: Declare and assign separately, SC2162: read with -r
leventyalcin Jul 22, 2019
754b0d7
SC2155: Declare and assign separately, SC2162: read with -r
leventyalcin Jul 22, 2019
b1ecdde
SC2236, SC2155, SC2162
leventyalcin Jul 22, 2019
8df50aa
SC2236, SC2155, SC2162
leventyalcin Jul 22, 2019
e6a5076
SC2236, SC2155, SC2162
leventyalcin Jul 22, 2019
0d1fd4f
SC2236, SC2155, SC2162
leventyalcin Jul 22, 2019
0a44864
SC2236, SC2155, SC2162
leventyalcin Jul 22, 2019
17cca4c
SC2236, SC2155, SC2162
leventyalcin Jul 22, 2019
31319af
shebang fix
leventyalcin Jul 22, 2019
d5a076f
shebang
leventyalcin Jul 22, 2019
dbff250
SC2236, SC2086
leventyalcin Jul 22, 2019
dd7ca27
SC2086
leventyalcin Jul 22, 2019
63a1a3d
SC2155, SC2086
leventyalcin Jul 22, 2019
8663d9c
SC2086
leventyalcin Jul 22, 2019
97aeeae
SC2155: Declare and assign separately
leventyalcin Jul 22, 2019
33c8529
SC2236, SC2155
leventyalcin Jul 22, 2019
21b91a6
SC2119
leventyalcin Jul 22, 2019
75178c0
SC2181: ignore in here
leventyalcin Jul 22, 2019
c3753c1
SC2086
leventyalcin Jul 22, 2019
815c5eb
SC2148
leventyalcin Jul 22, 2019
8a4eb85
SC2181
leventyalcin Jul 22, 2019
e53cb6e
SC2236: Use -n instead of ! -z.
leventyalcin Jul 22, 2019
4d3de83
SC2236: Use -n instead of ! -z.
leventyalcin Jul 22, 2019
cfd0558
SC2236: Use -n instead of ! -z.
leventyalcin Jul 22, 2019
eb4a85f
SC2034: get_opts appears unused., SC2155: Declare and assign separately
leventyalcin Jul 22, 2019
23de2f4
SC2236: Use -n instead of ! -z.
leventyalcin Jul 22, 2019
68f9360
SC2236: Use -n instead of ! -z.
leventyalcin Jul 22, 2019
b386e70
SC2034: tf var appears unused, SC2086: Double quote
leventyalcin Jul 22, 2019
00bb1b5
run shellcheck tests
leventyalcin Jul 22, 2019
2f500c4
install latest shellcheck
leventyalcin Jul 22, 2019
eff28f4
no need for $ in c-like expressions
leventyalcin Jul 23, 2019
fdfbcd6
disable SC2059 due to format should be templated to calculateindentation
leventyalcin Jul 23, 2019
8e28373
SC2120 in git.functions
leventyalcin Jul 24, 2019
cfeada4
t_str_to_safe_chars was failing due to quotation mistake, so disabled…
leventyalcin Jul 24, 2019
dd5cd20
I've got the idea wrong, so fixed now
leventyalcin Jul 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions bash/habitual/git.functions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# vim: et sr sw=4 ts=4 smartindent syntax=sh:
#
# @overview
Expand All @@ -18,7 +19,7 @@ GIT_SHA_LEN=${GIT_SHA_LEN:-8}
# __cd() - if user passed a path, cd to it.
__cd() {
local d="$1"
[[ ! -z "$d" ]] && ! cd $d 2>/dev/null && red_e "couldn't cd to $d" && return 1;
[[ -n "$d" ]] && ! cd "$d" 2>/dev/null && red_e "couldn't cd to $d" && return 1;
return 0
}

Expand All @@ -43,7 +44,7 @@ git_repo() {

# @desc Prints sha of current commit - up to $GIT\_SHA\_LEN chars.
git_sha() {
${GIT} rev-parse --short=${GIT_SHA_LEN} --verify HEAD
${GIT} rev-parse --short="$GIT_SHA_LEN" --verify HEAD
}

# @desc Prints out the git-tag on the current commit (exact match only)
Expand All @@ -67,10 +68,12 @@ git_email() {
# @desc Prints user.name user.email (from git config)
# Returns 1 if user.name not set.
git_id() {
local u=$(git_user)
local e=$(git_email)
local u="" e=""

u=$(git_user)
e=$(git_email)
[[ -z "$u" ]] && echo "" && return 1
echo $u $e
echo "$u" "$e"
}

# @desc Outputs a str formed of repo, sha1, tag and branch info.
Expand All @@ -91,8 +94,13 @@ git_info_str() {
local branch="" repo="" sha="" tag=""

(
__cd $d || exit 1
! in_git_clone && e "can't get git info for $(pwd) - not a git dir" && return 1
__cd "$d" || exit 1
# No need to call `cd` by sending $d in here for sure,
# but, shellcheck complains about SC2120 if you never
# call the function with an argument.
# It thinks you're confused about script's $1 and
# functions $1. So, no harm in this
! in_git_clone "$d" && e "can't get git info for $(pwd) - not a git dir" && return 1

repo="$(git_repo)"
sha="$(git_sha)"
Expand Down Expand Up @@ -143,13 +151,20 @@ git_vars() {
! in_git_clone && e "... $PWD is not inside a git repo" && return 1

GIT_BRANCH="$(git_branch)" || return 1 ; export GIT_BRANCH
export GIT_TAG="$(git_tag)"
export GIT_REPO="$(git_repo)"
export GIT_SHA="$(git_sha)"
export GIT_USER="$(git_user)"
export GIT_EMAIL="$(git_email)"
export GIT_ID="$(git_id)" # git user and email, space separated
export GIT_INFO=$(_git_info_str "$GIT_REPO" "$GIT_SHA" "$GIT_TAG" "$GIT_BRANCH")
GIT_TAG="$(git_tag)"
export GIT_TAG
GIT_REPO="$(git_repo)"
export GIT_REPO
GIT_SHA="$(git_sha)"
export GIT_SHA
GIT_USER="$(git_user)"
export GIT_USER
GIT_EMAIL="$(git_email)"
export GIT_EMAIL
GIT_ID="$(git_id)" # git user and email, space separated
export GIT_ID
GIT_INFO=$(_git_info_str "$GIT_REPO" "$GIT_SHA" "$GIT_TAG" "$GIT_BRANCH")
export GIT_INFO

}

Expand All @@ -170,10 +185,12 @@ git_vars() {
# DEVMODE=true no_unpushed_changes || exit 1
#
no_unpushed_changes() {
[[ ! -z "${DEVMODE}" ]] && yellow_i "DEVMODE - skipping git checks" && return 0;
[[ -n "${DEVMODE}" ]] && yellow_i "DEVMODE - skipping git checks" && return 0;

local d=$(pwd)
local sha=$(git_sha)
local d="" sha=""

d=$(pwd)
sha=$(git_sha)

check_for_changes "$d" || return 1
sha_in_origin "$sha" || return 1
Expand All @@ -195,7 +212,7 @@ check_for_changes() {
local d="${1:-$(pwd)}"
i "... checking for uncommitted changes in $d"
(
__cd $d || exit 1
__cd "$d" || exit 1

! in_git_clone && red_e "$(pwd) is not a git dir" && return 1;
git &>/dev/null --no-pager status # make sure index is up-to-date
Expand Down Expand Up @@ -238,7 +255,8 @@ sha_in_origin() {
return 1
fi

b=$(git branch -r --contains ${sha} 2>/dev/null)
b=$(git branch -r --contains "$sha" 2>/dev/null)
#shellcheck disable=SC2181
if [[ $? -ne 0 ]] || [[ -z "$b" ]]; then
red_e "This commit ($sha) does not exist on origin."
red_e "Did you push these changes?"
Expand All @@ -264,7 +282,7 @@ in_git_clone() {
local rc=0
local d="$1"
(
__cd $d || exit 1
__cd "$d" || exit 1
git --no-pager rev-parse --is-inside-work-tree >/dev/null 2>&1
) || rc=1
return $rc
Expand Down
Loading