55from os .path import isfile
66from os .path import join
77from os .path import samefile
8- from shlex import quote
98
109from .config import Configuration
1110from .scm_workdir import Workdir
@@ -39,8 +38,7 @@ def from_potential_worktree(cls, wd):
3938 wd = os .path .abspath (wd )
4039 git_dir = join (wd , ".git" )
4140 real_wd , _ , ret = do_ex (
42- f"git --git-dir={ quote (git_dir )} rev-parse --show-prefix" ,
43- wd ,
41+ ["git" , "--git-dir" , git_dir , "rev-parse" , "--show-prefix" ], wd
4442 )
4543 real_wd = real_wd [:- 1 ] # remove the trailing pathsep
4644 if ret :
@@ -59,35 +57,26 @@ def from_potential_worktree(cls, wd):
5957
6058 return cls (real_wd )
6159
62- def __init__ (self , * args , ** kwargs ):
63- super ().__init__ (* args , ** kwargs )
64- self ._git_dir = join (self .path , ".git" )
60+ def do_ex_git (self , cmd ):
61+ return self .do_ex (["git" , "--git-dir" , join (self .path , ".git" )] + cmd )
6562
6663 def is_dirty (self ):
67- out , _ , _ = self .do_ex (
68- f"git --git-dir={ quote (self ._git_dir )} "
69- "status --porcelain --untracked-files=no"
70- )
64+ out , _ , _ = self .do_ex_git (["status" , "--porcelain" , "--untracked-files=no" ])
7165 return bool (out )
7266
7367 def get_branch (self ):
74- branch , err , ret = self .do_ex (
75- f"git --git-dir={ quote (self ._git_dir )} rev-parse --abbrev-ref HEAD"
76- )
68+ branch , err , ret = self .do_ex_git (["rev-parse" , "--abbrev-ref" , "HEAD" ])
7769 if ret :
7870 trace ("branch err" , branch , err , ret )
79- branch , err , ret = self .do_ex (
80- f"git --git-dir={ quote (self ._git_dir )} symbolic-ref --short HEAD"
81- )
71+ branch , err , ret = self .do_ex_git (["symbolic-ref" , "--short" , "HEAD" ])
8272 if ret :
8373 trace ("branch err (symbolic-ref)" , branch , err , ret )
8474 branch = None
8575 return branch
8676
8777 def get_head_date (self ):
88- timestamp , err , ret = self .do_ex (
89- f"git --git-dir={ quote (self ._git_dir )} -c log.showSignature=false "
90- "log -n 1 HEAD --format=%cI"
78+ timestamp , err , ret = self .do_ex_git (
79+ ["-c" , "log.showSignature=false" , "log" , "-n" , "1" , "HEAD" , "--format=%cI" ]
9180 )
9281 if ret :
9382 trace ("timestamp err" , timestamp , err , ret )
@@ -100,25 +89,24 @@ def get_head_date(self):
10089 return datetime .strptime (date_part , r"%Y-%m-%d" ).date ()
10190
10291 def is_shallow (self ):
103- return isfile (join (self ._git_dir , "shallow" ))
92+ return isfile (join (self .path , ".git/ shallow" ))
10493
10594 def fetch_shallow (self ):
106- self .do_ex ( f"git --git-dir= { quote ( self . _git_dir ) } fetch --unshallow" )
95+ self .do_ex_git ([ " fetch" , " --unshallow"] )
10796
10897 def node (self ):
109- node , _ , ret = self .do_ex (
110- f"git --git-dir={ quote (self ._git_dir )} rev-parse --verify --quiet HEAD"
111- )
98+ node , _ , ret = self .do_ex_git (["rev-parse" , "--verify" , "--quiet" , "HEAD" ])
11299 if not ret :
113100 return node [:7 ]
114101
115102 def count_all_nodes (self ):
116- revs , _ , _ = self .do_ex ( f"git --git-dir= { quote ( self . _git_dir ) } rev-list HEAD" )
103+ revs , _ , _ = self .do_ex_git ([ " rev-list" , " HEAD"] )
117104 return revs .count ("\n " ) + 1
118105
119106 def default_describe (self ):
107+ git_dir = join (self .path , ".git" )
120108 return self .do_ex (
121- DEFAULT_DESCRIBE [:1 ] + ["--git-dir" , self . _git_dir ] + DEFAULT_DESCRIBE [1 :]
109+ DEFAULT_DESCRIBE [:1 ] + ["--git-dir" , git_dir ] + DEFAULT_DESCRIBE [1 :]
122110 )
123111
124112
0 commit comments