#!/usr/bin/env node

var exec = require('child_process').exec
var fs = require('fs')
var path = require('path')
var username = ""

// get their username
// verify branch matches username, case too.
// verify they've pushed
// check the file is in contributors directory

exec('git config user.username', function(err, stdout, stdrr) {
  if (err) return console.log(err)
  username = stdout.trim()

  exec('git rev-parse --abbrev-ref HEAD', function(err, stdout, stderr) {
    if (err) return console.log(err)
    var actualBranch = stdout.trim()
    var expectedBranch = "add-" + username
    if (actualBranch.match(expectedBranch)) {
      console.log("Found branch as expected!")
      checkPush(actualBranch)
    } else {
      console.log("Branch name expected: " + expectedBranch)
      checkPush(actualBranch)
    }
  })
})

function checkPush(branchname) {
  exec('git reflog show origin/' + branchname, function(err, stdout, stderr) {
    if (err) return console.log(err)
    if (stdout.match("update by push")) console.log("Changes have been pushed!")
    else console.log("Changes not pushed")
    findFile()
  })
}

function findFile() {
  fs.readdir(path.join(process.cwd(), "/contributors/"), function(err, files) {
    if (err) return console.log(err)
    var allFiles = files.join()
    if (allFiles.match(username)) console.log("File in contributors folder!")
    else console.log("File NOT in contribs.. folder!")
  })
}

@@ -1148,61 +1148,249 @@
 %7B%0A  
-fs.readdir(path.join(process.cwd(), %22/contributors/%22)
+// see if user is already within /contributors%0A  if (process.cwd().match(%22contributors%22)) %7B%0A    check(process.cwd())%0A  %7D else %7B%0A    check(path.join(process.cwd(), %22/contributors/%22))%0A  %7D%0A%0A  function check(userspath) %7B%0A    fs.readdir(userspath
 , fu
@@ -1406,24 +1406,26 @@
 r, files) %7B%0A
+  
     if (err)
@@ -1449,24 +1449,26 @@
 og(err)%0A    
+  
 var allFiles
@@ -1483,16 +1483,18 @@
 .join()%0A
+  
     if (
@@ -1559,24 +1559,26 @@
 s folder!%22)%0A
+  
     else con
@@ -1618,17 +1618,23 @@
 folder!%22)%0A  
+  %7D)%0A  
 %7D
-)
 %0A%7D%0A

verify cwd, fixes #84 #97 #107 See if user is inside or outside of /contributors before looking in that directory for their file