working on adding files to repo and making sure no duplicates
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package clientcmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -21,6 +22,7 @@ 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)
|
||||
@@ -39,6 +41,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
|
||||
// }
|
||||
// }
|
||||
relativePath := input //TODO: Figure out if path is corrrect?
|
||||
fmt.Println("Relative Path: ", relativePath)
|
||||
err = m.AddFileToRepo(relativePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add file to repo: %s", err)
|
||||
@@ -59,13 +62,19 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
|
||||
return fmt.Errorf("failure accessing path %s", err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
if currentFile == ".gvc" { // can't track anything in .gvc
|
||||
return SkipDir
|
||||
}
|
||||
err = common.CheckFileTypes(currentFile, "folder", ignore)
|
||||
if err != nil {
|
||||
return SkipDir
|
||||
}
|
||||
} else {
|
||||
err = common.CheckFileTypes(currentFile, "file", ignore)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
|
||||
return nil
|
||||
if err != nil {
|
||||
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
fmt.Println("adding file: ", path)
|
||||
relativePath, err := filepath.Rel(workingDir, path)
|
||||
@@ -92,17 +101,25 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
|
||||
}
|
||||
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)
|
||||
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
|
||||
}
|
||||
err = common.CheckFileTypes(currentFile, "folder", ignore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = common.CheckFileTypes(currentFile, "file", ignore)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
|
||||
return nil
|
||||
if err != nil {
|
||||
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
fileExt := filepath.Ext(path)
|
||||
if fileExt == wildcard { // seeing if the file ext matches the wildcard
|
||||
@@ -111,6 +128,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create relative path for file: %s", err)
|
||||
}
|
||||
fmt.Println("WILDCARD Relative Path: ", relativePath)
|
||||
err = m.AddFileToRepo(relativePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add file to repo: %s", err)
|
||||
@@ -126,13 +144,19 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
|
||||
return fmt.Errorf("failure accessing path %s", err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
if currentFile == ".gvc" { // can't track anything in .gvc
|
||||
return SkipDir
|
||||
}
|
||||
err = common.CheckFileTypes(currentFile, "folder", ignore)
|
||||
if err != nil {
|
||||
return SkipDir
|
||||
}
|
||||
} else {
|
||||
err = common.CheckFileTypes(currentFile, "file", ignore)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
|
||||
return nil
|
||||
if err != nil {
|
||||
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
relativePath, err := filepath.Rel(workingDir, path)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user