git-reclone 0.2.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git-reclone-version.rb +1 -1
- data/lib/git-reclone.rb +73 -35
- data/readme.md +19 -15
- metadata +25 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7d7a5a34e55842b68937ef1bf93521b7a07e4b2dfa8c13b2c4d7796a80c66602
|
|
4
|
+
data.tar.gz: 5c9e66b1ae1d394434a57d65b0e2998b5f82d062591f6750db97015b7b71a826
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7807f4738bbe02ffff7f0a424bfd43896e2d293d0eb7169b431fcb79e48257b6b1abda8762928453303a6553ad71965f6dbb08071558b30699097bd26205cc2d
|
|
7
|
+
data.tar.gz: 6405463051f049349651d27177902ef6f1b0e7a38f54ac6858681ebbdc826c61f2940b8fb7150dd2adeaf1f6360eeb7b057bd2b7a2535a59e48ebb059ea1a48c
|
data/lib/git-reclone-version.rb
CHANGED
data/lib/git-reclone.rb
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
# git-reclone gem
|
|
2
2
|
# jeremy warner
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
todo: add
|
|
6
|
-
todo:
|
|
7
|
-
todo: -b / --backup, and this actually should be the default (maybe)
|
|
8
|
-
=end
|
|
4
|
+
# todo: add an option to automatically add a backup of the local copy
|
|
5
|
+
# todo: add all remotes other than the origins, maintain connections
|
|
6
|
+
# todo: -b / --backup, and this actually should be the default (maybe)
|
|
9
7
|
|
|
10
8
|
require "colored"
|
|
11
9
|
require "fileutils"
|
|
10
|
+
require "tmpdir"
|
|
12
11
|
require "git-reclone-version"
|
|
13
12
|
|
|
14
13
|
class GitReclone
|
|
15
|
-
def initialize(test=false)
|
|
14
|
+
def initialize(test = false)
|
|
16
15
|
@pdelay = 0.01 # constant for arrow speed
|
|
17
16
|
@testing = test
|
|
18
17
|
@verify = !test
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
def fire(args = [])
|
|
22
|
-
opts = args.select {|a| a[0] == "-" }
|
|
23
|
-
opts.each {|o| parse_opt o }
|
|
24
|
-
exit 0 if
|
|
21
|
+
opts = args.select { |a| a[0] == "-" }
|
|
22
|
+
opts.each { |o| parse_opt o }
|
|
23
|
+
exit 0 if @testing || opts.first
|
|
25
24
|
parse_arg((args - opts).first)
|
|
26
25
|
end
|
|
27
26
|
|
|
@@ -35,14 +34,14 @@ class GitReclone
|
|
|
35
34
|
when "--force", "-f"
|
|
36
35
|
@verify = false
|
|
37
36
|
when "--help", "-h"
|
|
38
|
-
puts GitReclone::
|
|
37
|
+
puts GitReclone::HELP
|
|
39
38
|
when "--version", "-v"
|
|
40
|
-
puts GitReclone::
|
|
39
|
+
puts GitReclone::VERSION
|
|
41
40
|
end
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
def parse_arg(a)
|
|
45
|
-
a.nil
|
|
44
|
+
a.nil? ? verify(remote) : verify(remote(a))
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def no_repo?
|
|
@@ -51,11 +50,15 @@ class GitReclone
|
|
|
51
50
|
end
|
|
52
51
|
|
|
53
52
|
def git_root
|
|
54
|
-
|
|
53
|
+
`git rev-parse --show-toplevel`
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def current_branch
|
|
57
|
+
`git rev-parse --abbrev-ref HEAD`.chomp
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
def remotes
|
|
58
|
-
|
|
61
|
+
`git remote -v`.split("\n").map { |r| r.split[1] }.uniq
|
|
59
62
|
end
|
|
60
63
|
|
|
61
64
|
def reclonebanner
|
|
@@ -80,9 +83,9 @@ class GitReclone
|
|
|
80
83
|
if r.nil?
|
|
81
84
|
errmsg = "No remotes found that match #{search.to_s.red}. All remotes:\n" + remotes.join("\n")
|
|
82
85
|
pexit errmsg
|
|
83
|
-
|
|
86
|
+
errmsg
|
|
84
87
|
else
|
|
85
|
-
|
|
88
|
+
r
|
|
86
89
|
end
|
|
87
90
|
end
|
|
88
91
|
|
|
@@ -92,8 +95,11 @@ class GitReclone
|
|
|
92
95
|
puts "Remote source:\t".red << r
|
|
93
96
|
puts "Local target:\t".red << git_root
|
|
94
97
|
|
|
98
|
+
branch = current_branch
|
|
99
|
+
puts "Current branch:\t".red << branch unless branch == "HEAD"
|
|
100
|
+
|
|
95
101
|
if @verify
|
|
96
|
-
puts "Warning: this will
|
|
102
|
+
puts "Warning: this will replace the local copy with a fresh clone from the remote.".yellow
|
|
97
103
|
printf "Continue recloning local repo? [yN] ".yellow
|
|
98
104
|
unless $stdin.gets.chomp.downcase[0] == "y"
|
|
99
105
|
puts "Reclone aborted.".green
|
|
@@ -101,29 +107,61 @@ class GitReclone
|
|
|
101
107
|
end
|
|
102
108
|
end
|
|
103
109
|
|
|
104
|
-
reclone remote, git_root.chomp unless @testing
|
|
110
|
+
reclone remote, git_root.chomp, branch unless @testing
|
|
105
111
|
end
|
|
106
112
|
|
|
107
113
|
# overwrite the local copy of the repository with the remote one
|
|
108
|
-
def reclone(remote, root)
|
|
109
|
-
#
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
def reclone(remote, root, branch = nil)
|
|
115
|
+
# create a temporary directory for cloning
|
|
116
|
+
temp_dir = Dir.mktmpdir("git-reclone-")
|
|
117
|
+
|
|
118
|
+
begin
|
|
119
|
+
# clone into temp directory (disable credential prompts)
|
|
120
|
+
cloner = "GIT_TERMINAL_PROMPT=0 git clone \"#{remote}\" \"#{temp_dir}\" > /dev/null 2>&1"
|
|
121
|
+
|
|
122
|
+
if system(cloner)
|
|
123
|
+
# clone succeeded, now replace the local copy
|
|
124
|
+
if !@testing
|
|
125
|
+
tree = Dir.glob("*", File::FNM_DOTMATCH).select { |d| ![".", ".."].include? d }
|
|
126
|
+
FileUtils.rmtree(tree)
|
|
127
|
+
|
|
128
|
+
# move contents from temp to root
|
|
129
|
+
Dir.glob("#{temp_dir}/*", File::FNM_DOTMATCH).each do |item|
|
|
130
|
+
next if File.basename(item) == "." || File.basename(item) == ".."
|
|
131
|
+
FileUtils.mv(item, root)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# restore original branch if it exists
|
|
135
|
+
if branch && branch != "HEAD"
|
|
136
|
+
Dir.chdir(root) do
|
|
137
|
+
system("git checkout #{branch} > /dev/null 2>&1")
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
puts "Recloned successfully.".green
|
|
143
|
+
"Recloned successfully.".green
|
|
144
|
+
else
|
|
145
|
+
# clone failed
|
|
146
|
+
puts "Clone failed.".red
|
|
147
|
+
nil
|
|
148
|
+
end
|
|
149
|
+
ensure
|
|
150
|
+
# always clean up temp directory
|
|
151
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
113
152
|
end
|
|
114
|
-
|
|
115
|
-
cloner = "git clone \"#{remote}\" \"#{root}\""
|
|
116
|
-
|
|
117
|
-
puts "Recloned successfully.".green if system(cloner)
|
|
118
153
|
end
|
|
119
154
|
end
|
|
120
155
|
|
|
121
|
-
GitReclone::
|
|
122
|
-
#{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
to
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
156
|
+
GitReclone::HELP = <<~HELP
|
|
157
|
+
#{"git reclone".red}: a git repo restoring tool
|
|
158
|
+
|
|
159
|
+
replaces your local copy with a fresh clone from the remote.
|
|
160
|
+
clones to a temp directory first, so your local copy is safe if the clone fails.
|
|
161
|
+
to restore from a particular remote repository, specify the host:
|
|
162
|
+
|
|
163
|
+
git reclone github # reclone using github
|
|
164
|
+
git reclone bitbucket # reclone using bitbucket
|
|
165
|
+
git reclone gitea # reclone using gitea
|
|
166
|
+
git reclone gogs # reclone using gogs
|
|
129
167
|
HELP
|
data/readme.md
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
git-reclone :rocket:
|
|
2
|
-
=================
|
|
3
|
-
|
|
1
|
+
# git-reclone :rocket:
|
|
4
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/git-reclone)
|
|
4
|
+
[](https://app.travis-ci.com/github/jeremywrnr/git-reclone)
|
|
5
5
|
[](http://jeremywrnr.com/mit-license)
|
|
6
|
-
-[](https://badge.fury.io/rb/git-reclone)
|
|
7
|
-
[](https://travis-ci.org/jeremywrnr/git-reclone)
|
|
8
|
-
[](https://codeclimate.com/github/jeremywrnr/git-reclone)
|
|
9
|
-
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
replace your local copy of a git repo with a fresh clone from your remote.
|
|
12
8
|
|
|
13
|
-

|
|
14
10
|
|
|
15
11
|
tested and works well for:
|
|
16
12
|
|
|
17
13
|
- github
|
|
18
14
|
- bitbucket
|
|
15
|
+
- gitea
|
|
16
|
+
- gogs
|
|
19
17
|
|
|
20
18
|
## setup
|
|
21
19
|
|
|
@@ -35,18 +33,24 @@ part (or all) of the host name. for example:
|
|
|
35
33
|
git reclone bucket
|
|
36
34
|
git reclone bitbucket
|
|
37
35
|
|
|
38
|
-
will all
|
|
39
|
-
that some other host/repo name doesn't also match 'bitbucket').
|
|
36
|
+
will all replace the current repository with a fresh clone from bitbucket's
|
|
37
|
+
remote (assuming that some other host/repo name doesn't also match 'bitbucket').
|
|
38
|
+
|
|
39
|
+
The tool safely clones to a temporary directory first, so if the clone fails,
|
|
40
|
+
your local copy remains intact. Your current branch is automatically restored
|
|
41
|
+
after recloning (if it exists on the remote).
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
## about
|
|
43
45
|
|
|
44
46
|
sometimes i mess up git histories, with (merges or rebasing, etc), and it
|
|
45
47
|
becomes more of a headache to figure out how to undo what i did than to just
|
|
46
|
-
|
|
47
|
-
doing this often enough that i figured it would be nice to have a
|
|
48
|
-
just did this automatically.
|
|
49
|
-
|
|
48
|
+
get a fresh clone from the remote and apply the changes i want in the right
|
|
49
|
+
way. i was doing this often enough that i figured it would be nice to have a
|
|
50
|
+
tool that just did this automatically. the tool clones to a temporary directory
|
|
51
|
+
first, so if something goes wrong, your local copy is safe. besides, it can be
|
|
52
|
+
satisfying to just start fresh from the remote - after all, what are backups
|
|
53
|
+
meant for?
|
|
50
54
|
|
|
51
55
|
## testing
|
|
52
56
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: git-reclone
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Warner
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colored
|
|
@@ -31,48 +31,50 @@ dependencies:
|
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '1.2'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
|
-
name:
|
|
34
|
+
name: rake
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
39
|
+
version: '13.0'
|
|
40
40
|
type: :development
|
|
41
41
|
prerelease: false
|
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
|
-
- - "
|
|
44
|
+
- - "~>"
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '0'
|
|
46
|
+
version: '13.0'
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
|
-
name:
|
|
48
|
+
name: rspec
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
|
-
- - "
|
|
51
|
+
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '0'
|
|
53
|
+
version: '3.0'
|
|
54
54
|
type: :development
|
|
55
55
|
prerelease: false
|
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
|
-
- - "
|
|
58
|
+
- - "~>"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '0'
|
|
60
|
+
version: '3.0'
|
|
61
61
|
- !ruby/object:Gem::Dependency
|
|
62
|
-
name:
|
|
62
|
+
name: standard
|
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
|
-
- - "
|
|
65
|
+
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '0'
|
|
67
|
+
version: '1.0'
|
|
68
68
|
type: :development
|
|
69
69
|
prerelease: false
|
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
|
-
- - "
|
|
72
|
+
- - "~>"
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '0'
|
|
75
|
-
description:
|
|
74
|
+
version: '1.0'
|
|
75
|
+
description: A tool to safely replace your local git repository with a fresh clone
|
|
76
|
+
from the remote. Clones to a temporary directory first to protect your local copy
|
|
77
|
+
if something goes wrong, and automatically restores your current branch.
|
|
76
78
|
email: jeremy.warner@berkeley.edu
|
|
77
79
|
executables:
|
|
78
80
|
- git-reclone
|
|
@@ -87,7 +89,7 @@ homepage: http://github.com/jeremywrnr/git-reclone
|
|
|
87
89
|
licenses:
|
|
88
90
|
- MIT
|
|
89
91
|
metadata: {}
|
|
90
|
-
post_install_message:
|
|
92
|
+
post_install_message:
|
|
91
93
|
rdoc_options: []
|
|
92
94
|
require_paths:
|
|
93
95
|
- lib
|
|
@@ -102,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
102
104
|
- !ruby/object:Gem::Version
|
|
103
105
|
version: '0'
|
|
104
106
|
requirements: []
|
|
105
|
-
rubygems_version: 3.
|
|
106
|
-
signing_key:
|
|
107
|
+
rubygems_version: 3.4.20
|
|
108
|
+
signing_key:
|
|
107
109
|
specification_version: 4
|
|
108
|
-
summary:
|
|
110
|
+
summary: Replace your local git repo with a fresh clone from the remote
|
|
109
111
|
test_files: []
|