var fs = require("fs");
var path = require("path");

var _ = require("lodash");
var Bacon = require("baconjs");

var shell = require("shelljs");
var exec = shell.exec;
var rm = shell.rm;

var repo = "git@gitlab.clever-cloud.com:rbelouin/empty-repo.git";
var repoPath = __dirname + "/empty-repo";

if(fs.existsSync(repoPath)) {
  rm("-rf", repoPath);
};

if(exec("cd " + __dirname + " && git clone " + repo + " " + path.resolve(repoPath)).code != 0) {
  console.error("Cannot clone test repository: " + repo);
  exit(1);
}

describe("git", function() {
  var git = require("../src/models/git.js")(repoPath);

  it("should be able to get the current repository", function(done) {
    git.getRepository().subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      expect(path.resolve(event.value().path())).toBe(path.resolve(repoPath, ".git"));
      done();

      return Bacon.noMore;
    });
  });

  it("should be able to get the \"origin\" remote", function(done) {
    git.getRemote("origin").subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      expect(event.value().url()).toBe(repo);
      done();

      return Bacon.noMore;
    });
  });

  it("should be able to get the \"master\" branch", function(done) {
    git.getBranch("master").subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      expect(event.value().name()).toBe("refs/heads/master");
      done();

      return Bacon.noMore;
    });
  });

  it("should be able to create a \"origin2\" remote", function(done) {
    git.createRemote("origin2", repo).subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      expect(event.value().url()).toBe(repo);
      done();

      return Bacon.noMore;
    });
  });

  it("should be able to fetch a remote", function(done) {
    git.getRemote("origin").flatMapLatest(git.fetch).subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      expect(event.value().url()).toBe(repo);
      done();

      return Bacon.noMore;
    });
  });

  it("should be able to keep fetching a remote", function(done) {
    git.getRemote("origin").flatMapLatest(_.partial(git.keepFetching, 30000)).subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      expect(event.value().url()).toBe(repo);
      done();

      return Bacon.noMore;
    });
  });

  it("should be able to push to the origin remote", function(done) {
    git.getRemote("origin").flatMapLatest(_.partialRight(git.push, "master")).subscribe(function(event) {
      expect(event.hasValue()).toBe(true);
      done();

      return Bacon.noMore;
    });
  });
});

@@ -2367,26 +2367,19 @@
 %22should 
-be able to
+not
  push to
@@ -2392,24 +2392,52 @@
 rigin remote
+ if the remote is up-to-date
 %22, function(
@@ -2439,32 +2439,45 @@
 tion(done) %7B%0A   
+ var s_push =
  git.getRemote(%22
@@ -2503,31 +2503,404 @@
 est(
-_.partialRight(
+function(remote) %7B%0A      return git.push(remote, %22master%22, git.getCommitId(%22master%22), false);%0A    %7D);%0A%0A    s_push.subscribe(function(event) %7B%0A      expect(event.hasValue()).toBe(false);%0A      done();%0A%0A      return Bacon.noMore;%0A    %7D);%0A  %7D);%0A%0A  it(%22should push to the origin remote%22, function(done) %7B%0A    var s_push = git.getRemote(%22origin%22).flatMapLatest(function(remote) %7B%0A      return 
 git.push
 , %22m
@@ -2895,16 +2895,23 @@
 git.push
+(remote
 , %22maste
@@ -2912,18 +2912,101 @@
 %22master%22
-))
+, Bacon.once(%220000000000000000000000000000000000000000%22), false);%0A    %7D);%0A%0A    s_push
 .subscri

Update tests for git push