[PATCH] add possibility to use git in a sub-folder for multi repo usage

Philippe BEAUMONT philippe.beaumont at nfrance.com
Tue Apr 11 16:42:53 CEST 2017


add possibility to use git in a sub-folder for multi repo: rework patch with getopts

add possibility to use git in a sub-folder for multi repo: clean code
---
 man/pass.1            |  2 +-
 src/password-store.sh | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/man/pass.1 b/man/pass.1
index e842178..c254b54 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -159,7 +159,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-C 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,
diff --git a/src/password-store.sh b/src/password-store.sh
index 6a4172d..afb3156 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -285,7 +285,7 @@ cmd_usage() {
 	        Renames or moves old-path to new-path, optionally forcefully, selectively reencrypting.
 	    $PROGRAM cp [--force,-f] old-path new-path
 	        Copies old-path to new-path, optionally forcefully, selectively reencrypting.
-	    $PROGRAM git git-command-args...
+	    $PROGRAM git [-C subfolder] git-command-args...
 	        If the password store is a git repository, execute a git command
 	        specified by git-command-args.
 	    $PROGRAM help
@@ -627,6 +627,14 @@ cmd_copy_move() {
 }
 
 cmd_git() {
+	local opts subdir=""
+	opts="$($GETOPT -o C: -n "$PROGRAM" -- "$@")"
+	local err=$?
+	eval set -- "$opts"
+	while true; do case $1 in
+		-C) subdir="${2:-1}"; PREFIX="$PREFIX/$subdir"; shift 2 ;;
+		--) shift; break ;;
+	esac done
 	set_git "$PREFIX/"
 	if [[ $1 == "init" ]]; then
 		INNER_GIT_DIR="$PREFIX"
-- 
2.9.3



More information about the Password-Store mailing list