@@ -55,7 +55,7 @@ func initHookCallback(ctx *cli.Context) (retErr error) {
5555
5656 // create hook file
5757 hookFile := filepath .Join (hookDir , commitMsgHook )
58- err = writeHookFile (hookFile )
58+ err = commitlint . WriteHookToFile (hookFile )
5959 if err != nil {
6060 return err
6161 }
@@ -104,28 +104,6 @@ func setGitConf(hookDir string, isGlobal bool) error {
104104 return cmd .Run ()
105105}
106106
107- func writeHookFile (hookFilePath string ) (retErr error ) {
108- // if commit-msg already exists skip creating or overwriting it
109- if isFileExists (hookFilePath ) {
110- return nil
111- }
112- // commit-msg needs to be executable
113- file , err := os .OpenFile (hookFilePath , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0700 )
114- if err != nil {
115- return err
116- }
117- defer func () {
118- err1 := file .Close ()
119- if retErr == nil && err1 != nil {
120- retErr = err1
121- }
122- }()
123-
124- commitHook := commitlint .CommitMsgHook ()
125- _ , err = file .WriteString (commitHook )
126- return err
127- }
128-
129107func getLinter (confFilePath string ) (* commitlint.Linter , error ) {
130108 // Config Precedence
131109 // 1. Check for conf in current directory
@@ -139,7 +117,7 @@ func getLinter(confFilePath string) (*commitlint.Linter, error) {
139117
140118 // check if conf file exists in current directory
141119 currentDirConf := filepath .Join (currentDir , defConfFileName )
142- if isFileExists (currentDirConf ) {
120+ if commitlint . IsFileExists (currentDirConf ) {
143121 confFilePath = currentDirConf
144122 }
145123
@@ -189,8 +167,3 @@ func readStdIn() string {
189167 s := string (readBytes )
190168 return strings .TrimSpace (s )
191169}
192-
193- func isFileExists (filename string ) bool {
194- _ , err := os .Stat (filename )
195- return ! os .IsNotExist (err )
196- }
0 commit comments