From f4c2f49a8621d85de3512288125a27c69f259be2 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 10 Jul 2016 02:40:33 +0000 Subject: add functions that provides a git interface. * git-difme.scm (stage-files, difme-status, difme-stage, difme-commit, difme-push): new functions. --- git-difme.scm | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'git-difme.scm') diff --git a/git-difme.scm b/git-difme.scm index bc999da..d696085 100644 --- a/git-difme.scm +++ b/git-difme.scm @@ -53,6 +53,70 @@ function." (load-config path) (eval '(difme-repos) (interaction-environment)))) +;;;; git interfaces +(define (staged-files repo) + "return list of staged files in REPO." + (let ((cmd "git diff --name-only --cached")) + (with-directory-excursion repo + (difme-exec cmd)))) + +(define (difme-status repo) + "do `git status` on the REPO and return output as a list. + +if the output from `git status` is: + + M .asoundrc + D .config/i3/config + +the returned list will be in the following format: + + ((\"M\" . \".asoundrc\") (\"D\" . \".config/i3/config\")) + +if there is no output from `git status`, then an empty list will be +returned." + (let ((cmd "git status --porcelain")) + (define (process line) + (let* ((parts (string-split line #\space)) + (type (car parts)) + (file (cadr parts))) + (cons type file))) + (with-directory-excursion repo + (map process (difme-exec cmd))))) + +(define (difme-stage repo file) +"stage FILE in REPO." + (let ((cmd (string-append "git add " file))) + (with-directory-excursion repo + (difme-exec cmd)))) + +(define (difme-commit repo msg) +"do `git commit` on REPO. + +the commit message will be MSG followed by a list of files staged for +this commit. + +if files `foo.org`, `bar.scm` and `frob.el` are staged for the commit, +the commit message will be in the following format: + + MSG + + files: + - foo.org + - bar.scm + - frob.el" + (let* ((msg (string-append + msg "\n\nfiles:\n - " + (string-join (staged-files repo) "\n - "))) + (cmd (string-append "git commit -m '" msg "'"))) + (with-directory-excursion repo + (difme-exec cmd)))) + +(define (difme-push repo) + "do `git push` REPO to its default upstream remote." + (let ((cmd "git push")) + (with-directory-excursion repo + (difme-exec cmd)))) + ;;;; main (define (main srcs) srcs) -- cgit v1.2.3