diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-01 13:36:47 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-01 13:36:47 +0200 |
commit | d7845cdced852478e73cbd8f4b52dfc42da9c668 (patch) | |
tree | 5dc6afc6cf66f6d0d295ba6b6a6fdc95947b87a8 /bin/common/gt-cmd | |
parent | 642e439ddac3c27431616778925f26d37e3db0fb (diff) |
checkpoint
Diffstat (limited to 'bin/common/gt-cmd')
-rwxr-xr-x | bin/common/gt-cmd | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/bin/common/gt-cmd b/bin/common/gt-cmd index faa743a..bc5c9c9 100755 --- a/bin/common/gt-cmd +++ b/bin/common/gt-cmd @@ -11,10 +11,24 @@ args="$*" repo_pretty="$(printf '%s' "$repo" | sed "s@^$HOME@~@")" if [ ! -d "$repo" ]; then - printf '%s missing\n' "$repo_pretty" + printf '%s: missing\n' "$repo_pretty" exit 1 fi +# Check if repo's remote's key is in ssh-agent +# If key is not registered and command is push/pull we exit with error +r="$(grep "$repo" "$REPOS" | cut -f 2 -d ' ' | cut -f 2 -d '@' | cut -f 1 -d ':')" +if { [ "$command" = "push" ] || [ "$command" = "pull" ]; } && + # In my ssh config every Host has the same name as its private key. This means remotes in + # "$REPOS" (here "$r") + .pub is the public key, so we convert the name to what would be the + # public key's name and check if its contents are registered in the ssh-agent. + [ -r "$HOME/.ssh/$r.pub" ] && + ! ssh-add -L | grep "$(cat "$HOME/.ssh/$r.pub")" > /dev/null +then + printf '%s: key not added\n' "$repo_pretty" + exit 1 +fi + git -C "$repo" "$command" $args >/dev/null 2>&1 [ $? -gt 0 ] && s="x" || s="o" printf '%s: %s\n' "$repo_pretty" "$s" |