From 88a7101827ebd8ce2adb0d3d451254614d80904f Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Mon, 18 Mar 2019 16:34:52 -0400 Subject: libs/git: Add git_apply() and git_apply_check() Since changes from an applied diff need to be added to the index and committed (vs. mailbox files with the git_patch function) new functions were necessary to account for this difference. This also fixes a bug where diffs were applied but not committed, at minimum dirtying the work tree and potentially causing problems for any later patches. --- libs/git | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libs/git b/libs/git index 998ceae7..358d5d1f 100755 --- a/libs/git +++ b/libs/git @@ -169,6 +169,37 @@ git_commit() { ) } +git_apply() { + local repository_path=$1 + local branch=$2 + local patch=$3 + + ( + export GIT_COMMITTER_NAME=$GIT_NAME + export GIT_COMMITTER_EMAIL=$GIT_EMAIL + + cd "$repository_path" + git checkout "$branch" >/dev/null 2>&1 + + if git_apply_check "$repository_path" "$branch" "$patch"; then + git apply --index "$patch" + fi + ) +} + +git_apply_check() { + local repository_path=$1 + local branch=$2 + local patch=$3 + + ( + cd "$repository_path" + git checkout "$branch" >/dev/null 2>&1 + + git apply --check "$patch" + ) +} + git_patch() { local repository_path=$1 local branch=$2 @@ -249,7 +280,8 @@ git_project_patch_recursive() { if [[ ${patch##*.} == patch ]]; then git_patch "$repository_path" "$branch" "$patch" else - diff_patch "$repository_path" "$patch" + git_apply "$repository_path" "$branch" "$patch" + git_commit "$repository_path" "Applied ${patch##*/}" fi done } -- cgit v1.2.3-70-g09d2