~laumann/acme-git

35b4e59139e1bbedc712efc396ecf2132c8a2ee9 — Thomas Bracht Laumann Jespersen 2 years ago 7fffba8
Do full on commit from within Acme!

This commit was authored from within the Acme Git integration. That
means I:

 * Typed "Git" in a tag somewhere
 * Middle-clicked on "Commit" after adding files to the index
 * A buffer popped open in Acme in which I typed this very message
1 files changed, 44 insertions(+), 7 deletions(-)

M Git.go
M Git.go => Git.go +44 -7
@@ 16,10 16,9 @@ func wipe() {
	win.Write("data", nil)
}

func status() {
func gitcmd(arg ...string) {
	wipe()

	cmd := exec.Command("git", "status")
	cmd := exec.Command("git", arg...)
	r, w, err := os.Pipe()
	if err != nil {
		log.Fatal(err)


@@ 46,6 45,14 @@ func status() {
	}
}

func diff() {
	gitcmd("diff")
}

func status() {
	gitcmd("status")
}

func commit() {
	// I can see a couple of ways to implement "commit". (1) Open another buffer
	// to hold the commit message, and when closing that buffer capture the content


@@ 54,8 61,34 @@ func commit() {
	wipe()
	// Call mktemp, get the file name
	// Run the following:
	// GIT_EDITOR=./acme-ed.sh git commit -e -F /tmp/tmp.RS2v3ssoXL
}
	// GIT_EDITOR=./acme-ed.sh git commit
	// Our "editor" will be acme-ed, that pops open the file provided by git and monitors the index (or the events?) to exit only when the commit message buffer gets closed.

	cmd := exec.Command("git", "commit")
	r, w, err := os.Pipe()
	if err != nil {
		log.Fatal(err)
	}
	cmd.Stdout = w
	cmd.Stderr = w

	cmd.Env = append(os.Environ(), "GIT_EDITOR=acme-ed.sh")
	err = cmd.Start()
	w.Close()
	if err != nil {
		r.Close()
		win.Fprintf("data", "(exec: %s)\n", err)
	}
	buf := make([]byte, 4096)
	for {
		n, err := r.Read(buf)
		if err != nil {
			break
		}
		if n > 0 {
			win.Write("data", buf)
		}
	}}

func main() {
	var err error


@@ 70,7 103,6 @@ func main() {
	win.Ctl("clean")

	win.Fprintf("tag", "Status Diff Log Commit")
	//win.Fprintf("body", "PLACEHOLDER")

	go events()
	r, err := acme.Log()


@@ 83,8 115,9 @@ func main() {
			log.Fatal(err)
		}
		if ev.Op == "put" {
			fmt.Println("Saved!")
			; //fmt.Println("Saved!")
		}
		//fmt.Printf("%+v\n", ev)
	}
}



@@ 98,6 131,10 @@ func events() {
				win.Ctl("delete")
			case "Status":
				status()
			case "Diff":
				diff()
			case "Commit":
				commit()
			default:
				fmt.Println(text)
			}