@@ -44,3 +44,63 @@ pub(crate) fn has_unstaged_config(repo: &gix::Repository, config: &str) -> anyho
4444
4545 Ok ( retc == 1 )
4646}
47+
48+ // from `git rev-parse --local-env-vars`
49+ // TODO: use gix for this?
50+ const _LOCAL_ENV_VARS: & [ & str ] = & [
51+ "GIT_ALTERNATE_OBJECT_DIRECTORIES" ,
52+ "GIT_COMMON_DIR" ,
53+ "GIT_CONFIG" ,
54+ "GIT_CONFIG_COUNT" ,
55+ "GIT_CONFIG_PARAMETERS" ,
56+ "GIT_DIR" ,
57+ "GIT_GRAFT_FILE" ,
58+ "GIT_IMPLICIT_WORK_TREE" ,
59+ "GIT_INDEX_FILE" ,
60+ "GIT_INTERNAL_SUPER_PREFIX" ,
61+ "GIT_NO_REPLACE_OBJECTS" ,
62+ "GIT_OBJECT_DIRECTORY" ,
63+ "GIT_PREFIX" ,
64+ "GIT_REPLACE_REF_BASE" ,
65+ "GIT_SHALLOW_FILE" ,
66+ "GIT_WORK_TREE" ,
67+ ] ;
68+
69+ pub ( crate ) trait GitNoLocalEnv {
70+ fn git_no_local_env ( & mut self ) -> & mut Self ;
71+ }
72+
73+ impl GitNoLocalEnv for process:: Command {
74+ fn git_no_local_env ( & mut self ) -> & mut Self {
75+ for var in _LOCAL_ENV_VARS {
76+ self . env_remove ( var) ;
77+ }
78+ self
79+ }
80+ }
81+
82+ pub ( crate ) fn git_no_fs_monitor ( ) -> process:: Command {
83+ let mut ret = process:: Command :: new ( "git" ) ;
84+ ret. args ( [ "-c" , "core.useBuiltinFSMonitor=false" ] ) ;
85+ ret
86+ }
87+
88+ pub ( crate ) fn init_repo ( path : & str , remote : & str ) -> anyhow:: Result < ( ) > {
89+ // TODO:
90+ // if os.path.isdir(remote):
91+ // remote = os.path.abspath(remote)
92+
93+ // TODO: add this to gix?
94+ // avoid the user's template so that hooks do not recurse
95+ git_no_fs_monitor ( )
96+ . git_no_local_env ( )
97+ . args ( [ "init" , "--template=" , path] )
98+ . output ( ) ?;
99+ git_no_fs_monitor ( )
100+ . git_no_local_env ( )
101+ . current_dir ( path)
102+ . args ( [ "remote" , "add" , "origin" , remote] )
103+ . output ( ) ?;
104+
105+ Ok ( ( ) )
106+ }
0 commit comments