diff --git a/history/information.go b/history/information.go index 7bd55e4..ef60b32 100644 --- a/history/information.go +++ b/history/information.go @@ -82,6 +82,12 @@ func RecentChanges(n int) string { return templates.RecentChangesHTML(entries, n) } +// FileChanged tells you if the file has been changed. +func FileChanged(path string) bool { + _, err := gitsh("diff", "--exit-code", path) + return err != nil +} + // Revisions returns slice of revisions for the given hypha name. func Revisions(hyphaName string) ([]Revision, error) { var ( diff --git a/history/operations.go b/history/operations.go index e788b6e..a8177ba 100644 --- a/history/operations.go +++ b/history/operations.go @@ -109,6 +109,12 @@ func (hop *HistoryOp) Apply() *HistoryOp { return hop } +// Abort aborts the history operation. +func (hop *HistoryOp) Abort() *HistoryOp { + gitMutex.Unlock() + return hop +} + // WithMsg sets what message will be used for the future commit. If user message exceeds one line, it is stripped down. func (hop *HistoryOp) WithMsg(userMsg string) *HistoryOp { for _, ch := range userMsg { diff --git a/hypha.go b/hypha.go index 64015e8..be355b4 100644 --- a/hypha.go +++ b/hypha.go @@ -88,6 +88,9 @@ func uploadHelp(hop *history.HistoryOp, hyphaName, ext string, data []byte, u *u hyphae.IncrementCount() } *originalFullPath = fullPath + if hop.Type == history.TypeEditText && !history.FileChanged(fullPath) { + return hop.Abort() + } return hop.WithFiles(fullPath). WithUser(u). Apply()