fix broken change recognition
This commit is contained in:
parent
0d015ae410
commit
3fb9032de6
1 changed files with 28 additions and 21 deletions
43
main.go
43
main.go
|
@ -39,18 +39,17 @@ func Commit(
|
||||||
Commitmu.Lock()
|
Commitmu.Lock()
|
||||||
defer Commitmu.Unlock()
|
defer Commitmu.Unlock()
|
||||||
|
|
||||||
|
if _, err := tree.Add(padfile); err != nil {
|
||||||
|
return plumbing.ZeroHash, fmt.Errorf("Failed to stage %s: %w", padfile, err)
|
||||||
|
}
|
||||||
|
|
||||||
status, err := tree.Status()
|
status, err := tree.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return plumbing.ZeroHash, fmt.Errorf("Failed to get status of %s", padfile)
|
return plumbing.ZeroHash, fmt.Errorf("Failed to get status of %s", padfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tree.Add(padfile); err != nil {
|
|
||||||
return plumbing.ZeroHash, fmt.Errorf("Failed to stage %s: %w", padfile, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fileStatus := status.File(padfile)
|
fileStatus := status.File(padfile)
|
||||||
if fileStatus.Staging == git.Unmodified ||
|
if fileStatus.Staging != git.Added && fileStatus.Staging != git.Modified {
|
||||||
fileStatus.Staging == git.Untracked {
|
|
||||||
return plumbing.ZeroHash, NothingToDo
|
return plumbing.ZeroHash, NothingToDo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,26 +101,30 @@ func Download(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func PushChanges(
|
func CreateRemote(
|
||||||
repo *git.Repository,
|
repo *git.Repository,
|
||||||
remote string,
|
remote string,
|
||||||
auth githttp.AuthMethod,
|
) (*git.Remote, error) {
|
||||||
) error {
|
newRemote, err := repo.Remote(DefaultRemoteName)
|
||||||
if _, err := repo.Remote(DefaultRemoteName); err != nil {
|
if err != nil {
|
||||||
log.Println("Creating new git remote " + DefaultRemoteName)
|
log.Println("Creating new git remote " + DefaultRemoteName)
|
||||||
if _, err = repo.CreateRemote(&config.RemoteConfig{
|
return repo.CreateRemote(&config.RemoteConfig{
|
||||||
Name: DefaultRemoteName,
|
Name: DefaultRemoteName,
|
||||||
URLs: []string{remote},
|
URLs: []string{remote},
|
||||||
}); err != nil {
|
})
|
||||||
log.Fatalf("%s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newRemote, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Push(
|
||||||
|
auth *githttp.BasicAuth,
|
||||||
|
repo *git.Repository,
|
||||||
|
) error {
|
||||||
return repo.Push(&git.PushOptions{
|
return repo.Push(&git.PushOptions{
|
||||||
RemoteName: DefaultRemoteName,
|
RemoteName: DefaultRemoteName,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -202,18 +205,22 @@ func main() {
|
||||||
|
|
||||||
tree.Clean(&git.CleanOptions{Dir: true})
|
tree.Clean(&git.CleanOptions{Dir: true})
|
||||||
|
|
||||||
if *push == true {
|
|
||||||
auth := &githttp.BasicAuth{
|
auth := &githttp.BasicAuth{
|
||||||
Username: *username,
|
Username: *username,
|
||||||
Password: *password,
|
Password: *password,
|
||||||
}
|
}
|
||||||
if err := PushChanges(repo, *remote, auth); err != nil {
|
|
||||||
|
CreateRemote(repo, *remote)
|
||||||
|
|
||||||
|
if *push == true {
|
||||||
|
if err := Push(auth, repo); err != nil {
|
||||||
if err == git.NoErrAlreadyUpToDate {
|
if err == git.NoErrAlreadyUpToDate {
|
||||||
log.Println("Already up-to-date")
|
log.Println("Already up-to-date")
|
||||||
} else {
|
} else {
|
||||||
log.Fatalf("%s", err)
|
log.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
log.Println("Pushed changes to remote")
|
log.Println("Pushed changes to remote")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue