From 7fa6016fd15b40f433987d148df33ddbd500467f Mon Sep 17 00:00:00 2001 From: z38 Date: Wed, 20 Apr 2016 19:13:23 +0200 Subject: [PATCH] Add option to add tags to parent commits --- README.markdown | 4 ++++ lib/svn2git/migration.rb | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 9eb4740..0478562 100644 --- a/README.markdown +++ b/README.markdown @@ -210,6 +210,7 @@ Options Reference --trunk TRUNK_PATH Subpath to trunk from repository URL (default: trunk) --branches BRANCHES_PATH Subpath to branches from repository URL (default: branches) --tags TAGS_PATH Subpath to tags from repository URL (default: tags) + --tagparents Add tags without changes to its parent commit --rootistrunk Use this if the root level of the repo is equivalent to the trunk and there are no tags or branches --notrunk Do not import anything from trunk --nobranches Do not try to import any branches @@ -253,4 +254,7 @@ FAQ that very same tag in the original svn repo. This is only due to the fact that the svn tags allow changesets in them, making them not just annotated tags. + + In case your tags do not contain any changes, you can use `--tagparents` + to add the annotated tags to its parent. diff --git a/lib/svn2git/migration.rb b/lib/svn2git/migration.rb index bd0f6b2..ba29d72 100755 --- a/lib/svn2git/migration.rb +++ b/lib/svn2git/migration.rb @@ -49,6 +49,7 @@ def parse(args) options[:trunk] = 'trunk' options[:branches] = 'branches' options[:tags] = 'tags' + options[:tagparents] = false options[:exclude] = [] options[:revision] = nil options[:username] = nil @@ -91,6 +92,10 @@ def parse(args) options[:tags] = tags end + opts.on('--tagparents', 'Add tags without changes to its parent commit') do + options[:tagparents] = true + end + opts.on('--rootistrunk', 'Use this if the root level of the repo is equivalent to the trunk and there are no tags or branches') do options[:rootistrunk] = true options[:trunk] = nil @@ -285,12 +290,17 @@ def fix_tags date = run_command("git log -1 --pretty=format:'%ci' \"#{escape_quotes(tag)}\"").chomp("'").reverse.chomp("'").reverse author = run_command("git log -1 --pretty=format:'%an' \"#{escape_quotes(tag)}\"").chomp("'").reverse.chomp("'").reverse email = run_command("git log -1 --pretty=format:'%ae' \"#{escape_quotes(tag)}\"").chomp("'").reverse.chomp("'").reverse + diff = run_command("git diff --shortstat \"#{escape_quotes(tag)}~1\" \"#{escape_quotes(tag)}\"") run_command("#{git_config_command} user.name \"#{escape_quotes(author)}\"") run_command("#{git_config_command} user.email \"#{escape_quotes(email)}\"") original_git_committer_date = ENV['GIT_COMMITTER_DATE'] ENV['GIT_COMMITTER_DATE'] = escape_quotes(date) - run_command("git tag -a -m \"#{escape_quotes(subject)}\" \"#{escape_quotes(id)}\" \"#{escape_quotes(tag)}\"") + if diff.empty? and @options[:tagparents] + run_command("git tag -a -m \"#{escape_quotes(subject)}\" \"#{escape_quotes(id)}\" \"#{escape_quotes(tag)}~1\"") + else + run_command("git tag -a -m \"#{escape_quotes(subject)}\" \"#{escape_quotes(id)}\" \"#{escape_quotes(tag)}\"") + end ENV['GIT_COMMITTER_DATE'] = original_git_committer_date run_command("git branch -d -r \"#{escape_quotes(tag)}\"")