From 1846098db7a3f3802ac5c5caec171fc178b12979 Mon Sep 17 00:00:00 2001 From: Luke Plaster Date: Thu, 14 Mar 2013 23:51:42 +0000 Subject: [PATCH 01/11] for Travis: make use of Repo#identify to ensure that our repository has an identity set when running the #create_tag test --- test/repo.test.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/repo.test.coffee b/test/repo.test.coffee index a635994..2391cf0 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -235,10 +235,11 @@ describe "Repo", -> 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 + repo.identify new Actor('name', 'em@il'), -> + 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 From 3afe421d388cb088be30639b2cc0edb1f5d08cc2 Mon Sep 17 00:00:00 2001 From: Luke Plaster Date: Sun, 17 Mar 2013 15:35:37 +0000 Subject: [PATCH 02/11] [README] #status, #identity and #identify --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d4df787..44ae6ca 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A simple Node.js wrapper for the Git CLI. The API is based on # API git = require 'gift' - + repo = git "path/to/repo" # => # @@ -57,6 +57,16 @@ Get the difference between the trees. The callback receives `(err, diffs)`. +### `Repo#identity(callback)` +Get the commit identity for this repository. + +The callback receives `(err, actor)`, where `actor` is an Actor. + +### `Repo#identify(actor, callback)` +Set your account's default identity for commits to this repository. + +The callback receives `(err)`. + ### `Repo#remotes(callback)` Get the repository's remotes. @@ -73,9 +83,8 @@ Equivalent to `git remote add `. ### `Repo#remote_fetch(name, callback)` `git fetch ` - ### `Repo#status(callback)` -The callback receives `(err, status)`. +Uses `--porcelain` to parse repository status in a way that is agnostic of system language. The callback receives `(err, status)`. See below for a definition of what `status` is. ### `Repo#create_branch(name, callback)` Create a new branch with `name`, and call the callback when complete From cf01b461d45eab8e6d75d29a78593d5a6f86fc12 Mon Sep 17 00:00:00 2001 From: Luke Plaster Date: Sun, 17 Mar 2013 15:38:44 +0000 Subject: [PATCH 03/11] [README] #remote_remove and #remote_push --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 44ae6ca..8ed4cf6 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,15 @@ Get the string names of each of the remotes. ### `Repo#remote_add(name, url, callback)` Equivalent to `git remote add `. +### `Repo#remote_remove(name, callback)` +Remove a remote. + ### `Repo#remote_fetch(name, callback)` `git fetch ` +### `Repo#remote_push(name, callback)` +`git push ` + ### `Repo#status(callback)` Uses `--porcelain` to parse repository status in a way that is agnostic of system language. The callback receives `(err, status)`. See below for a definition of what `status` is. From eed147cdc5232517ee2e0874fb0ca6aed4bfaf81 Mon Sep 17 00:00:00 2001 From: Luke Plaster Date: Sun, 17 Mar 2013 15:44:20 +0000 Subject: [PATCH 04/11] [README] #sync --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 8ed4cf6..c0f5027 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,16 @@ Commit some changes. ### `Repo#checkout(treeish, callback)` `git checkout ` +### `Repo#sync([remote_name, ]branch, callback)` +Sync the current branch with the remote, keeping all local changes intact. + +The following steps are carried out: `stash`, `pull`, `push`, `stash pop`. If there were no changes to stash, the last `stash pop` is not executed. + + * `remote_name` - `String` + * `branch` - `String` + * `callback` - Receives `(err)`. + + ## Commit ### `Commit#id` `String` - The commit's SHA. From 4b4c8030c8174cfe02ad26c7ef16676388084fd8 Mon Sep 17 00:00:00 2001 From: Luke Plaster Date: Sun, 17 Mar 2013 17:00:22 +0000 Subject: [PATCH 05/11] locked down the signature of Repo#sync with unit tests and an accurate representation in the README --- README.md | 8 ++++---- package.json | 1 + src/repo.coffee | 18 +++++++++++++----- test/repo.test.coffee | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c0f5027..e31eca0 100644 --- a/README.md +++ b/README.md @@ -143,14 +143,14 @@ Commit some changes. ### `Repo#checkout(treeish, callback)` `git checkout ` -### `Repo#sync([remote_name, ]branch, callback)` +### `Repo#sync([[remote, ]branch, ]callback)` Sync the current branch with the remote, keeping all local changes intact. The following steps are carried out: `stash`, `pull`, `push`, `stash pop`. If there were no changes to stash, the last `stash pop` is not executed. - * `remote_name` - `String` - * `branch` - `String` - * `callback` - Receives `(err)`. + * `remote` - `String` (defaults to `origin`). + * `branch` - `String` (defaults to `master`). + * `callback` - Receives `(err)`. ## Commit diff --git a/package.json b/package.json index b90e05c..b5bd4a8 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ , "devDependencies": { "should": "1.2.x" , "mocha": "1.x.x" + , "sinon": "1.6.x" , "coffee-script": "1.6.x" } diff --git a/src/repo.coffee b/src/repo.coffee index 89b7523..7922dfd 100644 --- a/src/repo.coffee +++ b/src/repo.coffee @@ -299,18 +299,26 @@ module.exports = class Repo # Public: Sync the current branch with the remote. # + # Arguments: ([[remote_name, ]branch_name, ]callback) + # + # remote_name - String (optional). + # branch_name - String. # callback - Receives `(err)`. # - sync: (remote_name, branch, callback) -> - [remote_name, callback, branch] = ['origin', branch, remote_name] if !callback - [remote_name, callback, branch] = ['origin', remote_name, []] if !branch + sync: (remote_name, branch_name, callback) -> + + # handle 'curried' arguments + [remote, branch] = [remote_name, branch_name] if typeof callback is "function" + [remote, branch, callback] = ["origin", remote_name, branch_name] if typeof branch_name is "function" + [remote, branch, callback] = ["origin", "master", remote_name] if typeof remote_name is "function" + @status (err, status) => return callback err if err @git "stash", {}, ["save"], (err) => return callback err if err - @git "pull", {}, [remote_name, branch], (err) => + @git "pull", {}, [remote, branch], (err) => return callback err if err - @git "push", {}, [remote_name, branch], (err) => + @git "push", {}, [remote, branch], (err) => return callback err if err if not status?.clean @git "stash", {}, ["pop"], (err) => diff --git a/test/repo.test.coffee b/test/repo.test.coffee index 2391cf0..1fe7c0c 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -1,4 +1,5 @@ should = require 'should' +sinon = require 'sinon' fs = require 'fs' fixtures = require './fixtures' git = require '../src' @@ -13,6 +14,43 @@ Status = require '../src/status' {exec} = require 'child_process' describe "Repo", -> + describe "#sync", -> + describe "when passed curried arguments", -> + repo = fixtures.branched + remote = branch = "" + + before -> + sinon.stub repo, "git", (command, opts, args, callback) -> + if command is "pull" + remote = args[0] + branch = args[1] + callback? null + sinon.stub repo, "status", (callback) -> + callback? null, clean: no + + after -> + repo.git.restore() + repo.status.restore() + + it "passes through the correct parameters when nothing is omitted", (done) -> + repo.sync "github", "my-branch", -> + remote.should.eql "github" + branch.should.eql "my-branch" + done() + + it "passes through the correct parameters when remote_name is omitted", (done) -> + repo.sync "my-branch", -> + remote.should.eql "origin" + branch.should.eql "my-branch" + done() + + it "passes through the correct parameters when remote_name and branch are omitted", (done) -> + repo.sync -> + remote.should.eql "origin" + branch.should.eql "master" + done() + + describe "#identify", -> describe "when asked to set the identity's name and email", -> repo = fixtures.branched From 9503fc8208cf0f234bb159579519d8d1f692f0e8 Mon Sep 17 00:00:00 2001 From: sentientwaffle Date: Wed, 24 Jul 2013 07:04:41 -0700 Subject: [PATCH 06/11] bump to 0.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5bd4a8..50bbf9d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "gift" -, "version": "0.0.5" +, "version": "0.0.6" , "description": "a Git wrapper library" , "keywords": ["git"] , "homepage": "https://github.com/sentientwaffle/gift" From a197fe7ba071490d8d5406bf2657456c5964be12 Mon Sep 17 00:00:00 2001 From: Sergey Kovalyov Date: Mon, 23 Sep 2013 18:19:19 +0200 Subject: [PATCH 07/11] Git.clone() added * Wrapper for `git clone` command. * Test added and custom 30000 timeout is set to it as cloning requires quite some time. * Documentation updated. --- README.md | 9 +++++++++ src/index.coffee | 12 ++++++++++++ test/index.test.coffee | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/README.md b/README.md index e31eca0..336eadb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,15 @@ A simple Node.js wrapper for the Git CLI. The API is based on repo = git "path/to/repo" # => # + +Clone a repository: + + git = require 'gift' + + git.clone "git@host:path/to/remote/repo.git", "path/to/local/clone/repo", (err, _repo) -> + repo = _repo + # => # + ## Repo ### `Repo#path` `String` - The path to the repository. diff --git a/src/index.coffee b/src/index.coffee index 42ea7fb..1e4aa8c 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -18,3 +18,15 @@ Git.init = (path, callback) -> , (err, stdout, stderr) -> return callback err if err return callback err, (new Repo path) + +# Public: Clone a git repository. +# +# repository - The repository to clone from. +# path - The directory to clone into. +# callback - Receives `(err, repo)`. +# +Git.clone = (repository, path, callback) -> + bash = "git clone #{repository} #{path}" + exec bash, (err, stdout, stderr) -> + return callback err if err + return callback err, (new Repo path) \ No newline at end of file diff --git a/test/index.test.coffee b/test/index.test.coffee index 784bf44..25342b3 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -1,6 +1,7 @@ should = require 'should' git = require '../src' Repo = require '../src/repo' +{exec} = require 'child_process' describe "git", -> describe "()", -> @@ -8,3 +9,19 @@ describe "git", -> it "returns a Repo", -> repo.should.be.an.instanceof Repo + + describe "clone()", -> + @timeout 30000 + repo = null + newRepositoryDir = "#{__dirname}/fixtures/clone" + before (done) -> + git.clone "git@github.com:sentientwaffle/gift.git", newRepositoryDir, (err, _repo) -> + repo = _repo + done err + it "clone a repository", (done) -> + repo.should.be.an.instanceof Repo + repo.remote_list (err, remotes) -> + remotes.should.have.length 1 + done() + after (done) -> + exec "rm -rf #{newRepositoryDir}", done \ No newline at end of file From b71c18f93eeb313db6b7075066147b153c5d2b0e Mon Sep 17 00:00:00 2001 From: Sergey Kovalyov Date: Mon, 23 Sep 2013 18:20:31 +0200 Subject: [PATCH 08/11] Git.init() extended with bare parameter * When bare parameter is set to true, bare repository is initialized. * Tests added for bare and non-bare initialization. * Documentaiton updated. --- README.md | 17 +++++++++++++++++ src/index.coffee | 12 +++++++++--- test/index.test.coffee | 32 +++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 336eadb..7568f4f 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,28 @@ A simple Node.js wrapper for the Git CLI. The API is based on # API +For existing repositories: + git = require 'gift' repo = git "path/to/repo" # => # +Initialize a new repository: + + git = require 'gift' + + git.init "path/to/repo", (err, _repo) -> + repo = _repo + # => # + +Initialize a new bare repository: + + git = require 'gift' + + git.init "path/to/bare/repo", true, (err, _repo) -> + repo = _repo + # => # Clone a repository: diff --git a/src/index.coffee b/src/index.coffee index 1e4aa8c..927b70e 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -11,13 +11,19 @@ module.exports = Git = (path, bare=false) -> # Public: Initialize a git repository. # # path - The directory to run `git init .` in. +# bare - Create a bare repository when true. # callback - Receives `(err, repo)`. # -Git.init = (path, callback) -> - exec "git init .", {cwd: path} +Git.init = (path, bare, callback) -> + [bare, callback] = [callback, bare] if !callback + if bare + bash = "git init --bare ." + else + bash = "git init ." + exec bash, {cwd: path} , (err, stdout, stderr) -> return callback err if err - return callback err, (new Repo path) + return callback err, (new Repo path, bare) # Public: Clone a git repository. # diff --git a/test/index.test.coffee b/test/index.test.coffee index 25342b3..5fbfdee 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -1,15 +1,45 @@ should = require 'should' git = require '../src' Repo = require '../src/repo' +fs = require "fs" {exec} = require 'child_process' describe "git", -> describe "()", -> repo = git "#{__dirname}/fixtures/simple" - it "returns a Repo", -> repo.should.be.an.instanceof Repo + describe "init()", -> + repo = null + newRepositoryDir = "#{__dirname}/fixtures/new" + before (done) -> + fs.mkdirSync newRepositoryDir + git.init newRepositoryDir, (err, _repo) -> + repo = _repo + done err + it "inits a Repo", -> + repo.should.be.an.instanceof Repo + bare = repo.bare || false + bare.should.be.false + after (done) -> + exec "rm -rf #{newRepositoryDir}", done + + describe "init() bare", -> + repo = null + newRepositoryDir = "#{__dirname}/fixtures/bare" + before (done) -> + fs.mkdirSync newRepositoryDir + git.init newRepositoryDir, true, (err, _repo) -> + repo = _repo + done err + it "inits a bare Repo", -> + repo.should.be.an.instanceof Repo + bare = repo.bare || false + bare.should.be.true + after (done) -> + exec "rm -rf #{newRepositoryDir}", done + describe "clone()", -> @timeout 30000 repo = null From 0d951d75d4471359bb172117dbbbfb19cffdefe1 Mon Sep 17 00:00:00 2001 From: Sergey Kovalyov Date: Tue, 24 Sep 2013 10:37:19 +0200 Subject: [PATCH 09/11] Disable Git.clone() test This test fails on Travis as cloning from GitHub requires accepting the host authenticity, expects user input and eventually fails on timeout. It makes sense to uncomment this test only locally. --- test/index.test.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/index.test.coffee b/test/index.test.coffee index 5fbfdee..bb2ae85 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -40,6 +40,7 @@ describe "git", -> after (done) -> exec "rm -rf #{newRepositoryDir}", done + ### describe "clone()", -> @timeout 30000 repo = null @@ -54,4 +55,5 @@ describe "git", -> remotes.should.have.length 1 done() after (done) -> - exec "rm -rf #{newRepositoryDir}", done \ No newline at end of file + exec "rm -rf #{newRepositoryDir}", done + ### \ No newline at end of file From 3a197a43d5d8cb04c88a3369c33af5ca71dbf146 Mon Sep 17 00:00:00 2001 From: djg Date: Fri, 11 Oct 2013 14:53:10 -0700 Subject: [PATCH 10/11] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e31eca0..d77948c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Gift +### Not active, see [this fork](https://github.com/notatestuser/gift) + [![Build Status](https://secure.travis-ci.org/sentientwaffle/gift.png?branch=master)](http://travis-ci.org/sentientwaffle/gift) A simple Node.js wrapper for the Git CLI. The API is based on From ae25cf4d40ad7f0aaa25c23915258221b8836574 Mon Sep 17 00:00:00 2001 From: Sergey Kovalyov Date: Sat, 12 Oct 2013 13:46:45 +0200 Subject: [PATCH 11/11] Clone using HTTPS to avoid authentication prompt --- test/index.test.coffee | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/index.test.coffee b/test/index.test.coffee index bb2ae85..f7c8cfc 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -40,13 +40,12 @@ describe "git", -> after (done) -> exec "rm -rf #{newRepositoryDir}", done - ### describe "clone()", -> @timeout 30000 repo = null newRepositoryDir = "#{__dirname}/fixtures/clone" before (done) -> - git.clone "git@github.com:sentientwaffle/gift.git", newRepositoryDir, (err, _repo) -> + git.clone "https://github.com/notatestuser/gift.git", newRepositoryDir, (err, _repo) -> repo = _repo done err it "clone a repository", (done) -> @@ -55,5 +54,4 @@ describe "git", -> remotes.should.have.length 1 done() after (done) -> - exec "rm -rf #{newRepositoryDir}", done - ### \ No newline at end of file + exec "rm -rf #{newRepositoryDir}", done \ No newline at end of file