MCPcopy Create free account
hub / github.com/remotemobprogramming/mob / getPathOfLastModifiedFile

Function getPathOfLastModifiedFile

mob.go:871–911  ·  view source on GitHub ↗

uses git status --porcelain. To work properly files have to be staged.

()

Source from the content-addressed store, hash-verified

869
870// uses git status --porcelain. To work properly files have to be staged.
871func getPathOfLastModifiedFile() string {
872 rootDir := gitRootDir()
873 files := getModifiedFiles(rootDir)
874 lastModifiedFilePath := ""
875 lastModifiedTime := time.Time{}
876
877 say.Debug("Find last modified file")
878 if len(files) == 1 {
879 lastModifiedFilePath = files[0]
880 say.Debug("Just one modified file: " + lastModifiedFilePath)
881 return lastModifiedFilePath
882 }
883
884 for _, file := range files {
885 unquotedFile := file
886 if strings.HasPrefix(file, "\"") {
887 var err error
888 unquotedFile, err = strconv.Unquote(file)
889 if err != nil {
890 say.Warning("Could not unquote filename from git: " + file)
891 say.Warning(err.Error())
892 continue
893 }
894 }
895 absoluteFilepath := rootDir + "/" + unquotedFile
896 say.Debug(absoluteFilepath)
897 info, err := os.Stat(absoluteFilepath)
898 if err != nil {
899 say.Warning("Could not get statistics of file: " + absoluteFilepath)
900 say.Warning(err.Error())
901 continue
902 }
903 modTime := info.ModTime()
904 if modTime.After(lastModifiedTime) {
905 lastModifiedTime = modTime
906 lastModifiedFilePath = file
907 }
908 say.Debug(modTime.String())
909 }
910 return lastModifiedFilePath
911}
912
913// uses git status --porcelain. To work properly files have to be staged.
914func getModifiedFiles(rootDir string) []string {

Calls 5

DebugFunction · 0.92
WarningFunction · 0.92
gitRootDirFunction · 0.85
getModifiedFilesFunction · 0.85
StringMethod · 0.80