Giter Site home page Giter Site logo

clj-git's Introduction

Dependencies

Only Clojure and contrib. Either modify build.xml or use -Dclojure.jar=... and -Dclojure.contrib.jar=... when running ant.

At runtime this library requires git to be on the path.

What is it?

This is a Clojure front-end to git. Right now only low-level operations are included; this is enough to allow very basic serialization of data into Git's object store.

Examples

user=> (use 'com.twinql.clojure.git)  
nil

;; List refs and their commits -- returns a map.
;; with-repo is only necessary if your working directory is not the 
;; repo you want to access.
user=> (with-repo "." (refs->commits))
{"refs/remotes/origin/master" "eca2ada9fb79c50a0404e9fef4c0255f2fbe8a30",
 "refs/heads/master" "eca2ada9fb79c50a0404e9fef4c0255f2fbe8a30"}

;; Fetch the commit for a single ref.
user=> (ref->commit "refs/remotes/origin/master")
"eca2ada9fb79c50a0404e9fef4c0255f2fbe8a30"

user=> (object-type "eca2ada9fb79c50a0404e9fef4c0255f2fbe8a30")
"commit"

user=> (object-size "eca2ada9fb79c50a0404e9fef4c0255f2fbe8a30")
235

;; Let's write in an object.
user=> (with-repo "/tmp/raw"
  (hash-object-from-string "Hello, world!" nil :write false))                 
"5dd01c177f5d7d1be5346a5bc18a569a7410c2ef"

user=> (with-repo "/tmp/raw"
  (cat-object "5dd01c177f5d7d1be5346a5bc18a569a7410c2ef"))
"Hello, world!"

;; Make a tree and commit it.
user=> (with-repo "/tmp/raw"
  (make-tree [[nil "blob" "5dd01c177f5d7d1be5346a5bc18a569a7410c2ef" "some-file"]]))
"1a4d231af53de9164b03296a4dcc18e2fcd715c6"

user=> (with-repo "/tmp/raw"
  (commit-tree *1 (ref->commit "refs/heads/master") "Author" "Committer" "Test commit."))
"f8455ab747e18e8bba7b14acbd92dcbf8c15b5fa"

;; Now update the ref.
user=> (with-repo "/tmp/raw" 
  (update-ref "refs/heads/master" *1))
""

;; TADA!
user=> (with-repo "/tmp/raw" (ref->commit "refs/heads/master"))
"f8455ab747e18e8bba7b14acbd92dcbf8c15b5fa"

;; Fetch file contents for the tree identified by the head.
user=> (with-repo "/tmp/raw"
  (tree-contents
    ((comp commit->tree ref->commit) "refs/heads/master")
    blob?))
{"some-file" "Hello, world!"}

clj-git's People

Contributors

rnewman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.