git-difme

git do it for me - ricketyspace.net/git-difme
git clone git://git.ricketyspace.net/git-difme.git
Log | Files | Refs

commit 18f9aaf8e7c14ef42470c779d96aa56a1198560c
parent f944254dc1a12703981451e9a1c575ddd179591c
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon, 18 Jul 2016 23:57:18 +0000

file regex can be a rule.

* git-difme (build-stage-regex): remove function.
(difme-stage-commit?): new function.
(difme): use `difme-stage-commit?`
* README.org: add info about file regex as a rule.

Diffstat:
README.org | 26++++++++++++++++----------
git-difme.scm | 25++++++++++++++++---------
2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/README.org b/README.org @@ -18,12 +18,14 @@ it always does a =git push= on each repo that it visits. ** rules the rules specify what type of files to stage and commit. -file types: +a rule can either be a regex that matches a file or a file mod type. - - modified file (M). - - deleted file (D). - - untracked file (?). - - all files (.). +the following file mod types are recognized: + + - =M= :: modified file. + - =D= :: deleted file. + - =?= :: untracked file. + - =.= :: all files. the rules are defined per git repository in the config file. @@ -40,17 +42,21 @@ function: (define (difme-repos) (list '("/path/to/git/repo/foo" "M" "D" "?") '("/path/to/git/repo/bar" "M") - '("/path/to/git/repo/baz" "M" "?") - '("/path/to/git/repo/frb" "."))) + '("/path/to/git/repo/baz" ".") + '("/path/to/git/repo/frb" "\\.txt" "personal/log.org" "?") + '("/path/to/git/repo/dot" ".config/"))) #+END_SRC - for repo ~foo~, git-difme will stage and commit modified (M), deleted (D) and untracked (?) files. - for repo ~bar~, git-difme will only stage and commit modified (M) files. -- for repo ~baz~, git-difme will only stage and commit modified (M) and - untracked (?) files. -- for repo ~frb~, git-difme will stage and commit all files. +- for repo ~baz~, git-difme will stage and commit all files (.). +- for repo ~frb~, git-difme will stage and commit all files that have + =.txt= extension, file(s) whose path matches =personal/log.org=, and + all untracked files (?). +- for repo ~dot~, git-difme will stage and commit all files under the + =.config= directory. ** installing *** the script diff --git a/git-difme.scm b/git-difme.scm @@ -126,13 +126,21 @@ the commit message will be in the following format: (difme-exec cmd)))) ;;;; difme workers -(define (build-stage-regex rules) - "build stage regex based on RULES." - (let ((regex "^")) - (cond ((null? rules) (string-append regex "$")) - ((member "." rules) ".") - (else (string-append - regex "[" (string-concatenate rules) "]"))))) +(define (difme-stage-commit? file-info rules) + "return non-nil if file must be staged and commited; #f otherwise." + (let ((file-mod-type (car file-info)) + (file-path (cdr file-info))) + (define (mod-type? rule) + (member rule '("M" "D" "?" "."))) + (define (process rule) + (if (equal? rule ".") + rule + (string-append "^[" rule "]"))) + (define (match rule) + (if (mod-type? rule) + (if (string-match (process rule) file-mod-type) #t #f) + (if (string-match rule file-path) #t #f))) + (member #t (map match rules)))) (define (difme repo-info) "stage and commit relevant files in repo defined REPO-INFO. @@ -140,7 +148,6 @@ the commit message will be in the following format: also does `git push` to the repo' default upstream remote." (let* ((repo-path (car repo-info)) (rules (cdr repo-info)) - (stage-regex (build-stage-regex rules)) (msg "git-difme autocommit")) (define (commit-staged) (let ((msg (string-append msg " already staged file(s)."))) @@ -148,8 +155,8 @@ also does `git push` to the repo' default upstream remote." (define (process file-info) (let* ((mod-type (car file-info)) (file-path (cdr file-info)) - (if (string-match stage-regex type) (msg (string-append msg " [" mod-type "]."))) + (if (difme-stage-commit? file-info rules) (difme-stage-commit repo-path file-path msg)))) ;; first commit already staged files. (commit-staged)