diff --git a/package.json b/package.json index a52867e..9ad3f85 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "gift" -, "version": "0.0.2" +, "version": "0.0.3" , "description": "a Git wrapper library" , "keywords": ["git"] , "homepage": "https://github.com/sentientwaffle/gift" diff --git a/src/index.coffee b/src/index.coffee index 77d72c9..42ea7fb 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -14,7 +14,7 @@ module.exports = Git = (path, bare=false) -> # callback - Receives `(err, repo)`. # Git.init = (path, callback) -> - exec "git init .", {cwd: git_dir} + exec "git init .", {cwd: path} , (err, stdout, stderr) -> return callback err if err return callback err, (new Repo path) diff --git a/src/repo.coffee b/src/repo.coffee index fbbb2b1..b4101d4 100644 --- a/src/repo.coffee +++ b/src/repo.coffee @@ -132,10 +132,13 @@ module.exports = class Repo # Public: Create a tag. # # name - String + # options - An Object of command line arguments to pass to + # `git tag` (optional). # callback - Receives `(err)`. # - create_tag: (name, callback) -> - @git "tag", {a: name}, callback + create_tag: (name, options, callback) -> + [options, callback] = [callback, options] if !callback + @git "tag", options, [name], callback # Public: Delete the tag. # @@ -228,3 +231,19 @@ module.exports = class Repo # Public: Revert the given commit. revert: (sha, callback) -> @git "revert", {}, sha, callback + + + # Public: Sync the current branch with the remote. + # + # callback - Receives `(err)`. + # + sync: (callback) -> + @git "stash", {}, ["save"], (err) => + return callback err if err + @git "pull", {}, branch, (err) => + return callback err if err + @git "push", (err) => + return callback err if err + @git "stash", {}, "pop", (err) => + return callback err if err + return callback null diff --git a/test/repo.test.coffee b/test/repo.test.coffee index 6295488..74da4b7 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -1,4 +1,5 @@ should = require 'should' +fs = require 'fs' fixtures = require './fixtures' git = require '../src' Commit = require '../src/commit' @@ -8,6 +9,7 @@ Tag = require '../src/tag' Status = require '../src/status' {Ref, Head} = require '../src/ref' +{exec} = require 'child_process' describe "Repo", -> describe "#commits", -> @@ -199,6 +201,25 @@ describe "Repo", -> tags.should.eql [] done err + describe "#create_tag", -> + repo = null + git_dir = __dirname + "/fixtures/junk_create_tag" + before (done) -> + fs.mkdir git_dir, 0755, (err) -> + return done err if err + git.init git_dir, (err) -> + return done err if err + repo = git(git_dir) + fs.writeFileSync "#{git_dir}/foo.txt", "cheese" + repo.add "#{git_dir}/foo.txt", (err) -> + return done err if err + repo.commit "initial commit", {all: true}, done + + after (done) -> + exec "rm -rf #{ git_dir }", done + + it "creates a tag", (done) -> + repo.create_tag "foo", done describe "#delete_tag", -> describe "deleting a tag that does not exist", ->