1
0
mirror of https://github.com/danog/gift.git synced 2024-11-26 20:04:47 +01:00

Merge branch 'sync'

This commit is contained in:
sentientwaffle 2012-03-23 08:32:21 -06:00
commit 6e8567845e
4 changed files with 44 additions and 4 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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

View File

@ -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", ->