Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow commits to be created without index #63

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
23 changes: 14 additions & 9 deletions lib/bindings/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ Gitteh.error.GIT_ENOTIMPLEMENTED = undefined;
Repository.prototype.getCommit = function(sha1, callback) {};

/**
* Creates a new Commit and immediately stores it in the Repository.
* @param {Object} data The data for the commit. Should be the same properties that a {@link Commit} contains.
* @param {Function} [callback] If provided, the Commit will be created asynchronously, and the newly created Commit object returned to the callback.
* @throws If Commit couldn't be created.
* Creates a new {@link Commit} and immediately stores it in the Repository.
* @param {Object} data The data for the commit. Should be the same properties that a {@link Commit} contains, but without id.
* @param {Function} [callback] The id of the newly created Commit is returned to the callback.
*/
Repository.prototype.createCommit = function(data, callback) {};

Expand All @@ -203,12 +202,11 @@ Repository.prototype.createCommit = function(data, callback) {};
Repository.prototype.getTree = function(sha1, callback) {};

/**
* Creates a new {@link Tree} in the Repository with the given data. <b>NOTE:</b>
* this is currently unimplemented.
* @param {Object} data
* @param {Function} [callback]
* Creates a new {@link Tree} in the Repository with the given entries.
* @param {Array} entries A list of file-entries from which to create the tree. Each entry should have a name, id (of the blob object) and mode. The mode should be any of the values 0040000, 0100644, 0100755, 0120000 or 0160000.
* @param {Function} [callback] The id of the newly created Tree is returned to the callback.
*/
Repository.prototype.createTree = function(data, callback) {};
Repository.prototype.createTree = function(entries, callback) {};

/**
* Retrieves a {@link Reference} from the Repository with the given name.
Expand Down Expand Up @@ -307,6 +305,13 @@ Repository.prototype.getTag = function(sha1, callback) {};
*/
Repository.prototype.createBlob = function(data, callback) {};

/**
* Creates a new {@link Blob} in the Repository.
* @param {String} path The path to a file from which data will be made into the Blob.
* @param {Function} [callback] The id of the newly created Blob is returned to the callback.
*/
Repository.prototype.createBlobFromDisk = function(path, callback) {};

/**
* Retrieves a Blob from the Repository with given id.
* @param {String} sha1 The sha1 hash id of the blob.
Expand Down
8 changes: 7 additions & 1 deletion src/args.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ fn.validators =
return objectTypes.indexOf val > -1

remoteDir: (val) ->
return remoteDirs.indexOf val > -1
return remoteDirs.indexOf val > -1

array: (val) ->
return val instanceof Array

object: (val) ->
return typeof val is "object"
70 changes: 67 additions & 3 deletions src/gitteh.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Gitteh.Tree = class Tree
* **id**: *(String)* OID this entry points to.
* **name**: *(String)* file name of this entry.
* **type**: *(String)* kind of object pointed to by this entry
* **attributes**: *(Number)* UNIX file attributes for this entry.
* **filemode**: *(Number)* UNIX file filemode for this entry.
###

constructor: (@repository, obj) ->
Expand All @@ -200,7 +200,7 @@ Gitteh.Tree = class Tree
.set("id")
.set("name")
.set("type")
.set("attributes")
.set("filemode")
_immutable(@, obj)
.set("id")
.set("entries")
Expand Down Expand Up @@ -580,6 +580,70 @@ Gitteh.Repository = class Repository
_priv.native.createRemote name, url, _wrapCallback cb, (remote) =>
return cb null, new Remote @, remote

createBlobFromDisk: ->
###
Creates a new Blob for this repository from the file-content loaded
from `path`. Calls `cb` when the operation has completed.
###
_priv = _getPrivate @
[path, cb] = args
path: type: "string"
cb: type: "function"
_priv.native.createBlobFromDisk path, _wrapCallback cb, (blob) =>
return cb null, blob

createBlobFromBuffer: ->
###
Creates a new Blob for this repository from the data supplied
as `buffer`. Calls `cb` when the operation has completed.
###
_priv = _getPrivate @
[buffer, cb] = args
buffer: type: "object"
cb: type: "function"
_priv.native.createBlobFromBuffer buffer, _wrapCallback cb, (blob) =>
return cb null, blob

createTree: ->
###
Creates a new Tree for this repository from the `entities`
that contain the content (as a blob), the name and the filemode
of the tree-entities that will be in the new Tree.
Calls `cb` when the operation has completed.
###
_priv = _getPrivate @
[entities, cb] = args
entities: type: "array"
cb: type: "function"
_priv.native.createTree entities, _wrapCallback cb, (tree) =>
return cb null, tree

createCommit: ->
###
Creates a new Commit for this repository from `data`.
`data` should contain the following keys:

* **updateref**: updates this reference to the new commit. (optional, default: do not update any refs)
* **author**: a signature of the author (optional, default: committer is used)
* **committer**: a signature of the committer
* **message**: the message of the commit
* **tree**: the id of a tree object
* **parents**: an array of parents.

A signature has the following keys:

* **name**: the name of the author/committer
* **email**: the email of the author/committer
* **time**: the time of the commit (optional)
* **offset**: timezone offset of the commit-time (optional)
###
_priv = _getPrivate @
[data, cb] = args
data: type: "object"
cb: type: "function"
_priv.native.createCommit data, _wrapCallback cb, (commit) =>
return cb null, commit

###*
* Alias of {@link #reference}.
* @param {String} oid id of reference to be fetched.
Expand Down Expand Up @@ -691,7 +755,7 @@ Gitteh.clone = =>
else if entry.type is "blob"
repo.blob entry.id, _wrapCallback cb, (blob) ->
file = fs.createWriteStream _path.join(dest, entry.name),
mode: entry.attributes
mode: entry.filemode
file.write blob.data
file.end()
cb()
Expand Down
Loading