A repository-specific protocol configuration that's not pushed

34 Views Asked by At

I'd like to configure the file protocol for use with one of my repository, as it resides next 2 other repos that I'll use as dependency in the form of git submodules. But due to security reasons, I don't want random repo I pull elsewhere to go rogue and clone files from my local filesystem when I initialize their submodules.

I thought a repository-specific configuration would work for me, but I don't want this config to be pushed to public git servers.

The similar question box led me to this when I'm drafting this question, but I wonder if there's better solution.

1

There are 1 best solutions below

0
DannyNiu On BEST ANSWER

According to git-config#ENVIRONMENT, you can override your "secure" default on command-by-command basis by setting environment variables, like this:

#!/bin/sh

# I've made it a function for you to include in your profile/{shell}rc file.

git_allow_file_proto()(
    export GIT_CONFIG_COUNT=1
    export GIT_CONFIG_KEY_0=protocol.file.allow
    export GIT_CONFIG_VALUE_0=always
    git "$@"
    # for example: 
    # git_allow_file_proto submodule add ${local_fs_path} ${worktree_path}
)