-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from swinkels/on-update-copy-changed-files-onl…
…y-pr On update, only copy changed files
- Loading branch information
Showing
15 changed files
with
221 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from os.path import join, exists | ||
from common import * | ||
from .common import * | ||
|
||
FILE = '.gitcc' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from common import * | ||
from .common import * | ||
|
||
class Clearcase: | ||
def rebase(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from common import * | ||
from .common import * | ||
from os.path import join, dirname | ||
|
||
class Status: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""Tag a particular commit as gitcc start point""" | ||
|
||
from common import * | ||
from .common import * | ||
|
||
def main(commit): | ||
tag(CI_TAG, commit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
"""Update the git repository with Clearcase manually, ignoring history""" | ||
|
||
from common import * | ||
import sync, reset | ||
from __future__ import print_function | ||
|
||
from .common import * | ||
from . import reset | ||
from . import sync | ||
|
||
|
||
def main(message): | ||
cc_exec(['update', '.'], errors=False) | ||
sync.main() | ||
git_exec(['add', '.']) | ||
git_exec(['commit', '-m', message]) | ||
reset.main('HEAD') | ||
if sync.main(): | ||
git_exec(['add', '.']) | ||
git_exec(['commit', '-m', message]) | ||
reset.main('HEAD') | ||
else: | ||
print("No files have changed, nothing to commit.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a document about the letter "a". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import imp | ||
import pkgutil | ||
import sys | ||
import unittest | ||
|
||
|
||
class ImportTestSuite(unittest.TestCase): | ||
|
||
def test_import_of_each_module(self): | ||
"""Import each module of package git_cc. | ||
This test was added because the import Python 3 requires you to use the | ||
relative package import syntax "from . import <module name>" to import | ||
packages from the same package, whereas Python 2 you could just use | ||
"import <module name>". | ||
""" | ||
import git_cc | ||
package_dir = os.path.dirname(os.path.abspath(git_cc.__file__)) | ||
for _, module_name, _ in pkgutil.iter_modules([package_dir]): | ||
self.try_module_import(package_dir, module_name) | ||
|
||
def try_module_import(self, package_dir, module_name): | ||
"""Try to import the given module from the given directory. | ||
If the import fails, this method throws an exception. | ||
Note that when the import was successful, this method immediately | ||
removes it from the list of loaded modules. | ||
""" | ||
|
||
module_path = os.path.join(package_dir, module_name) + ".py" | ||
|
||
# The call to imp.load_source fails when it indirectly imports a | ||
# module that was already loaded by a previous call to | ||
# imp.load_source under the same name. | ||
# | ||
# To give an example, say you have the following pseudo-code: | ||
# | ||
# imp.load_source("package.module-a", ... ) | ||
# imp.load_source("package.module-b", ... ) | ||
# | ||
# and module-b has an import of module a, then the second call | ||
# throws an ImportError with the message that it cannot import name | ||
# "module-b". | ||
# | ||
# To avoid this issue, we remove the module from the list of imported | ||
# modules once the import has succeeded. | ||
|
||
full_module_name = "git_cc." + module_name | ||
imp.load_source(full_module_name, module_path) | ||
del sys.modules[full_module_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import filecmp | ||
import os | ||
import shutil | ||
import stat | ||
import unittest | ||
|
||
|
||
from git_cc.sync import copy | ||
|
||
|
||
class SyncTestSuite(unittest.TestCase): | ||
|
||
def setUp(self): | ||
|
||
self.clear_filecmp_cache() | ||
|
||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
self.src_dir = os.path.join(current_dir, "copy-data") | ||
self.dst_dir = os.path.join(current_dir, "sandbox") | ||
|
||
if os.path.exists(self.dst_dir): | ||
shutil.rmtree(self.dst_dir) | ||
|
||
os.mkdir(self.dst_dir) | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.dst_dir) | ||
|
||
def test_copy_creates_new_file(self): | ||
|
||
fileName = "a.txt" | ||
|
||
copyIsDone = copy(fileName, src_dir=self.src_dir, dst_dir=self.dst_dir) | ||
self.assertTrue(copyIsDone) | ||
src_path = os.path.join(self.src_dir, fileName) | ||
dst_path = os.path.join(self.dst_dir, fileName) | ||
self.files_are_equal(src_path, dst_path) | ||
|
||
def test_copy_overwrites_existing_different_file(self): | ||
|
||
fileName = "a.txt" | ||
|
||
src_path = os.path.join(self.src_dir, fileName) | ||
with open(src_path, "r") as f: | ||
lines = f.readlines() | ||
lines[0] = lines[0].replace('e', 'f') | ||
|
||
dst_path = os.path.join(self.dst_dir, fileName) | ||
with open(dst_path, "w") as f: | ||
f.writelines(lines) | ||
|
||
# to make it more difficult, we give the destination file the same | ||
# file stats | ||
shutil.copystat(src_path, dst_path) | ||
|
||
copyIsDone = copy(fileName, src_dir=self.src_dir, dst_dir=self.dst_dir) | ||
self.assertTrue(copyIsDone) | ||
self.files_are_equal(src_path, dst_path) | ||
|
||
def test_copy_does_not_overwrite_equal_file(self): | ||
|
||
fileName = "a.txt" | ||
|
||
src_path = os.path.join(self.src_dir, fileName) | ||
dst_path = os.path.join(self.dst_dir, fileName) | ||
|
||
shutil.copyfile(src_path, dst_path) | ||
self.assertTrue(os.path.exists(dst_path)) | ||
|
||
# We make the destination file read-only. If the copy statement throws | ||
# an exception, it did not recognize that the destination file was the | ||
# same and tried to copy it. | ||
os.chmod(dst_path, stat.S_IREAD) | ||
|
||
copyIsDone = copy(fileName, src_dir=self.src_dir, dst_dir=self.dst_dir) | ||
self.assertFalse(copyIsDone) | ||
|
||
def files_are_equal(self, src_path, dst_path): | ||
|
||
self.clear_filecmp_cache() | ||
|
||
self.assertTrue(filecmp.cmp(src_path, dst_path)) | ||
|
||
src_stats = os.stat(src_path) | ||
dst_stats = os.stat(dst_path) | ||
self.assertAlmostEqual(src_stats.st_mtime, dst_stats.st_mtime, | ||
places=2) | ||
|
||
def clear_filecmp_cache(self): | ||
"""Clear the cache of module filecmp to trigger new file comparisons. | ||
Module filecmp keeps a cache of file comparisons so it does not have to | ||
recompare files whose stats have not changed. This disrupts tests in | ||
this suite which compare files with the same paths and stats but with | ||
different contents. For that reason, we can clear the cache. | ||
Do note that this function uses an internal variable of filecmp and can | ||
break when that variable is removed, renamed etc. | ||
""" | ||
filecmp._cache = {} |