Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Handle renames, and test it. Test copies.
Browse files Browse the repository at this point in the history
Fix update from git when there are no local changes, use --squash instead of --no-commit, because --no-commit makes a commit in a fast forward merge
  • Loading branch information
Sergio Cambra authored and francois committed Oct 15, 2008
1 parent ff41549 commit 25103b9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 20 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
= Integration tests to verify

* Handles copies
* Handles conflicts (currently when there is a conflict doesn't update from git repositories, update from svn repositories but ignores the conflict)
* Maybe handle renames
* Force addition of Git repositories, because the files might be ignored in .gitignore
17 changes: 7 additions & 10 deletions lib/piston/git/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def update_to(commit)
Dir.chdir(@dir) do
logger.debug {"in dir #{@dir}"}
git(:commit, '-a', '-m', 'local changes') unless git(:status) =~ /nothing to commit/
git(:merge, '--no-commit', commit)
added_and_deleted
git(:merge, '--squash', commit)

output = git(:status)
added = output.scan(/new file:\s+(.*)$/).flatten
deleted = output.scan(/deleted:\s+(.*)$/).flatten
renamed = output.scan(/renamed:\s+(.+) -> (.+)$/)
[added, deleted, renamed]
end
end

Expand All @@ -85,14 +90,6 @@ def remotely_modified
commit = git('ls-remote', repository.url, recalled_values[Piston::Git::BRANCH]).match(/\w+/)[0]
commit != self.commit
end

private
def added_and_deleted
output = git(:status)
added = output.scan(/new file:\s+(.*)$/).flatten
deleted = output.scan(/deleted:\s+(.*)$/).flatten
[added, deleted]
end
end
end
end
6 changes: 6 additions & 0 deletions lib/piston/git/working_copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def delete(deleted)
deleted.each { |item| git(:rm, item) }
end
end

def rename(renamed)
Dir.chdir(path) do
renamed.each { |from, to| git(:mv, from, to) }
end
end

def update(revision, to, lock)
tmpdir = temp_dir_name
Expand Down
11 changes: 6 additions & 5 deletions lib/piston/svn/revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def update_to(revision)
else
raise Failed, "Could not update #{@dir} to revision #{revision} from #{repository.url}\n#{answer}"
end
added_and_deleted(answer)
added = relative_paths(answer.scan(/^A\s+(.*)$/).flatten)
deleted = relative_paths(answer.scan(/^D\s+(.*)$/).flatten)
renamed = []
[added, deleted, renamed]
end

def remember_values
Expand Down Expand Up @@ -87,10 +90,8 @@ def remotely_modified
end

private
def added_and_deleted(output)
added = output.scan(/^A\s+(.*)$/).flatten.map { |item| Pathname.new(item).relative_path_from(@dir) }
deleted = output.scan(/^D\s+(.*)$/).flatten.map { |item| Pathname.new(item).relative_path_from(@dir) }
[added, deleted]
def relative_paths(paths)
paths.map { |item| Pathname.new(item).relative_path_from(@dir) }
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/piston/svn/working_copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def delete(deleted)
end
end

def rename(renamed)
renamed.each do |from, to|
svn(:mv, path + from, path + to)
end
end

# Returns all defined externals (recursively) of this WC.
# Returns a Hash:
# {"vendor/rails" => {:revision => :head, :url => "http://dev.rubyonrails.org/svn/rails/trunk"},
Expand Down
9 changes: 7 additions & 2 deletions lib/piston/working_copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def add(added)
end

# delete some files from working copy
def delete(added)
def delete(deleted)
end

# rename some files in working copy
def rename(renamed)
end

# Stores a Hash of values that can be retrieved later.
Expand Down Expand Up @@ -197,9 +201,10 @@ def update(revision, to, lock)
copy_to(revision)

logger.info {"Updating to #{to.revision}"}
added, deleted = revision.update_to(to.revision)
added, deleted, renamed = revision.update_to(to.revision)

logger.debug {"Copying files from temporary directory"}
rename(renamed) # rename before copy because copy_from will copy these files
copy_from(revision)
add(added)
delete(deleted)
Expand Down
10 changes: 9 additions & 1 deletion test/integration/test_git_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def setup
git(:init)
File.open("README", "wb") {|f| f.write "Readme - first commit\n"}
File.open("file_in_first_commit", "wb") {|f| f.write "file_in_first_commit"}
File.open("file_to_rename", "wb") {|f| f.write "file_to_rename"}
File.open("file_to_copy", "wb") {|f| f.write "file_to_copy"}
git(:add, ".")
git(:commit, "-m", "'first commit'")
end
Expand Down Expand Up @@ -57,6 +59,8 @@ def test_import
#\tnew file: vendor/parent/.piston.yml
#\tnew file: vendor/parent/README
#\tnew file: vendor/parent/file_in_first_commit
#\tnew file: vendor/parent/file_to_rename
#\tnew file: vendor/parent/file_to_copy
#
)

