diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c9be681 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: ruby +rvm: + - 2.4.1 + - jruby + - ruby-head +matrix: + allow_failures: + - rvm: ruby-head +branches: + only: + - develop diff --git a/ChangeLog.markdown b/ChangeLog.md similarity index 82% rename from ChangeLog.markdown rename to ChangeLog.md index f8d7239..7ed3111 100644 --- a/ChangeLog.markdown +++ b/ChangeLog.md @@ -8,10 +8,40 @@ * Added the ability to specify the '--branches' and '--tags' arguments multiple times (thanks pdf). * Fixed a problem with processing of the '--exclude' argument (improper quoting internally) (thanks pdf). +# 2.3.3 - 2016-03-02 + This is a bugfix release. It provides fix for git localized messages issue, and also fixes "gc is already running" message. + + As git2svn runs git to do it's things (and analyzes it's responses in some points), it is necessary to set LANGUAGE environment variable to "en_US" to fix this kind of error: + + Running command: git branch --track "" "remotes/svn/" + fatal: Не удалось настроить информацию отслеживания; стартовая точка «remotes/svn/» не является веткой. + ******************************************************************** + svn2git warning: Tracking remote SVN branches is deprecated. + In a future release local branches will be created without tracking. + If you must resync your branches, run: svn2git --rebase + ******************************************************************** + Running command: git checkout "" + error: pathspec '' did not match any file(s) known to git. + command failed: + git checkout "" + + Notice localized message of git output. You can fix it with new key `--force-en-us-to-git`. + + Also there was changes in git, which triggers `git gc --auto` after some point of modifications to local git repo, so now svn2git modifies `gc.auto` option, sets it to `0` to disable automatic packing of loose objects. + This fixes failing at the end of svn2git script, where it calls `git gc` explicitly: + + Running command: git gc + fatal: gc is already running on machine '' pid (use --force if not) + command failed: + git gc + + For me, `gc ---auto` starts just after `fetch`, and while svn2git finishes it's work (really fast) it stays running. When svn2git starts `git gc` explicitly, this new process conflicts with already running process, causing an error message. + + # 2.3.2 - 2014-06-08 This is a bugfix release. It fixes issues running with Windows using MRI ruby and fixes a problem with Ruby 1.8.7. - + * Removed open4 dependency. svn2git no longer has any runtime dependencies and things work well on Windows again. * Fixed an issue with Ruby 1.8.7, which doesn't implicitly require the 'thread' library meaning classes that library weren't in scope. @@ -23,20 +53,20 @@ issue a "git pull" to fetch the changes. git-svn ceased allowing this in 1.8.3.2, which broke svn2git with that version of git and all subsequent versions. The rationale seemed to be in order to prevent pushing changes from git-svn back up and breaking the remote link, but this was never something svn2git supported anyway. - + Acknowledging the new reality of upstream, the old behavior is retained but deprecated for users of git < 1.8.3.2. We'll be removing the establishment of remote tracking SVN branches in the 2.5.0 release. If you wish to sync back with upstream, run `svn2git --rebase`. If you're on git >= 1.8.3.2 your only option for resynchronizing is to use `svn2git --rebase`. - + Many thanks to ktdreyer for modernizing the test suite and Daniel Ruf (DanielRuf) for pushing on the git compatibility issue. - + * Fixed creating local branches for remote SVN branches in git >= 1.8.3.2. * Fixed verbose logging of sub-process STDERR stream. * Added MIT license metadata to gemspec. * Switched to minitest to get tests working on Ruby 1.9+ with minitest 5+ installed. - + # 2.3.0 - 2014-05-14 @@ -112,7 +142,7 @@ Thanks to Francois Rey (fmjrey), Sven Axelsson (svenax), and Julian Taylor (juliantaylor) for submitting all the patches that comprise this release. svn2git now works with a much wider array SVN repositories because of their efforts. - + * Added --no-minimize-url option for migrating specific subprojects from an SVN repo containing several projects (thanks fmjrey). * Added --username option for migrating password-protected repositories (thanks svenax). * Added --revision option for specifying the revision to start importing from (thanks svenax). @@ -147,7 +177,7 @@ # 1.3.1 - 2009-06-09 Thanks to KUBO Atsuhiro (iteman) for finding a problem with the tagging process and providing a patch. - + * Fixed a problem with creating actual git tags when the SVN tags path was named anything other than 'tags.' # 1.3.0 - 2009-06-09 @@ -182,14 +212,14 @@ * Improved docs. # 1.1.1 - 2009-04-15 - + * Started using Jeweler for gem management. * Fixed issue with not loading up RubyGems appropriately. # 1.1.0 - 2009-01-02 * First release since nirvdrum fork. - + * Fixed issues with handling of tags and branches. * Added better logging of output from git-svn. * Wrap external command processing to capture failures. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f04b10 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM ubuntu:16.04 +RUN apt-get -qq update +RUN apt-get -q -y install git-core git-svn ruby +RUN gem install svn2git +CMD ["svn2git"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..bcbfa26 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "minitest" +gem "rake" +gem "jeweler" diff --git a/README.markdown b/README.md similarity index 77% rename from README.markdown rename to README.md index 7b1165c..dfa8490 100644 --- a/README.markdown +++ b/README.md @@ -68,10 +68,59 @@ Make sure you have git, git-svn, and ruby installed. svn2git is a ruby wrapper $ sudo apt-get install git-core git-svn ruby -Once you have the necessary software on your system, you can install svn2git through rubygems, which will add the `svn2git` command to your PATH. +Once you have the necessary software on your system, you can install svn2git through rubygems, which will add the `svn2git` command to your PATH. $ sudo gem install svn2git +Some hints before you start +----- +In Ubuntu 14.04 you have to install latest git and subversion versions to successfully done conversion. +This fixes "error: git-svn died of signal 11" issue. + +Upgrade can be done using PPAs: +[https://launchpad.net/~dominik-stadler/+archive/ubuntu/subversion-1.9](https://launchpad.net/~dominik-stadler/+archive/ubuntu/subversion-1.9) +[https://launchpad.net/~git-core/+archive/ubuntu/ppa](https://launchpad.net/~git-core/+archive/ubuntu/ppa) + +To add each ppa use commands: + + $ sudo add-apt-repository ppa:dominik-stadler/subversion-1.9 + $ sudo add-apt-repository ppa:git-core/ppa + +or add -E to sudo if you are using proxy to preserve environment variables with proxy information + + $ sudo -E add-apt-repository ppa:dominik-stadler/subversion-1.9 + $ sudo -E add-apt-repository ppa:git-core/ppa + +After that update repository cache and upgrade packages + + $ sudo apt-get update + $ sudo apt-get install git-core git-svn subversion + +This will upgrade git, git-svn and subversion to latest version (as for 2016-03-02) + +Also if you get this kind of error + + Running command: git branch --track "" "remotes/svn/" + fatal: Не удалось настроить информацию отслеживания; стартовая точка «remotes/svn/» не является веткой. + ******************************************************************** + svn2git warning: Tracking remote SVN branches is deprecated. + In a future release local branches will be created without tracking. + If you must resync your branches, run: svn2git --rebase + ******************************************************************** + Running command: git checkout "" + error: pathspec '' did not match any file(s) known to git. + command failed: + git checkout "" + +Notice localized message of git. As svn2git script analyzes git answer here, force English messages from git, using new key `--force-en-us-to-git` (testing feature). +This sets LANGUAGE environment variable to "en_US" for svn2git and its child processes. + +Also if you have to provide a password to subversion repository and stuck on + + Authentication realm: CollabNet Subversion Repository + Password for '': + +then try to invoke in console `svn co` first to authorize at subversion repo, it will cache your visit, and then rerun svn2git command. Usage ----- @@ -143,6 +192,16 @@ specified trunk=foo branches=bar and tags=foobar it would be referencing http://svn.example.com/path/to/repo/foo as your trunk, and so on. However, in case 4 it references the root of the repo as trunk. +### Tags Notice ### + +Notice, that if you want to push tags also to git repo, you need to run not only + + git push origin --all + +but also + + git push origin --tags + ### Repository Updates ### As of svn2git 2.0 there is a new feature to pull in the latest changes from SVN into your @@ -202,11 +261,11 @@ Options Reference $ svn2git --help Usage: svn2git SVN_URL [options] - + Specific options: --rebase Instead of cloning a new project, rebase an existing one against SVN --username NAME Username for transports that needs it (http(s), svn) - --password PASS Password for transports that needs it (http(s), svn) + --password PASSWORD Password for transports that needs it (http(s), svn) --trunk TRUNK_PATH Subpath to trunk from repository URL (default: trunk) --branches BRANCHES_PATH Subpath to branches from repository URL (default: branches); can be used multiple times --tags TAGS_PATH Subpath to tags from repository URL (default: tags); can be used multiple times @@ -221,7 +280,9 @@ Options Reference --authors AUTHORS_FILE Path to file containing svn-to-git authors mapping (default: ~/.svn2git/authors) --exclude REGEX Specify a Perl regular expression to filter paths when fetching; can be used multiple times -v, --verbose Be verbose in logging -- useful for debugging issues - + --rebasebranch REBASEBRANCH Rebase specified branch. + --force-en-us-to-git Force en_US locale to be used by git commands, called by this script. + -h, --help Show this message FAQ @@ -234,9 +295,9 @@ FAQ Those commits are the first (head) commit of branch in svn that is associated with that tag. If you want to see all the branches and tags and their relationships in gitk you can run the following: gitk --all - + For further details please refer to FAQ #2. - + 2. Why don't you reference the parent of the tag commits instead? In svn you are forced to create what are known in git as annotated tags. @@ -246,11 +307,10 @@ FAQ treated as an annotated tag. Hence, for there to be a true 1-to-1 mapping between git and svn we have to transfer over the svn commit which acts as an annotated tag and then tag that commit in git using an annotated tag. - + If we were to reference the parent of this svn tagged commit there could potentially be situations where a developer would checkout a tag in git and the resulting code base would be different than if they checked out 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. - diff --git a/bin/svn2git b/bin/svn2git index 63bbf00..0beaf59 100644 --- a/bin/svn2git +++ b/bin/svn2git @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/ruby # Copyright (c) 2008 James Coglan # diff --git a/lib/svn2git/migration.rb b/lib/svn2git/migration.rb index 4de8a9e..1c6cbff 100755 --- a/lib/svn2git/migration.rb +++ b/lib/svn2git/migration.rb @@ -26,6 +26,13 @@ def initialize(args) end def run! + log "LANGUAGE is: #{ENV["LANGUAGE"]}\n" + if @options[:forceenustogit] + log "Set LANGUAGE environment variable to \"en_US.\"\n" + ENV["LANGUAGE"]="en_US" + log "LANGUAGE is: #{ENV["LANGUAGE"]}\n" + end + if @options[:rebase] get_branches elsif @options[:rebasebranch] @@ -37,6 +44,13 @@ def run! fix_tags fix_trunk optimize_repos + + ensure + unless @gc_auto_is_off.nil? + run_command("#{git_config_command} --get gc.auto", false) + run_command("#{git_config_command} --unset gc.auto") + run_command("#{git_config_command} --get gc.auto", false) + end end def parse(args) @@ -54,8 +68,9 @@ def parse(args) options[:username] = nil options[:password] = nil options[:rebasebranch] = false + options[:forceenustogit] = false - if File.exists?(File.expand_path(DEFAULT_AUTHORS_FILE)) + if File.exist?(File.expand_path(DEFAULT_AUTHORS_FILE)) options[:authors] = DEFAULT_AUTHORS_FILE end @@ -138,6 +153,10 @@ def parse(args) options[:rebasebranch] = rebasebranch end + opts.on('--force-en-us-to-git', 'Force en_US locale to be used by git commands, called by this script.') do + options[:forceenustogit] = true + end + opts.separator "" # No argument, shows at tail. This will print an options summary. @@ -224,6 +243,11 @@ def clone! run_command(cmd, true, true) end + run_command("#{git_config_command} --get gc.auto", false) + run_command("#{git_config_command} gc.auto 0") + gc_auto_is_off = true + run_command("#{git_config_command} --get gc.auto", false) + run_command("#{git_config_command} svn.authorsfile #{authors}") unless authors.nil? cmd = "git svn fetch " @@ -261,11 +285,11 @@ def get_branches end def get_rebasebranch - get_branches + get_branches @local = @local.find_all{|l| l == @options[:rebasebranch]} @remote = @remote.find_all{|r| r.include? @options[:rebasebranch]} - if @local.count > 1 + if @local.count > 1 pp "To many matching branches found (#{@local})." exit 1 elsif @local.count == 0 @@ -330,7 +354,14 @@ def fix_branches svn_branches.delete_if { |b| b.strip !~ %r{^svn\/} } if @options[:rebase] - run_command("git svn fetch", true, true) + revision = @options[:revision] + cmd = "git svn fetch " + unless revision.nil? + range = revision.split(":") + range[1] = "HEAD" unless range[1] + cmd += "-r #{range[0]}:#{range[1]} " + end + run_command(cmd, true, true) end svn_branches.each do |branch| @@ -348,7 +379,7 @@ def fix_branches if @cannot_setup_tracking_information run_command(Svn2Git::Migration.checkout_svn_branch(branch)) else - status = run_command("git branch --track \"#{branch}\" \"remotes/svn/#{branch}\"", false) + status = run_command("git branch \"#{branch}\" \"remotes/svn/#{branch}\"", false) # As of git 1.8.3.2, tracking information cannot be set up for remote SVN branches: # http://git.661346.n2.nabble.com/git-svn-Use-prefix-by-default-td7594288.html#a7597159 @@ -357,7 +388,7 @@ def fix_branches # Our --rebase option obviates the need for read-only tracked remotes, however. So, we'll # deprecate the old option, informing those relying on the old behavior that they should # use the newer --rebase otion. - if status =~ /Cannot setup tracking information/m + if status =~ /fatal:.+'#{branch}'.+/ @cannot_setup_tracking_information = true run_command(Svn2Git::Migration.checkout_svn_branch(branch)) else @@ -430,13 +461,17 @@ def run_command(cmd, exit_on_error=true, printout_output=false) # sub-process's stdin pipe. Thread.new do loop do - user_reply = @stdin_queue.pop + begin + user_reply = @stdin_queue.pop - # nil is our cue to stop looping (pun intended). - break if user_reply.nil? + # nil is our cue to stop looping (pun intended). + break if user_reply.nil? - stdin.puts user_reply - stdin.close + $stdin.puts user_reply + $stdin.close + rescue IOError + $stdout.print "No input requested.\n" + end end end @@ -448,7 +483,7 @@ def run_command(cmd, exit_on_error=true, printout_output=false) if exit_on_error && $?.exitstatus != 0 $stderr.puts "command failed:\n#{cmd}" - exit -1 + exit(1) end ret @@ -468,7 +503,7 @@ def verify_working_tree_is_clean status = run_command('git status --porcelain --untracked-files=no') unless status.strip == '' puts 'You have local pending changes. The working tree must be clean in order to continue.' - exit -1 + exit(1) end end @@ -476,7 +511,7 @@ def git_config_command if @git_config_command.nil? status = run_command('git config --local --get user.name', false) - @git_config_command = if status =~ /unknown option/m + @git_config_command = if status =~ /error: .+\s.+git config \[.+/m 'git config' else 'git config --local' @@ -488,4 +523,3 @@ def git_config_command end end - diff --git a/svn2git.gemspec b/svn2git.gemspec index c5a786f..c230011 100644 --- a/svn2git.gemspec +++ b/svn2git.gemspec @@ -15,13 +15,13 @@ Gem::Specification.new do |s| s.email = "nirvdrum@gmail.com" s.executables = ["svn2git"] s.extra_rdoc_files = [ - "ChangeLog.markdown", - "README.markdown" + "ChangeLog.md", + "README.md" ] s.files = [ - "ChangeLog.markdown", + "ChangeLog.md", "MIT-LICENSE", - "README.markdown", + "README.md", "Rakefile", "VERSION.yml", "bin/svn2git",