Skip to content

Commit

Permalink
Makes ignore of private files optional
Browse files Browse the repository at this point in the history
  • Loading branch information
swinkels committed Oct 31, 2016
1 parent 8ba14a2 commit 883754b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@ Changelog for git-cc
1.0.1 (unreleased) 1.0.1 (unreleased)
------------------ ------------------


- gitcc --update only syncs files under ClearCase control.
- Various fixes to work towards Python 3 compatibility. - Various fixes to work towards Python 3 compatibility.
- Various improvements to the update command: - Various improvements to the update command:
- only copies files that have changed; - only copies files that have changed;
Expand Down
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -100,6 +100,7 @@ allows you to limit which branches and folders you import from:
include = FolderA|FolderB include = FolderA|FolderB
exclude = FolderA/sub/folder|FolderB/other/file exclude = FolderA/sub/folder|FolderB/other/file
users_module_path = users.py users_module_path = users.py
ignore_private_files = False
debug = False debug = False
type = UCM type = UCM
[master] [master]
Expand Down Expand Up @@ -132,6 +133,12 @@ from directory .git. But you can also use an absolute users module path.
If you do not specify the users module path in the config file, the ClearCase If you do not specify the users module path in the config file, the ClearCase
user information will be used. user information will be used.


If you make a snapshot of a ClearCase VOB, you copy all the files that are
visible in the view, including view-private files. This might not be what you
want, for example if the VOB contains all kinds of build artifacts. To only
copy the files that are actually under ClearCase control, set the key
'ignore\_private\_files' to True.

## Notes ## Notes


Can either work with static or dynamic views. I use dynamic at work because Can either work with static or dynamic views. I use dynamic at work because
Expand Down
9 changes: 9 additions & 0 deletions git_cc/common.py
Expand Up @@ -181,6 +181,15 @@ def getUsersModulePath(self):
abs_path = os.path.join(config_dir, path) abs_path = os.path.join(config_dir, path)
return abs_path return abs_path


def ignorePrivateFiles(self):
"""Return true if and only if private files should not be synced.
If this option holds, only the files that are under ClearCase control
will be synced. Otherwise all the files in the VOB are synced.
"""
return self.getCore('ignore_private_files', False)



def write(file, blob): def write(file, blob):
_write(file, blob) _write(file, blob)
Expand Down
8 changes: 7 additions & 1 deletion git_cc/sync.py
Expand Up @@ -126,7 +126,13 @@ def main(cache=False, dry_run=False):
dst_root = GIT_DIR dst_root = GIT_DIR
sync_file = SyncFile() if not dry_run else IgnoreFile() sync_file = SyncFile() if not dry_run else IgnoreFile()


return ClearCaseSync(src_root, src_dirs, dst_root, sync_file).do_sync() # determine whether we should sync all files or only the files that are
# under ClearCase control
syncClass = Sync
if cfg.ignorePrivateFiles():
syncClass = ClearCaseSync

return syncClass(src_root, src_dirs, dst_root, sync_file).do_sync()




def output_as_set(command): def output_as_set(command):
Expand Down
2 changes: 2 additions & 0 deletions tests/sync-config/gitcc
@@ -0,0 +1,2 @@
[core]
ignore_private_files=True
Empty file added tests/sync-config/gitcc-empty
Empty file.
33 changes: 33 additions & 0 deletions tests/test_sync.py
Expand Up @@ -5,6 +5,7 @@
import stat import stat
import unittest import unittest


from git_cc.common import GitConfigParser
from git_cc.sync import Sync from git_cc.sync import Sync
from git_cc.sync import SyncFile from git_cc.sync import SyncFile
from git_cc.sync import ClearCaseSync from git_cc.sync import ClearCaseSync
Expand All @@ -18,6 +19,8 @@
else: else:
from unittest.mock import Mock from unittest.mock import Mock


_current_dir = os.path.dirname(__file__)



class CopyTestSuite(unittest.TestCase): class CopyTestSuite(unittest.TestCase):


Expand Down Expand Up @@ -189,3 +192,33 @@ def test_collect_output(self):
contents = output_as_set([sys.executable, module, directory]) contents = output_as_set([sys.executable, module, directory])


self.assertEqual(set(["a.txt", "b.txt"]), contents) self.assertEqual(set(["a.txt", "b.txt"]), contents)


class SyncConfigTestSuite(unittest.TestCase):

def test_retrieval_of_setting_using_config(self):

gitcc_config_path = self.get_path_to("gitcc")

cfg = GitConfigParser("don't care section", gitcc_config_path)
cfg.read()

self.assertTrue(cfg.ignorePrivateFiles())

def test_retrieval_of_setting_using_empty_config(self):

gitcc_config_path = self.get_path_to("gitcc-empty")

cfg = GitConfigParser("don't care section", gitcc_config_path)
cfg.read()

self.assertFalse(cfg.ignorePrivateFiles())

def get_path_to(self, file_name):
"""Return the path to the given file in directory "sync-config".
Directory "sync-config" is located in the same directory as the current
file.
"""
return os.path.join(_current_dir, "sync-config", file_name)

0 comments on commit 883754b

Please sign in to comment.