Expand All @@ -78,6 +82,8 @@ def test_update
File.open("README", "ab") {|f| f.write "Readme - second commit\n"}
git(:rm, "file_in_first_commit")
File.open("file_in_second_commit", "wb") {|f| f.write "file_in_second_commit"}
FileUtils.cp("file_to_copy", "copied_file")
git(:mv, "file_to_rename", "renamed_file")
git(:add, ".")
git(:commit, "-m", "'second commit'")
end
Expand All @@ -87,7 +93,7 @@ def test_update
end

Dir.chdir(wc_path) do
assert_equal CHANGE_STATUS.split("\n"), git(:status).split("\n")
assert_equal CHANGE_STATUS.split("\n").sort, git(:status).split("\n").sort
end
assert_equal README, File.readlines(wc_path + "vendor/parent/README").join
end
Expand All @@ -100,6 +106,8 @@ def test_update
#\tmodified: vendor/parent/README
#\tdeleted: vendor/parent/file_in_first_commit
#\tnew file: vendor/parent/file_in_second_commit
#\tnew file: vendor/parent/copied_file
#\trenamed: vendor/parent/file_to_rename -> vendor/parent/renamed_file
#
)
README = %Q(Readme - modified after imported
Expand Down
9 changes: 9 additions & 0 deletions test/integration/test_git_svn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def setup
git(:init)
File.open(parent_path + "README", "wb") {|f| f.write "Readme - first commit\n"}
File.open(parent_path + "file_in_first_commit", "wb") {|f| f.write "file_in_first_commit"}
File.open("file_to_rename", "wb") {|f| f.write "file_to_rename"}
File.open("file_to_copy", "wb") {|f| f.write "file_to_copy"}
git(:add, ".")
git(:commit, "-m", "'first commit'")
end
Expand Down Expand Up @@ -92,6 +94,8 @@ def test_import_from_tag
A vendor/parent/.piston.yml
A vendor/parent/README
A vendor/parent/file_in_first_commit
A vendor/parent/file_to_rename
A vendor/parent/file_to_copy
)

def test_update
Expand All @@ -109,6 +113,8 @@ def test_update
File.open("README", "ab") {|f| f.write "Readme - second commit\n"}
git(:rm, "file_in_first_commit")
File.open("file_in_second_commit", "wb") {|f| f.write "file_in_second_commit"}
FileUtils.cp("file_to_copy", "copied_file")
git(:mv, "file_to_rename", "renamed_file")
git(:add, ".")
git(:commit, "-m", "'second commit'")
end
Expand All @@ -123,6 +129,9 @@ def test_update
M vendor/parent/README
A vendor/parent/file_in_second_commit
D vendor/parent/file_in_first_commit
A vendor/parent/copied_file
D vendor/parent/file_to_rename
A + vendor/parent/renamed_file
)
README = %Q(Readme - modified after imported
Readme - first commit
Expand Down
7 changes: 7 additions & 0 deletions test/integration/test_svn_svn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def setup
svn :mkdir, "--parents", "parent", "wc/tags", "wc/branches", "wc/trunk/vendor"
File.open("parent/README", "wb") {|f| f.write "Readme - first commit\n"}
File.open("parent/file_in_first_commit", "wb") {|f| f.write "file_in_first_commit"}
File.open("parent/file_to_rename", "wb") {|f| f.write "file_to_rename"}
File.open("parent/file_to_copy", "wb") {|f| f.write "file_to_copy"}
svn :add, "parent/*"
end
svn :commit, wc_path, "--message", "'first commit'"
Expand Down Expand Up @@ -62,6 +64,8 @@ def test_update
svn(:rm, "file_in_first_commit")
File.open("file_in_second_commit", "wb") {|f| f.write "file_in_second_commit"}
svn(:add, "file_in_second_commit")
svn(:copy, "file_to_copy", "copied_file")
svn(:mv, "file_to_rename", "renamed_file")
svn(:commit, "-m", "'second commit'")
end

Expand All @@ -79,6 +83,9 @@ def test_update
M vendor/parent/README
D vendor/parent/file_in_first_commit
A vendor/parent/file_in_second_commit
A vendor/parent/copied_file
D vendor/parent/file_to_rename
A vendor/parent/renamed_file
)
README = %Q(Readme - modified after imported
Readme - first commit
Expand Down

0 comments on commit 25103b9

Please sign in to comment.