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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 773ab4311def22ad7a61354f524f3439850a3b850a7d7d85478fb5ee50546de8
4
- data.tar.gz: 6bc7f99038ba912dc4f132d7e904807a39d1379621486249f743f5c3c0aefbe1
3
+ metadata.gz: 7d7a5a34e55842b68937ef1bf93521b7a07e4b2dfa8c13b2c4d7796a80c66602
4
+ data.tar.gz: 5c9e66b1ae1d394434a57d65b0e2998b5f82d062591f6750db97015b7b71a826
5
5
  SHA512:
6
- metadata.gz: c6a5922718687dc8c61bdc899a084f731e0d8ab9db978e1a8b606f3bec13cae0cd7264f751316aeaf30221bf46a5f9b146161743f5f17945553090235d7f346c
7
- data.tar.gz: a5c29b46ea984b37bb6f6ecce064e5e760d286d9b064b488c053967fe49fe3f692c1ab943a121329c7bd7daf2a5e5e3a23d7bdf06a098714b25d9cbb3901660d
6
+ metadata.gz: 7807f4738bbe02ffff7f0a424bfd43896e2d293d0eb7169b431fcb79e48257b6b1abda8762928453303a6553ad71965f6dbb08071558b30699097bd26205cc2d
7
+ data.tar.gz: 6405463051f049349651d27177902ef6f1b0e7a38f54ac6858681ebbdc826c61f2940b8fb7150dd2adeaf1f6360eeb7b057bd2b7a2535a59e48ebb059ea1a48c
@@ -1,5 +1,5 @@
1
1
  # universal version tracking
2
2
 
3
3
  class GitReclone
4
- Version = "0.2.3"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/git-reclone.rb CHANGED
@@ -1,27 +1,26 @@
1
1
  # git-reclone gem
2
2
  # jeremy warner
3
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
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 (@testing || opts.first)
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::Help
37
+ puts GitReclone::HELP
39
38
  when "--version", "-v"
40
- puts GitReclone::Version
39
+ puts GitReclone::VERSION
41
40
  end
42
41
  end
43
42
 
44
43
  def parse_arg(a)
45
- a.nil?? verify(remote) : verify(remote(a))
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
- %x{git rev-parse --show-toplevel}
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
- %x{git remote -v}.split("\n").map { |r| r.split[1] }.uniq
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
- return errmsg
86
+ errmsg
84
87
  else
85
- return r
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 completely overwrite the local copy.".yellow
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
- # 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)
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::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
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
+ [![Gem Version](https://badge.fury.io/rb/git-reclone.svg)](https://badge.fury.io/rb/git-reclone)
4
+ [![Build Status](https://app.travis-ci.com/jeremywrnr/git-reclone.svg)](https://app.travis-ci.com/github/jeremywrnr/git-reclone)
5
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
6
 
11
- destroy your local copy of a git repo, and reclone it from your remote.
7
+ replace your local copy of a git repo with a fresh clone from your remote.
12
8
 
13
- ![Screencast](http://i.imgur.com/HIvZCJB.gif)
9
+ ![Screencast](assets/screencast.gif)
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 overwrite the current repository with bitbucket's remote (assuming
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
- 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?
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.2.3
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: 2019-11-15 00:00:00.000000000 Z
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: ronn
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: rake
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: rspec
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: reclone a local git repo from the remote.
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.0.6
106
- signing_key:
107
+ rubygems_version: 3.4.20
108
+ signing_key:
107
109
  specification_version: 4
108
- summary: reclone a local git repo from the remote.
110
+ summary: Replace your local git repo with a fresh clone from the remote
109
111
  test_files: []