git-reclone 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/git-reclone +8 -0
- data/lib/git-reclone-version.rb +5 -0
- data/lib/git-reclone.rb +129 -0
- data/readme.md +55 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 773ab4311def22ad7a61354f524f3439850a3b850a7d7d85478fb5ee50546de8
|
4
|
+
data.tar.gz: 6bc7f99038ba912dc4f132d7e904807a39d1379621486249f743f5c3c0aefbe1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6a5922718687dc8c61bdc899a084f731e0d8ab9db978e1a8b606f3bec13cae0cd7264f751316aeaf30221bf46a5f9b146161743f5f17945553090235d7f346c
|
7
|
+
data.tar.gz: a5c29b46ea984b37bb6f6ecce064e5e760d286d9b064b488c053967fe49fe3f692c1ab943a121329c7bd7daf2a5e5e3a23d7bdf06a098714b25d9cbb3901660d
|
data/bin/git-reclone
ADDED
data/lib/git-reclone.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# git-reclone gem
|
2
|
+
# jeremy warner
|
3
|
+
|
4
|
+
=begin
|
5
|
+
todo: add an option to automatically add a backup of the local copy
|
6
|
+
todo: add all remotes other than the origins, maintain connections
|
7
|
+
todo: -b / --backup, and this actually should be the default (maybe)
|
8
|
+
=end
|
9
|
+
|
10
|
+
require "colored"
|
11
|
+
require "fileutils"
|
12
|
+
require "git-reclone-version"
|
13
|
+
|
14
|
+
class GitReclone
|
15
|
+
def initialize(test=false)
|
16
|
+
@pdelay = 0.01 # constant for arrow speed
|
17
|
+
@testing = test
|
18
|
+
@verify = !test
|
19
|
+
end
|
20
|
+
|
21
|
+
def fire(args = [])
|
22
|
+
opts = args.select {|a| a[0] == "-" }
|
23
|
+
opts.each {|o| parse_opt o }
|
24
|
+
exit 0 if (@testing || opts.first)
|
25
|
+
parse_arg((args - opts).first)
|
26
|
+
end
|
27
|
+
|
28
|
+
def pexit(msg)
|
29
|
+
puts msg
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_opt(o)
|
34
|
+
case o
|
35
|
+
when "--force", "-f"
|
36
|
+
@verify = false
|
37
|
+
when "--help", "-h"
|
38
|
+
puts GitReclone::Help
|
39
|
+
when "--version", "-v"
|
40
|
+
puts GitReclone::Version
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_arg(a)
|
45
|
+
a.nil?? verify(remote) : verify(remote(a))
|
46
|
+
end
|
47
|
+
|
48
|
+
def no_repo?
|
49
|
+
`git status 2>&1`.split("\n").first ==
|
50
|
+
"fatal: Not a git repository (or any of the parent directories): .git"
|
51
|
+
end
|
52
|
+
|
53
|
+
def git_root
|
54
|
+
%x{git rev-parse --show-toplevel}
|
55
|
+
end
|
56
|
+
|
57
|
+
def remotes
|
58
|
+
%x{git remote -v}.split("\n").map { |r| r.split[1] }.uniq
|
59
|
+
end
|
60
|
+
|
61
|
+
def reclonebanner
|
62
|
+
25.times { |x| slowp "\rpreparing| ".red << "~" * x << "#==>".red }
|
63
|
+
25.times { |x| slowp "\rpreparing| ".red << " " * x << "~" * (25 - x) << "#==>".yellow }
|
64
|
+
printf "\rREADY.".red << " " * 50 << "\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
def slowp(x)
|
68
|
+
sleep @pdelay
|
69
|
+
printf x
|
70
|
+
end
|
71
|
+
|
72
|
+
# trying to parse out which remote should be the new source
|
73
|
+
def remote(search = /.*/)
|
74
|
+
pexit "Not currently in a git repository.".yellow if no_repo?
|
75
|
+
|
76
|
+
r = remotes.find { |gr| gr.match search }
|
77
|
+
|
78
|
+
pexit "No remotes found in this repository.".yellow if remotes.nil?
|
79
|
+
|
80
|
+
if r.nil?
|
81
|
+
errmsg = "No remotes found that match #{search.to_s.red}. All remotes:\n" + remotes.join("\n")
|
82
|
+
pexit errmsg
|
83
|
+
return errmsg
|
84
|
+
else
|
85
|
+
return r
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# show remote to user and confirm location (unless using -f)
|
90
|
+
def verify(r)
|
91
|
+
reclonebanner
|
92
|
+
puts "Remote source:\t".red << r
|
93
|
+
puts "Local target:\t".red << git_root
|
94
|
+
|
95
|
+
if @verify
|
96
|
+
puts "Warning: this will completely overwrite the local copy.".yellow
|
97
|
+
printf "Continue recloning local repo? [yN] ".yellow
|
98
|
+
unless $stdin.gets.chomp.downcase[0] == "y"
|
99
|
+
puts "Reclone aborted.".green
|
100
|
+
return
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
reclone remote, git_root.chomp unless @testing
|
105
|
+
end
|
106
|
+
|
107
|
+
# overwrite the local copy of the repository with the remote one
|
108
|
+
def reclone(remote, root)
|
109
|
+
# remove the git repo from this computer
|
110
|
+
if !@testing
|
111
|
+
tree = Dir.glob("*", File::FNM_DOTMATCH).select {|d| not ['.','..'].include? d }
|
112
|
+
FileUtils.rmtree (tree)
|
113
|
+
end
|
114
|
+
|
115
|
+
cloner = "git clone \"#{remote}\" \"#{root}\""
|
116
|
+
|
117
|
+
puts "Recloned successfully.".green if system(cloner)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
GitReclone::Help = <<-HELP
|
122
|
+
#{'git reclone'.red}: a git repo restoring tool
|
123
|
+
|
124
|
+
reclones from the remote listed first, overwriting your local copy.
|
125
|
+
to restore from a particular remote repository, specify the host:
|
126
|
+
|
127
|
+
git reclone bitbucket # reclone using bitbucket
|
128
|
+
git reclone github # reclone using github
|
129
|
+
HELP
|
data/readme.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
git-reclone :rocket:
|
2
|
+
=================
|
3
|
+
|
4
|
+
|
5
|
+
[![MIT](https://img.shields.io/npm/l/alt.svg?style=flat)](http://jeremywrnr.com/mit-license)
|
6
|
+
-[![Gem Version](https://badge.fury.io/rb/git-reclone.svg)](https://badge.fury.io/rb/git-reclone)
|
7
|
+
[![Build Status](https://travis-ci.org/jeremywrnr/git-reclone.svg?branch=master)](https://travis-ci.org/jeremywrnr/git-reclone)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/jeremywrnr/git-reclone/badges/gpa.svg)](https://codeclimate.com/github/jeremywrnr/git-reclone)
|
9
|
+
|
10
|
+
|
11
|
+
destroy your local copy of a git repo, and reclone it from your remote.
|
12
|
+
|
13
|
+
![Screencast](http://i.imgur.com/HIvZCJB.gif)
|
14
|
+
|
15
|
+
tested and works well for:
|
16
|
+
|
17
|
+
- github
|
18
|
+
- bitbucket
|
19
|
+
|
20
|
+
## setup
|
21
|
+
|
22
|
+
[sudo] gem install git-reclone
|
23
|
+
|
24
|
+
This will enable the `git reclone` command automatically!
|
25
|
+
|
26
|
+
|
27
|
+
## usage
|
28
|
+
|
29
|
+
git reclone
|
30
|
+
|
31
|
+
reclones from the first git remote. to clone a specific remote, specify some
|
32
|
+
part (or all) of the host name. for example:
|
33
|
+
|
34
|
+
git reclone bit
|
35
|
+
git reclone bucket
|
36
|
+
git reclone bitbucket
|
37
|
+
|
38
|
+
will all overwrite the current repository with bitbucket's remote (assuming
|
39
|
+
that some other host/repo name doesn't also match 'bitbucket').
|
40
|
+
|
41
|
+
|
42
|
+
## about
|
43
|
+
|
44
|
+
sometimes i mess up git histories, with (merges or rebasing, etc), and it
|
45
|
+
becomes more of a headache to figure out how to undo what i did than to just
|
46
|
+
reclone the remote copy and apply the changes i want in the right way. i was
|
47
|
+
doing this often enough that i figured it would be nice to have a tool that
|
48
|
+
just did this automatically. besides, it can be satisfying to just reclone your
|
49
|
+
local copy and start anew - after all, what are backups meant for?
|
50
|
+
|
51
|
+
## testing
|
52
|
+
|
53
|
+
bundle || gem install bundler && bundle
|
54
|
+
rake # running git-reclone's tests
|
55
|
+
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-reclone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Warner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colored
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.2'
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ronn
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: reclone a local git repo from the remote.
|
76
|
+
email: jeremy.warner@berkeley.edu
|
77
|
+
executables:
|
78
|
+
- git-reclone
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- bin/git-reclone
|
83
|
+
- lib/git-reclone-version.rb
|
84
|
+
- lib/git-reclone.rb
|
85
|
+
- readme.md
|
86
|
+
homepage: http://github.com/jeremywrnr/git-reclone
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: reclone a local git repo from the remote.
|
109
|
+
test_files: []
|