Browse files

use-git

  • Loading branch information...
1 parent 93b5d16 commit a4ddfc9ae60e19a7dbf8134657a08f9c27cbf5c4 @awwx committed Jun 9, 2011
Showing with 61 additions and 6 deletions.
  1. +13 −3 git.arc
  2. +20 −3 git.t
  3. +4 −0 use-git.arc
  4. +24 −0 use-git.t
View
16 git.arc
@@ -10,6 +10,7 @@
(subst "__" "_" hack)))))
(def parse-git-spec (spec)
+ (zap string spec)
(and (begins spec "git://")
(iflet p (pos [in _ #\: #\!] spec 6)
(with (repo (cut spec 0 p)
@@ -35,20 +36,29 @@
(zap git-spec git)
(or git!revision "master"))
-(def git-path (git)
+(def git-dir (git)
(path (filenamize (cut git!repo 6))
(filenamize (git-revision git))))
(def gitcmd args
- (apply check-system "/usr/bin/git" args))
+ (w/stdout stderr
+ (apply check-system "/usr/bin/git" args)))
(def git-repo (git)
(zap git-spec git)
- (ret gitdir (path git-cachedir* (git-path git))
+ (ret gitdir (path git-cachedir* (git-dir git))
(unless (dir-exists gitdir)
(let dir (dirpart gitdir)
(ensure-dir dir)
(w/cwd dir
(gitcmd "clone" "--no-checkout" git!repo (filepart gitdir)))
(w/cwd gitdir
(gitcmd "checkout" "-q" (git-revision git)))))))
+
+(def git-filepath (git)
+ (zap git-spec git)
+ (path (git-repo git) git!file))
+
+(def git-pull (git)
+ (w/cwd (git-repo git)
+ (gitcmd "pull")))
View
23 git.t
@@ -1,4 +1,4 @@
-(use test test-by-example path)
+(use test test-by-example path cwd)
(example-test (runtime '(print-table git)) #<<.
@@ -20,7 +20,7 @@ nil
> (parse-git-spec "git://github.com/nex3/arc.git!arcc:arcc/ac.arc")
#table((file "arcc/ac.arc") (repo "git://github.com/nex3/arc.git") (revision "arcc"))
-> (git-path (parse-git-spec "git://github.com/nex3/arc.git!arcc"))
+> (git-dir (parse-git-spec "git://github.com/nex3/arc.git!arcc:arcc/ac.arc"))
"github.com_nex3_arc.git/arcc"
.
@@ -42,4 +42,21 @@ nil
repo)
(testis
(filechars (path repo "foo"))
- "version 1\n"))))
+ "version 1\n"))
+
+ (testis (r!git-filepath "git://github.com/awwx/for-testing.git:foo")
+ (path testdir "git/github.com_awwx_for-testing.git/master/foo"))
+
+ (testis (~~file-exists (r!git-filepath "git://github.com/awwx/for-testing.git:bar.arc"))
+ t)
+
+ (w/cwd (r!git-repo "git://github.com/awwx/for-testing.git")
+ (system "git reset --hard HEAD^"))
+
+ (testis (~~file-exists (r!git-filepath "git://github.com/awwx/for-testing.git:bar.arc"))
+ nil)
+
+ (r!git-pull "git://github.com/awwx/for-testing.git")
+
+ (testis (~~file-exists (r!git-filepath "git://github.com/awwx/for-testing.git:bar.arc"))
+ t)))
View
4 use-git.arc
@@ -0,0 +1,4 @@
+(use git)
+
+(defrule use-load (parse-git-spec item)
+ (usepath* (cons (git-repo it) (usepath*))))
View
24 use-git.t
@@ -0,0 +1,24 @@
+(use test-by-example test path)
+
+(w/testdir
+ (let dir (path testdir "git")
+
+ (let r (runtime '(use-git))
+ (= r!git-cachedir* dir)
+ (example-test r #<<.
+
+> (use "git://github.com/awwx/for-testing.git" bar)
+prints: hello, this is bar\n
+
+.
+ ))
+
+ (let r (runtime '(use-git))
+ (= r!git-cachedir* dir)
+ (example-test r #<<.
+
+> (use "git://github.com/awwx/for-testing.git" bar)
+prints: hello, this is bar\n
+
+.
+ ))))

0 comments on commit a4ddfc9

Please sign in to comment.