1+ import os
12from subprocess import call , Popen , PIPE
23from sys import platform as _platform
34from .colors import logcolors
67
78class git_commands :
89 def __init__ (self , path ):
10+ self .current_directory = os .getcwd ()
911 self .path = path
1012 self .git_path = join (self .path , '.git' )
1113 self .git_command = f'git --git-dir={ self .git_path } --work-tree={ self .path } '
@@ -14,18 +16,19 @@ def init(self):
1416 """
1517 Initializes git repository by calling git init
1618 """
17- call (f'{ self .git_command } init' )
19+ os .chdir (self .path )
20+ call (f'git init' )
21+ os .chdir (self .current_directory )
1822
1923 def createReadme (self ):
2024 """
2125 Creates README.md if during the git repository initialization
2226 """
23- if _platform == "linux" or _platform == "linux2" :
24- call ('touch README.md' )
25- elif _platform == "darwin" :
26- call ('touch README.md' )
27- elif _platform == "win32" :
28- call ('type nul>README.md' )
27+ readme_path = os .path .join (self .path , 'README.md' )
28+ dir = self .path .split ('\\ ' )[- 1 ]
29+ with open (readme_path , 'w' ) as readme :
30+ readme .write (f'# { dir } ' )
31+ readme .close ()
2932
3033 def add (self , file ):
3134 """
@@ -83,7 +86,7 @@ def setBranch(self, branch):
8386 branch: str
8487 Working branch
8588 """
86- call (f'{ self .git_command } git branch -M { branch } ' )
89+ call (f'{ self .git_command } branch -M { branch } ' )
8790
8891 def push (self , url , branch ):
8992 """
@@ -128,7 +131,7 @@ def initRepository(self, info):
128131 self .init ()
129132 self .createReadme ()
130133 self .add ('.' )
131- self .commit ('added README.md ' )
134+ self .commit ('initial commit ' )
132135 self .setBranch (branch )
133136 self .setRemote (url )
134137 self .push (url , branch )
0 commit comments