<commit_before># Copyright (c) 2011 <NAME>
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license

require 'rubygems'
require 'legit-the-git'
require 'fileutils'

module LegitGit
  class CommandLine

    # Parse command line options and execute
    def self.execute(args)

      help = <<-EOS
Usage #{File.basename $0} [--version] [--help] <command>

Commands:
  install      Install the Accurev Git hook into the current directory

Workflow:
  Once installed commit your changes like usual. When you would like to push
  those changes to accurev, just run `git push accurev`. This will sync new
  commits from the current branch to the accurev server. Just make sure you
  are logged into accurev!

EOS

      case args
      when "install"
        ret_val = LegitGit::Installation.new(Dir.pwd)
        exit 0
      when "--version"
        puts "0.0.4"
        exit 0
      else
        puts help
      end
    end
  end

  class Installation

    def initialize(repo)
      install(repo)
    end

    def install(repo_path)
      repository = Grit::Repo.new(repo_path)

      repo_hooks = File.join(repo_path, '.git', 'hooks')
      accurev_repo = File.join(repo_path, '.git', 'accurev.git')
      accurev_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')

      repository.fork_bare(accurev_repo, :shared => false, :mirror => true)
      repository.remote_add("accurev", accurev_repo)

      FileUtils.mkdir accurev_hooks unless File.exist? accurev_hooks
      FileUtils.mkdir repo_hooks unless File.exist? repo_hooks

      FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-commit"), repo_hooks, :mode => 0755)
      FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "pre-receive"), accurev_hooks, :mode => 0755)
    end
  end
end<commit_msg>Add uninstall option to cli<commit_after># Copyright (c) 2011 <NAME>
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license

require 'rubygems'
require 'legit-the-git'
require 'fileutils'

module LegitGit
  class CommandLine

    # Parse command line options and execute
    def self.execute(args)

      help = <<-EOS
Usage #{File.basename $0} [--version] [--help] <command>

Commands:
  install      Install the Accurev Git hook into the current directory

Workflow:
  Once installed commit your changes like usual. When you would like to push
  those changes to accurev, just run `git push accurev`. This will sync new
  commits from the current branch to the accurev server. Just make sure you
  are logged into accurev!

EOS

      case args
      when "install"
        installation = LegitGit::Installation.new(Dir.pwd)
        installation.install
        puts 'Successfully installed!'
        puts "Run #{File.basename $0} --help for usage."
        exit 0
      when "uninstall"
        installation = LegitGit::Installation.new(Dir.pwd)
        installation.uninstall
        puts 'Successfully uninstalled!'
        exit 0
      when "--version"
        puts "0.0.4"
        exit 0
      else
        puts help
      end
    end
  end

  class Installation
    # Refactor!

    def initialize(repo_path)
      @repository = Grit::Repo.new(repo_path)
      @accurev_repo = File.join(repo_path, '.git', 'accurev.git')

      @accurev_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')
      @repo_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')
    end

    def install
      @repository do |repo|
        repo.fork_bare(@accurev_repo, :shared => false, :mirror => true)
        repo.remote_add("accurev", @accurev_repo)
      end

      FileUtils.mkdir_p(@accurev_hooks, @repo_hooks)

      FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-commit"), @repo_hooks, :mode => 0755)
      FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "pre-receive"), @accurev_hooks, :mode => 0755)
    end

    def uninstall(repo_path)
      unless repository.remotes.select {|r| r.name =~ /accurev/}.empty?
        git = Grit::Git.new(Dir.pwd)
        git.native("remote rm accurev")
      end

      FileUtils.rm_rf(@accurev_repo, File.join(@repo_hooks, "hooks", "post-commit"))
    end
  end
end
{'fraction_non_alphanumeric': 0.11068611044704757, 'fraction_numerical': 0.009084389194358116, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6519267', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1359, 'n_words': 375}