func popLastDirectory(path string) string {
	list := strings.Split(path, "/")
	list = list[0 : len(list)-1]
	path = "/" + filepath.Join(list...)
	return path
}
Removes the last directory in a path and returns it.
package lfs
import (
	"context"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"time"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/container"
	"github.com/docker/docker/api/types/network"
	"github.com/docker/docker/client"
	"github.com/docker/go-connections/nat"
	git "gopkg.in/libgit2/git2go.v26"
	"github.com/pkg/errors"
)
func Track(filename, repositoryLocation string) (string, error) {
	cmd := exec.Command("git-lfs", "track", filename)
	cmd.Dir = repositoryLocation
	out, err := cmd.Output()
	time.Sleep(2 * time.Second)
	output := string(out)
	output = strings.TrimRight(output, "\n")
	return output, err
}
func AddAndCommitData(path, msg string) (string, error) {
	changes, repositoryLocation, err := AddData(path)
	if err != nil {
		return "", err
	}
	var commitId string
	if changes {
		commitId, err = commit(repositoryLocation, msg)
		if err != nil {
			return "", err
		}
	}
	return commitId, nil
}
func Add(filename string) error {
	repo, _, err := openContainingRepository(filename)
	if err != nil {
		return err
	}
	changed, err := fileChanged(repo, filename)
	if err != nil {
		return err
	}
	if changed {
		err := addToIndex(repo, filename)
		if err != nil {
			return err
		}
	}
	return nil
}
func openContainingRepository(filename string) (repo *git.Repository,
	repositoryLocation string, err error) {
	path := filepath.Dir(filename)
	path, err = filepath.Abs(path)
	if err != nil {
		return nil, "", err
	}
	return openRepository(path)
}
func AddAndCommit(filename, msg string) (string, error) {
	repo, repositoryLocation, err := openContainingRepository(filename)
	if err != nil {
		return "", err
	}
	changed, err := fileChanged(repo, filename)
	if err != nil {
		return "", err
	}
	var commitId string
	if changed {
		err := addToIndex(repo, filename)
		if err != nil {
			return "", err
		}
		commitId, err = commit(repositoryLocation, msg)
		if err != nil {
			return "", err
		}
	} else {
		return "", errors.New("No changes. Nothing to commit")
	}
	return commitId, nil
}
func AddData(path string) (changes bool, repositoryLocation string, err error) {
	wd, err := os.Getwd()
	if err != nil {
		return false, "", err
	}
	defer os.Chdir(wd)
	repo, repositoryLocation, err := openRepository(path)
	if err != nil {
		return false, "", err
	}
	os.Chdir(repositoryLocation)
	dataPath, err := filepath.Rel(repositoryLocation, path)
	if err != nil {
		return false, "", err
	}
	dataPattern := "" + dataPath + "/**"
	gitAttr := ".gitattributes"
	b, err := ioutil.ReadFile(gitAttr)
	if err != nil {
		pe := err.(*os.PathError)
		if pe.Err.Error() != "no such file or directory" {
			return false, "", err
		}
	}
	if !strings.Contains(string(b), dataPattern) {
		output, err := Track(dataPattern, repositoryLocation)
		if err != nil {
			return false, "", errors.Wrap(err, "Could not track files using git-lfs: "+output)
		}
	}
	changed, err := fileChanged(repo, gitAttr)
	if err != nil {
		return false, "", err
	}
	if changed {
		err := addToIndex(repo, gitAttr)
		if err != nil {
			return false, "", err
		}
		changes = changed
	}
	changed = false
	err = filepath.Walk(dataPath, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return errors.Wrap(err, "Could not add "+path+"to repository")
		}
		if info.IsDir() {
			return nil
		}
		changedFile, err := fileChanged(repo, path)
		if err != nil {
			return err
		}
		if changedFile {
			changed = true
			return nil
		}
		return nil
	})
	if err != nil {
		return false, "", err
	}
	if changed {
		output, err := add(dataPath, repositoryLocation)
		if err != nil {
			return false, "", errors.Wrap(err, "Could not add files "+output)
		}
	}
	changes = changed
	return changes, repositoryLocation, nil
}
func addToIndex(repo *git.Repository, path string) error {
	index, err := repo.Index()
	if err != nil {
		return err
	}
	err = index.AddByPath(path)
	if err != nil {
		return err
	}
	_, err = index.WriteTree()
	if err != nil {
		return err
	}
	err = index.Write()
	if err != nil {
		return err
	}
	return err
}