Sha256: 0372ef86c000755e55eadf422077a442715da153f6e3972f4ff462f7e3f33857
Contents?: true
Size: 1.52 KB
Versions: 1
Compression:
Stored size: 1.52 KB
Contents
module GitHubRecordsArchiver class GitError < StandardError; end class GitRepository def clone if Dir.exist? repo_dir # Repo already exists, just pull new objects Dir.chdir repo_dir do git 'pull' end else # Clone Git content from scratch git 'clone', clone_url, repo_dir end end def repo_dir raise 'Not implemented' end private def clone_url raise 'Not implemented' end # There's a bug, whereby if you attempt to clone a wiki that's enabled # but has not yet been initialized, GitHub returns a remote error # Rather than let this break the export, capture the error and continue def wiki_does_not_exist?(output) expected = '^fatal: remote error: access denied or repository not ' expected << "exported: .*?\.wiki\.git$" output =~ /#{expected}/ end # Attempting to clone an empty repo will rightfulyl fail at the Git level # But we shouldn't let that fail the archive operation def empty_repo?(output) expected = 'Your configuration specifies to merge with the ref ' expected << "'refs/heads/master'\n" expected << 'from the remote, but no such ref was fetched.' output =~ Regexp.new(expected) end # Run a git command, piping output to stdout def git(*args) output, status = Open3.capture2e('git', *args) return false if empty_repo?(output) || wiki_does_not_exist?(output) raise GitError, output if status.exitstatus != 0 output end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
github_records_archiver-0.1.0 | lib/github_records_archiver/git_repository.rb |