[PATCH] Use git commit --only

Luis Ressel aranea at aixah.de
Fri Nov 25 20:46:47 CET 2016


Pass the name of the file being committed to "git commit". This way, git
will only commit the change to the password file which has been changed,
even if the password store happens to be part of a larger git repository
and other (completely unrelated) files are staged.

Adding the "--only" option isn't strictly neccessary; even without it,
"git commit" would behave in this way when it's passed file names as
arguments. For clarity, I've chosen to add the option regardless.
---
 src/password-store.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 63be840..5d7d733 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -28,13 +28,13 @@ git_add_file() {
 	[[ -d $GIT_DIR ]] || return
 	git add "$1" || return
 	[[ -n $(git status --porcelain "$1") ]] || return
-	git_commit "$2"
+	git_commit "$1" "$2"
 }
 git_commit() {
 	local sign=""
 	[[ -d $GIT_DIR ]] || return
 	[[ $(git config --bool --get pass.signcommits) == "true" ]] && sign="-S"
-	git commit $sign -m "$1"
+	git commit $sign --only --message="$2" "$1"
 }
 yesno() {
 	[[ -t 0 ]] || return 0
@@ -279,7 +279,7 @@ cmd_init() {
 		rm -v -f "$gpg_id" || exit 1
 		if [[ -d $GIT_DIR ]]; then
 			git rm -qr "$gpg_id"
-			git_commit "Deinitialize ${gpg_id}${id_path:+ ($id_path)}."
+			git_commit "$gpg_id" "Deinitialize ${gpg_id}${id_path:+ ($id_path)}."
 		fi
 		rmdir -p "${gpg_id%/*}" 2>/dev/null
 	else
@@ -502,7 +502,7 @@ cmd_delete() {
 	rm $recursive -f -v "$passfile"
 	if [[ -d $GIT_DIR && ! -e $passfile ]]; then
 		git rm -qr "$passfile"
-		git_commit "Remove $path from store."
+		git_commit "$passfile" "Remove $path from store."
 	fi
 	rmdir -p "${passfile%/*}" 2>/dev/null
 }
-- 
2.10.2



More information about the Password-Store mailing list