ascend from the current dir till I find a .git folder or reach home_dir
968615
def git_root_till_home
      Pathname.new(Dir.pwd).ascend do |dir_pathname|
        return dir_pathname if File.directory?("#{dir_pathname}/.git")
        return nil if dir_pathname.to_s == home_dir
      end
    end
1029974
def require_repo(directory=None):
    """"""
    if directory and not os.path.isdir(directory):
        raise ValueError('Directory not found: ' + repr(directory))
    repo = repo_path(directory)
    if not os.path.isdir(repo):
        raise RepositoryNotFoundError(directory)
    return repo
77896
function findFilesToPackage(dir, callback) {
    var cwd = process.cwd();
    process.chdir(dir);

    var gitls = spawn('git', ['ls-files']),
        // This gets the full path to each file in each submodule
        subls = spawn('git', ['submodule', 'foreach', 'for file in `git ls-files`; do echo "$path/$file"; done']);
        // List all node_modules
        modls = spawn('find', ['node_modules']);


    var mainFileList = '';
    gitls.stdout.on('data', function (data) {
        mainFileList += data;
    });
    gitls.on('exit', returnFileList);

    var subFileList = '';
    subls.stdout.on('data', function (data) {
        subFileList += data;
    });
    subls.on('exit', returnFileList);
    
    var modFileList = '';
    modls.stdout.on('data', function (data) {
        modFileList += data;
    });
    modls.on('exit', returnFileList);

    var lsCount = 0;
    function returnFileList(code) {
        lsCount++;
        if (lsCount < 3) {
            return;
        }
        process.chdir(cwd);

        // Convert \n separated list of filenames into a sorted array
        var fileList = (mainFileList.trim() + '\n' + subFileList.trim() + '\n' + modFileList.trim()).split('\n').filter(function(file) {
            // Ignore entering submodule messages
            if (file.indexOf('Entering ') === 0) {
                return;
            }

            // Ignore hidden and backup files
            if (file.split('/').pop()[0] == '.' || file[file.length - 1] == '~') {
                return;
            }

            // Submodules appear in ls-files but aren't files. Skip them
            if (fs.statSync(path.join(dir, file)).isDirectory()) {
                return;
            }

            
            return file;
        }).sort();

        callback(fileList);
    }

}
113328
function mk(dir) {
      var absDir = path.resolve(dir);
      if (!fs.existsSync(absDir)) {
        try {
          fs.mkdirSync(absDir);
        }
        catch (e) {
          mk(path.dirname(absDir));
          fs.mkdirSync(absDir);
        }
      }
    }
1144230
def excursion(directory):
    """"""
    old_dir = os.getcwd()
    try:
        os.chdir(directory)
        yield
    finally:
        os.chdir(old_dir)
558313
def traverse_tree(cls, static_dir):
        """"""
        for root, dirs, files in os.walk(static_dir):
            for filename in files:
                if cls._pattern.match(filename):
                    APPS_INCLUDE_DIRS.append(static_dir)
                    return
1233021
def get_vcs_directory(context, directory):
        """"""
        nested = os.path.join(directory, '.git')
        return nested if context.is_directory(nested) else directory
87938
function getGitFolderPath(currentPath) {
  var git = path.resolve(currentPath, '.git')

  if (!exists(git) || !fs.lstatSync(git).isDirectory()) {
    console.log('pre-commit:');
    console.log('pre-commit: Not found .git folder in', git);
    
    var newPath = path.resolve(currentPath, '..');

    // Stop if we on top folder
    if (currentPath === newPath) {
      return null;
    }

    return getGitFolderPath(newPath);
  }

  console.log('pre-commit:');
  console.log('pre-commit: Found .git folder in', git);
  return git;
}
773758
def find_vcs_root(path, dirs=(".git",)):
    """"""
    prev, path = None, os.path.abspath(path)
    while prev != path:
        if any(os.path.exists(os.path.join(path, d)) for d in dirs):
            return path
        prev, path = path, os.path.abspath(os.path.join(path, os.pardir))
    return None
