[PATCH] pass git understands -p/--path option

Björn Fiedler bjoern at reldeif.de
Thu Nov 17 15:21:22 UTC 2022


This commit allows to use -p/--path for `pass git` the same way as
`pass init` accepts it.
---
 man/pass.1            |  4 +++-
 src/password-store.sh | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/man/pass.1 b/man/pass.1
index a555dcb..09ada0c 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -164,7 +164,7 @@ silently overwrite \fInew-path\fP if it exists. If \fInew-path\fP ends in a
 trailing \fI/\fP, it is always treated as a directory. Passwords are selectively
 reencrypted to the corresponding keys of their new destination.
 .TP
-\fBgit\fP \fIgit-command-args\fP...
+\fBgit\fP [ \fI--path=sub-folder\fP, \fI-p sub-folder\fP ] \fIgit-command-args\fP...
 If the password store is a git repository, pass \fIgit-command-args\fP as arguments to
 .BR git (1)
 using the password store as the git repository. If \fIgit-command-args\fP is \fBinit\fP,
@@ -173,6 +173,8 @@ store to the repository in an initial commit. If the git config key \fIpass.sign
 is set to \fItrue\fP, then all commits will be signed using \fIuser.signingkey\fP or the
 default git signing key. This config key may be turned on using:
 .B `pass git config --bool --add pass.signcommits true`
+If \fI--path\fP or \fI-p\fP is specified, the git command is executed in that specific
+sub folder of the password store.
 .TP
 \fBhelp\fP
 Show usage message.
diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..2acacef 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -650,6 +650,19 @@ cmd_copy_move() {
 }
 
 cmd_git() {
+	local opts id_path=""
+	opts="$($GETOPT -o p: -l path: -n "$PROGRAM git" -- "$@")"
+	local err=$?
+	eval set -- "$opts"
+	while true; do case $1 in
+		-p|--path) id_path="$2"; shift 2 ;;
+		--) shift; break ;;
+	esac done
+
+	[[ -n $id_path ]] && check_sneaky_paths "$id_path"
+	[[ -n $id_path && ! -d $PREFIX/$id_path && -e $PREFIX/$id_path ]] && die "Error: $PREFIX/$id_path exists but is not a directory."
+
+	local PREFIX="$PREFIX/$id_path"
 	set_git "$PREFIX/"
 	if [[ $1 == "init" ]]; then
 		INNER_GIT_DIR="$PREFIX"
-- 
2.37.2



More information about the Password-Store mailing list