Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sync empty folders from CC to Git repo #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions git_cc/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

ARGS = {
'cache': 'Use the cache for faster syncing',
'dry_run': 'Only print the paths of files to be synced'
'dry_run': 'Only print the paths of files to be synced',
'sync_empty_folders': 'Sync empty folders from dest to src folder'
}


Expand Down Expand Up @@ -78,6 +79,19 @@ def do_sync(self):
self.dst_root):
copied_file_count += 1
return copied_file_count

def do_sync_empty_folders(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to do this I wouldn't have a separate function, I would pass an argument to do_sync to avoid the duplication here.

empty_folders_count = 0
for rel_dir, file_names in self.iter_src_files():
if len(file_names) == 0 and len(rel_dir) > 0:
print("Found Empty dir %s" % rel_dir)
file_path = os.path.join(self.dst_root, rel_dir, '.keep')
print("Create file %s" % file_path)
mkdirs(file_path)
with open(file_path, "w") as text_file:
text_file.write("Keep it for empty folder")
empty_folders_count += 1
return empty_folders_count

def iter_src_files(self):
for src_dir in self.src_dirs:
Expand Down Expand Up @@ -116,7 +130,7 @@ def collect_private_files(self):
return output_as_set(command.split(' '))


def main(cache=False, dry_run=False):
def main(cache=False, dry_run=False, sync_empty_folders=False):
validateCC()
if cache:
return syncCache()
Expand All @@ -132,7 +146,10 @@ def main(cache=False, dry_run=False):
if cfg.ignorePrivateFiles():
syncClass = ClearCaseSync

return syncClass(src_root, src_dirs, dst_root, sync_file).do_sync()
if sync_empty_folders:
return syncClass(src_root, src_dirs, dst_root, sync_file).do_sync_empty_folders()
else:
return syncClass(src_root, src_dirs, dst_root, sync_file).do_sync()


def output_as_set(command):
Expand Down