func (repo *Repository) ReadGitModifiedFiles(scanner *bufio.Scanner) {
	for scanner.Scan() {
		file := scanner.Text()
		matched := false
		for _, regex := range repo.IgnoreRegexes {
			if regex.Match([]byte(file)) {
				fmt.Println("Skipping file " + file + " matches ignore spec " + regex.String())
				matched = true
				break
			}
		}
		if !matched {
			repo.UnpushedFiles.Add(scanner.Text())
		}
	}
}
ReadGitModifiedFiles reads the git output describe files modified since last S3 push
package s3push
import (
	"bufio"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"strings"
	"github.com/deckarep/golang-set"
	"github.com/speedata/gogit"
)
const refS3Push string = "refs/heads/s3-pushed"
const prefixRefS3 string = "refs/heads/git-s3-push/"
const configFilePath string = ".git_s3_push"
type Repository struct {
	GitRepo        *gogit.Repository
	HeadCommit     *gogit.Commit
	LastPushCommit *gogit.Commit
	UnpushedFiles  mapset.Set
	Config         repoConfig
	IgnoreRegexes  []*regexp.Regexp
	s3Uploader     S3Uploader
}
type repoConfig struct {
	S3Region      string
	S3Bucket      string
	Public        bool
	Prefix        string
	Ignore        []string
	IncludeNonGit []string
}
func OpenRepository() (*Repository, error) {
	repo := new(Repository)
	repo.UnpushedFiles = mapset.NewSet()
	wd, err := os.Getwd()
	if err != nil {
		return nil, err
	}
	path := filepath.Join(wd, ".git")
	if _, err = os.Stat(path); os.IsNotExist(err) {
		return nil, err
	}
	gitRepo, err := gogit.OpenRepository(path)
	if err != nil {
		return nil, err
	}
	repo.GitRepo = gitRepo
	return repo, nil
}
func (repo *Repository) ReadConfigFile() error {
	file, err := ioutil.ReadFile(configFilePath)
	if err != nil {
		return err
	}
	err = json.Unmarshal(file, &repo.Config)
	if err != nil {
		return err
	}
	err = repo.CompileIgnoreRegexes()
	if err != nil {
		return err
	}
	return nil
}
func (repo *Repository) CompileIgnoreRegexes() error {
	for _, regexStr := range repo.Config.Ignore {
		regexStr = strings.Replace(regexStr, "*", "(.*)", -1)
		regex, err := regexp.Compile(regexStr)
		if err != nil {
			return err
		}
		repo.IgnoreRegexes = append(repo.IgnoreRegexes, regex)
	}
	return nil
}
func (repo Repository) SaveConfigToFile() error {
	jsonData, err := json.Marshal(repo.Config)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(configFilePath, jsonData, 0644)
	if err != nil {
		return err
	}
	return nil
}
func (repo *Repository) FindRelevantCommits() error {
	headRef, err := repo.GitRepo.LookupReference("HEAD")
	if err != nil {
		return err
	}
	headCommit, err := repo.GitRepo.LookupCommit(headRef.Target())
	if err != nil {
		return err
	}
	repo.HeadCommit = headCommit
	lastPushRef, err := repo.GitRepo.LookupReference(repo.getRefName())
	if err != nil {
		return nil
	}
	lastPushCommit, err := repo.GitRepo.LookupCommit(lastPushRef.Target())
	if err != nil {
		return nil
	}
	repo.LastPushCommit = lastPushCommit
	return nil
}