starting to write the commit functions
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
			
		||||
package clientcmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
@@ -22,7 +21,6 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	var trackedFiles []string
 | 
			
		||||
	var SkipDir = errors.New("ignore folder, either .gvc or on ignores") // default variable for filewalk errors to skip the entire dir
 | 
			
		||||
	switch inputType {
 | 
			
		||||
	case "file": // If the -file flag was used, then make sure it is a file, make sure not on ignore list, then add it to tracked files
 | 
			
		||||
		_, err := os.Stat(input)
 | 
			
		||||
@@ -41,6 +39,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
 | 
			
		||||
		// 	}
 | 
			
		||||
		// }
 | 
			
		||||
		relativePath := input //TODO: Figure out if path is corrrect?
 | 
			
		||||
		relativePath = "test.go"
 | 
			
		||||
		fmt.Println("Relative Path: ", relativePath)
 | 
			
		||||
		err = m.AddFileToRepo(relativePath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
@@ -57,22 +56,25 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
 | 
			
		||||
			return fmt.Errorf("file exists, but is not a folder %s", err)
 | 
			
		||||
		}
 | 
			
		||||
		filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
 | 
			
		||||
			currentFile := filepath.Base(path)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return fmt.Errorf("failure accessing path %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			if info.IsDir() {
 | 
			
		||||
				if currentFile == ".gvc" { // can't track anything in .gvc
 | 
			
		||||
					return SkipDir
 | 
			
		||||
				if info.Name() == ".gvc" { // can't track anything in .gvc
 | 
			
		||||
					fmt.Println("skipping .gvc directory")
 | 
			
		||||
					m.Info().Msg("skipping .gvc directory")
 | 
			
		||||
					return filepath.SkipDir
 | 
			
		||||
				}
 | 
			
		||||
				err = common.CheckFileTypes(currentFile, "folder", ignore)
 | 
			
		||||
				err = common.CheckFileTypes(info.Name(), "folder", ignore)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return SkipDir
 | 
			
		||||
					fmt.Printf("skipping ignored directory: %s\n", err)
 | 
			
		||||
					m.Info().Msgf("skipping ignored directory: %s\n", err)
 | 
			
		||||
					return filepath.SkipDir
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				err = common.CheckFileTypes(currentFile, "file", ignore)
 | 
			
		||||
				err = common.CheckFileTypes(info.Name(), "file", ignore)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
 | 
			
		||||
					fmt.Printf("Not adding file %s as it is on the ingores list \n", info.Name())
 | 
			
		||||
					return nil
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@@ -100,38 +102,44 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
 | 
			
		||||
			currentFile := filepath.Base(path) // Stripping all the pathing so we just get the filename
 | 
			
		||||
			fmt.Println("path: ", path)
 | 
			
		||||
			fmt.Printf("Checking file: %s\n", currentFile)
 | 
			
		||||
			fmt.Printf("Checking file: %s\n", info.Name())
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return fmt.Errorf("failure accessing path %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			if info.IsDir() {
 | 
			
		||||
				if currentFile == ".gvc" { // can't track anything in .gvc
 | 
			
		||||
					return nil
 | 
			
		||||
				if info.Name() == ".gvc" { // can't track anything in .gvc
 | 
			
		||||
					fmt.Println("skipping .gvc directory")
 | 
			
		||||
					m.Info().Msg("skipping .gvc directory")
 | 
			
		||||
					return filepath.SkipDir
 | 
			
		||||
				}
 | 
			
		||||
				err = common.CheckFileTypes(currentFile, "folder", ignore)
 | 
			
		||||
				err = common.CheckFileTypes(info.Name(), "folder", ignore)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
					fmt.Printf("skipping ignored directory: %s\n", err)
 | 
			
		||||
					m.Info().Msgf("skipping ignored directory: %s\n", err)
 | 
			
		||||
					return filepath.SkipDir
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				err = common.CheckFileTypes(currentFile, "file", ignore)
 | 
			
		||||
				err = common.CheckFileTypes(info.Name(), "file", ignore)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
 | 
			
		||||
					fmt.Printf("Not adding file %s as it is on the ingores list \n", info.Name())
 | 
			
		||||
					return nil
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			fileExt := filepath.Ext(path)
 | 
			
		||||
			if fileExt == wildcard { // seeing if the file ext matches the wildcard
 | 
			
		||||
				fmt.Println("Adding file that matched wildcard: ", currentFile)
 | 
			
		||||
				fmt.Println("Adding file that matched wildcard: ", info.Name())
 | 
			
		||||
				relativePath, err := filepath.Rel(workingDir, path)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("unable to create relative path for file: %s", err)
 | 
			
		||||
					fmt.Printf("unable to create relative path for file: %s\n", err)
 | 
			
		||||
					m.Info().Msgf("unable to create relative path for file: %s\n", err)
 | 
			
		||||
					return nil
 | 
			
		||||
				}
 | 
			
		||||
				fmt.Println("WILDCARD Relative Path: ", relativePath)
 | 
			
		||||
				err = m.AddFileToRepo(relativePath)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("unable to add file to repo: %s", err)
 | 
			
		||||
					fmt.Printf("unable to add file to repo: %s\n", err)
 | 
			
		||||
					m.Info().Msgf("unable to add file to repo: %s\n", err)
 | 
			
		||||
					return nil
 | 
			
		||||
				}
 | 
			
		||||
				trackedFiles = append(trackedFiles, relativePath)
 | 
			
		||||
			}
 | 
			
		||||
@@ -139,22 +147,25 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
 | 
			
		||||
		})
 | 
			
		||||
	case "all":
 | 
			
		||||
		filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
 | 
			
		||||
			currentFile := filepath.Base(path)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return fmt.Errorf("failure accessing path %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			if info.IsDir() {
 | 
			
		||||
				if currentFile == ".gvc" { // can't track anything in .gvc
 | 
			
		||||
					return SkipDir
 | 
			
		||||
				if info.Name() == ".gvc" { // can't track anything in .gvc
 | 
			
		||||
					fmt.Println("skipping .gvc directory")
 | 
			
		||||
					m.Info().Msg("skipping .gvc directory")
 | 
			
		||||
					return filepath.SkipDir
 | 
			
		||||
				}
 | 
			
		||||
				err = common.CheckFileTypes(currentFile, "folder", ignore)
 | 
			
		||||
				err = common.CheckFileTypes(info.Name(), "folder", ignore)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return SkipDir
 | 
			
		||||
					fmt.Printf("skipping ignored directory: %s\n", err)
 | 
			
		||||
					m.Info().Msgf("skipping ignored directory: %s\n", err)
 | 
			
		||||
					return filepath.SkipDir
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				err = common.CheckFileTypes(currentFile, "file", ignore)
 | 
			
		||||
				err = common.CheckFileTypes(info.Name(), "file", ignore)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
 | 
			
		||||
					fmt.Printf("Not adding file %s as it is on the ingores list \n", info.Name())
 | 
			
		||||
					return nil
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@@ -173,7 +184,13 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
 | 
			
		||||
			return nil
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	fmt.Println("Added tracked files", trackedFiles) // Print out all the new tracked files
 | 
			
		||||
	if len(trackedFiles) > 0 {
 | 
			
		||||
		fmt.Println("Added tracked files", trackedFiles) // Print out all the new tracked files
 | 
			
		||||
		m.Info().Msgf("Adding the following files to tracked: %s", trackedFiles)
 | 
			
		||||
	} else {
 | 
			
		||||
		fmt.Println("No files found that could be added to tracked")
 | 
			
		||||
		m.Info().Msg("No files found that could be added to tracked")
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user