diff options
author | Andrew Robbins <contact@andrewrobbins.info> | 2019-03-26 20:34:35 -0400 |
---|---|---|
committer | Andrew Robbins <contact@andrewrobbins.info> | 2019-03-28 11:00:34 -0400 |
commit | 89176737ad54ddbdef55e0c207ccd5dba7ade2b4 (patch) | |
tree | 3ff15f53c30f634475171c6253afe2c1ed00f9bf | |
parent | ac462c0df361e067698f04111bad078fa7d1e1b8 (diff) | |
download | librebootfr-89176737ad54ddbdef55e0c207ccd5dba7ade2b4.tar.gz librebootfr-89176737ad54ddbdef55e0c207ccd5dba7ade2b4.zip |
libs/git: Exit subshell upon "cd" failure
If cd fails, nothing else should be done. This is to prevent a
potentially destructive action from being performed on the Libreboot
repository (if the script is executed from the same directory).
-rwxr-xr-x | libs/git | 54 |
1 files changed, 33 insertions, 21 deletions
@@ -41,7 +41,8 @@ git_submodule_update() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git submodule update --init ) } @@ -51,7 +52,8 @@ git_merge() { local revision=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git merge "$revision" ) } @@ -62,7 +64,8 @@ git_branch_create() { local revision=$3 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git checkout -B "$branch" if [[ -n "$revision" ]] @@ -77,7 +80,8 @@ git_branch_delete() { local branch=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git branch -D "$branch" ) } @@ -87,7 +91,8 @@ git_branch_checkout() { local branch=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" > /dev/null ) } @@ -97,7 +102,7 @@ git_branch_check() { local branch=$2 ( - cd "$repository_path" >/dev/null 2>&1 || return 1 + cd "$repository_path" 2>/dev/null || exit 1 git rev-parse --verify "$branch" >/dev/null 2>&1 ) @@ -107,7 +112,8 @@ git_fetch() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git fetch origin ) } @@ -116,7 +122,7 @@ git_fetch_check() { local repository_path=$1 ( - cd "$repository_path" >/dev/null 2>&1 || return 1 + cd "$repository_path" 2>/dev/null || exit 1 git fetch --dry-run origin >/dev/null 2>&1 ) @@ -126,7 +132,8 @@ git_clean() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git clean -df ) } @@ -136,7 +143,8 @@ git_remove() { local path=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git rm -rf "$path" ) } @@ -145,7 +153,7 @@ git_diff_staged_check() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 git diff --staged --quiet ) @@ -155,7 +163,7 @@ git_diff_check() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 git diff --quiet ) @@ -169,7 +177,8 @@ git_commit() { export GIT_COMMITTER_NAME=$GIT_NAME export GIT_COMMITTER_EMAIL=$GIT_EMAIL - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git commit --author="$GIT_NAME <$GIT_EMAIL>" -m "$message" ) } @@ -183,7 +192,8 @@ git_am() { export GIT_COMMITTER_NAME=$GIT_NAME export GIT_COMMITTER_EMAIL=$GIT_EMAIL - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" >/dev/null 2>&1 if ! git am "$patch"; then @@ -200,9 +210,9 @@ git_apply() { local patch=$3 ( - cd "$repository_path" - git checkout "$branch" >/dev/null 2>&1 + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" >/dev/null 2>&1 git apply --index "$patch" ) } @@ -213,9 +223,9 @@ git_apply_check() { local patch=$3 ( - cd "$repository_path" - git checkout "$branch" >/dev/null 2>&1 + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" >/dev/null 2>&1 git apply --check "$patch" ) } @@ -244,7 +254,8 @@ git_revision() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git rev-parse "$HEAD" ) } @@ -253,7 +264,8 @@ git_describe() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git describe --tags ) } @@ -262,7 +274,7 @@ git_files() { local repository_path="$1" ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 git ls-files -z | sort -z ) |