git-amend 0.0.1

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +32 -0
  3. data/bin/git-amend +125 -0
  4. data/lib/version.rb +5 -0
  5. metadata +63 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3bd3abf7772d1c24e5297fd7e340d84b51058bb
4
+ data.tar.gz: 2846262006afffc5f375efc41650d98766a9c871
5
+ SHA512:
6
+ metadata.gz: 41dea1d7cab1df953057436a90421622d64685ce7034ddf0c7aa3550a786fcf50a2b5dad3b7eded6bd6ec40fa603138f7c8c86ba7ec96d941c61ba44f6ac0d73
7
+ data.tar.gz: 3d7dc92530135b15c9024ec4dccfddb49406ca246dc421c8b8427fca7e2c8df04deb13fbfa9618a6a0b68cad0f60e0eeb0ef34b34103f565959ee6458d7daf79
@@ -0,0 +1,32 @@
1
+ # git-amend
2
+ A CLI tool to update the information of exisiting git commit, such as commit date, auther, etc.
3
+
4
+ ## How to install
5
+ ```bash
6
+ gem install git-amend
7
+ ```
8
+
9
+ ## How to install
10
+ ```bash
11
+ gem build git-amend.gemspec
12
+ gem install --local git-amend-<version>.gem
13
+ cd <repository>
14
+ git-amend
15
+ ```
16
+
17
+ ## How to use
18
+ ```bash
19
+ Usage: git-amend [options]
20
+ -p, --path=<path> Path to the target respository
21
+ -a, --author=<email> Author email for all commits
22
+ -n, --author-name=<name> Author name for all commits
23
+ -c, --committer=<email> Committer email for all commits
24
+ -m, --committer-name=<name> Committer name for all commits
25
+ -C, --commit-hash=<hash> The hash of git commit that needs to be updated
26
+ -s, --shuffle Whether to shuffle the commit date (default: no)
27
+ -f, --from=<date> Date of the first commit
28
+ -t, --to=<date> Date of the latest commit
29
+ -v, --verbose Verbose mode
30
+ -V, --version Print version
31
+ -d, --dry-run Dry run without executing the actual command.
32
+ ```
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+ require 'timerizer'
3
+ require 'time'
4
+ require 'optparse'
5
+ require_relative '../lib/version'
6
+
7
+ # Default values
8
+ options = {
9
+ path: Dir.pwd,
10
+ author_email: nil,
11
+ author_name: nil,
12
+ committer_email: nil,
13
+ committer_name: nil,
14
+ should_shuffle_date: false,
15
+ from: 365.days.ago,
16
+ to: 0.days.ago,
17
+ dry_run: false,
18
+ verbose: false,
19
+ version: false,
20
+ commit_hash: nil
21
+ }
22
+
23
+ OptionParser.new do |opts|
24
+ opts.banner = "Usage: git-amend [options]"
25
+
26
+ opts.on("-p <path>", "--path=<path>", "Path to the target respository") do |path|
27
+ options[:path] = path
28
+ end
29
+ opts.on("-a <email>", "--author=<email>", "Author email for all commits") do |author_email|
30
+ options[:author_email] = author_email
31
+ puts "Setting author email to #{author_email}..."
32
+ end
33
+ opts.on("-n <name>", "--author-name=<name>", "Author name for all commits") do |author_name|
34
+ options[:author_name] = author_name
35
+ puts "Setting author name to #{author_name}..."
36
+ end
37
+ opts.on("-c <email>", "--committer=<email>", "Committer email for all commits") do |committer_email|
38
+ options[:committer_email] = committer_email
39
+ puts "Setting committer email to #{committer_email}..."
40
+ end
41
+ opts.on("-m <name>", "--committer-name=<name>", "Committer name for all commits") do |committer_name|
42
+ options[:committer_name] = committer_name
43
+ puts "Setting committer name to #{committer_name}..."
44
+ end
45
+ opts.on("-C <hash>", "--commit-hash=<hash>", "The hash of git commit that needs to be updated") do |commit_hash|
46
+ options[:commit_hash] = commit_hash
47
+ end
48
+ opts.on("-s", "--shuffle", "Whether to shuffle the commit date (default: no)") do |should_shuffle|
49
+ options[:should_shuffle_date] = true
50
+ end
51
+ opts.on("-f <date>", "--from=<date>", "Date of the first commit") do |from|
52
+ options[:from] = DateTime.strptime(from, '%Y-%m-%d').to_time # TODO: format data
53
+ end
54
+ opts.on("-t <date>", "--to=<date>", "Date of the latest commit") do |to|
55
+ options[:to] = DateTime.strptime(to, '%Y-%m-%d').to_time # TODO: format data
56
+ end
57
+ opts.on("-v", "--verbose", "Verbose mode") do
58
+ options[:verbose] = true
59
+ end
60
+ opts.on("-V", "--version", "Print version") do
61
+ options[:version] = true
62
+ end
63
+ opts.on("-d", "--dry-run", "Dry run without executing the actual command.") do
64
+ options[:dry_run] = true
65
+ end
66
+ end.parse!
67
+
68
+ if options[:version] then
69
+ puts "git-amend v#{GitAmend::VERSION}"
70
+ exit 0
71
+ end
72
+
73
+ all_commits = %x(git log --format=format:%H)
74
+ all_commits = all_commits.split(' ')
75
+ no_of_all_commits = all_commits.size
76
+
77
+ development_days_for_repo = (options[:to] - options[:from])/(3600 * 24)
78
+ days_offset = (0..development_days_for_repo).to_a.sample(no_of_all_commits).sort.reverse
79
+ no_of_commits_to_update = days_offset.size
80
+
81
+ Dir.chdir options[:path]
82
+ days_offset.each_index do |index|
83
+ commit_hash = all_commits[index]
84
+
85
+ if options[:commit_hash] and commit_hash != options[:commit_hash] then
86
+ puts "[#{index+1}/#{no_of_commits_to_update}] Skipping commit #{commit_hash} ..."
87
+ next
88
+ end
89
+
90
+ extra_cmd = ''
91
+ if options[:author_email]
92
+ extra_cmd += "export GIT_AUTHOR_EMAIL='#{options[:author_email]}'; "
93
+ end
94
+ if options[:author_name]
95
+ extra_cmd += "export GIT_AUTHOR_NAME='#{options[:author_name]}'; "
96
+ end
97
+ if options[:committer_email]
98
+ extra_cmd += "export GIT_COMMITTER_EMAIL='#{options[:committer_email]}'; "
99
+ end
100
+ if options[:committer_name]
101
+ extra_cmd += "export GIT_COMMITTER_NAME='#{options[:committer_name]}'; "
102
+ end
103
+
104
+ if options[:should_shuffle_date] then
105
+ offset = days_offset[index]
106
+ date = options[:from] + offset * (24 * 3600)
107
+ new_time = Time.new(date.year, date.month, date.day, (18..23).to_a.sample, (0..59).to_a.sample, (0..59).to_a.sample, "+02:00").to_s
108
+
109
+ extra_cmd += "export GIT_AUTHOR_DATE='#{new_time}'; "
110
+ extra_cmd += "export GIT_COMMITTER_DATE='#{new_time}'; "
111
+ end
112
+
113
+ command = <<-FOO
114
+ git filter-branch -f --env-filter "if test \\$GIT_COMMIT = '#{commit_hash}' ; then #{extra_cmd} fi && rm -fr '.git/refs/original/'"
115
+ FOO
116
+
117
+ if options[:verbose] then
118
+ puts command
119
+ end
120
+
121
+ puts "[#{index+1}/#{no_of_commits_to_update}] Updating commit #{commit_hash} ..."
122
+ unless options[:dry_run] then
123
+ system("FILTER_BRANCH_SQUELCH_WARNING=1 #{command}")
124
+ end
125
+ end
@@ -0,0 +1,5 @@
1
+
2
+ module GitAmend
3
+ VERSION = '0.0.1'
4
+ DATE = '2018-02-05'
5
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-amend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Han
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: timerizer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A CLI tool to update the information of exisiting git commit, such as
28
+ commit date, auther, etc.
29
+ email: hex0cter@gmail.com
30
+ executables:
31
+ - git-amend
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - bin/git-amend
37
+ - lib/version.rb
38
+ homepage: http://rubygems.org/gems/git-amend
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ source_code_uri: https://github.com/hex0cter/git-amend
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '2.2'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.4.5
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Update git commit info.
63
+ test_files: []