1065927
function () {
      gutil.log('Pushing ' + chalk.magenta(folder) + ' to ' + chalk.cyan(remote) + '/' + chalk.cyan(branch));
      execute('git subtree push --prefix ' + folder + ' ' + remote + ' ' + branch, function (error) {
        if (error) {
          return cb(error);
        }
        gutil.log('Resetting ' + chalk.magenta(folder) + ' temporary commit');
        execute('git reset HEAD^', function (error) {
          return cb(error, file);
        });
      });
    }
1044283
def install_git(path):
    """"""
    hook = op.join(path, 'pre-commit')
    with open(hook, 'w') as fd:
        fd.write("""#!/usr/bin/env python
import sys
from pylama.hook import git_hook

if __name__ == '__main__':
    sys.exit(git_hook())
""")
    chmod(hook, 484)
105662
def check_directory(self):
        """"""
        exists = os.path.exists(self.directory)
        if not exists:
            logger.error("No migrations directory found. Check your path or create a migration first.")
            logger.error("Directory: %s" % self.directory)
        return exists
1093132
def archive(directory, id, destination_path)
      Dir.chdir(@directory) do
        FileUtils.mkdir_p(File.dirname(destination_path))
        run("git archive --format=tar #{id} -- #{directory} | xz -9e > #{destination_path}")
      end
      destination_path
    end
334561
def get_git_root(index=3):  # type: (int) -> str
    
    path = get_current_path(index=index)
    while True:
        git_path = os.path.join(path, '.git')
        if os.path.isdir(git_path):
            return path
        if os.path.dirname(path) == path:
            raise RuntimeError("Cannot find git root")
        path = os.path.split(path)[0]
1032018
function (workingDirectory) {
        var gitPath = getClosestGitPath(workingDirectory);

        if (!gitPath) {
            throw new Error('git-hooks must be run inside a git repository');
        }

        var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME);
        var pathToGitHooks = path.join(path.relative(hooksPath, __dirname), 'git-hooks');
 
        if (isWin32) {
            pathToGitHooks = pathToGitHooks.replace(/\\/g, '\\\\');
        }

        if (fsHelpers.exists(hooksOldPath)) {
            throw new Error('git-hooks already installed');
        }

        if (fsHelpers.exists(hooksPath)) {
            fs.renameSync(hooksPath, hooksOldPath);
        }

        var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME);
        var pathToGitHooks = path.relative(hooksPath, __dirname);
        // Fix non-POSIX (Windows) separators
        pathToGitHooks = pathToGitHooks.replace(new RegExp(path.sep.replace(/\\/g, '\\$&'), 'g'), '/');
        var hook = util.format(hookTemplate.toString(), pathToGitHooks);

        fsHelpers.makeDir(hooksPath);
        HOOKS.forEach(function (hookName) {
            var hookPath = path.resolve(hooksPath, hookName);
            try {
                fs.writeFileSync(hookPath, hook, {mode: '0777'});
            } catch (e) {
                // node 0.8 fallback
                fs.writeFileSync(hookPath, hook, 'utf8');
                fs.chmodSync(hookPath, '0777');
            }
        });
    }
1022825
def subtree_up(path = Dir.pwd)
      error "Unable to pull subtree(s): Dirty Git repository" if FalkorLib::Git.dirty?( path )
      exit_status = 0
      git_root_dir = rootdir(path)
      Dir.chdir(git_root_dir) do
        FalkorLib.config.git[:subtrees].each do |dir, conf|
          next if conf[:url].nil?
          #url    = conf[:url]
          remote = dir.gsub(/\//, '-')
          branch = (conf[:branch].nil?) ? 'master' : conf[:branch]
          remotes = FalkorLib::Git.remotes
          info "Pulling changes into subtree '#{dir}' using remote '#{remote}/#{branch}'"
          raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
          info "\t\\__ fetching remote '#{remotes.join(',')}'"
          FalkorLib::Git.fetch( git_root_dir )
          raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory?( File.join(git_root_dir, dir) )
          info "\t\\__ pulling changes"
          exit_status = execute "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
          #exit_status = puts "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
        end
      end
      exit_status
    end
519965
def go_to_parent_directory(self):
        """"""
        self.chdir(osp.abspath(osp.join(getcwd_or_home(), os.pardir)))