starting to write the commit functions
This commit is contained in:
		
							
								
								
									
										33
									
								
								client/clientcmd/commit.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								client/clientcmd/commit.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
package clientcmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	clientconfig "github.com/deranjer/gvc/client/clientconfig"
 | 
			
		||||
	"github.com/deranjer/gvc/common/engine"
 | 
			
		||||
	"github.com/deranjer/gvc/common/manager"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Commit commits the tracked files and changes to the repo
 | 
			
		||||
func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *manager.Manager) error {
 | 
			
		||||
	trackedFiles, err := m.FetchTrackedFiles()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	for _, trackedFile := range trackedFiles {
 | 
			
		||||
		currentFile, err := os.Stat(trackedFile.Path)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		currentFileHash, err := engine.UniqueFileHash(trackedFile.Path)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err)
 | 
			
		||||
		}
 | 
			
		||||
		if currentFileHash == trackedFile.CurrentHash {
 | 
			
		||||
			fmt.Printf("No changes found in file: %s when compared to file: %s\n", currentFile.Name(), trackedFile.Name)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user