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 tracking empty directories #157

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

embs
Copy link
Contributor

@embs embs commented Oct 21, 2017

Handle creating and removing placeholders files for versioning empty
directories as suggested in 1.

@@ -35,11 +35,16 @@ def f(args, repo):

for fp in args.files:
try:
empty_dir = fp.endswith('.glkeep')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create constant for .glkeep.

@@ -129,6 +129,9 @@ def process_paths():
self.skip_dir_cb(curr_dir_rel)
dirs[:] = []
continue
if not fps:
open(curr_dir + "/.glkeep", "a").close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use constant for .glkeep

@@ -63,6 +63,18 @@ def assert_not_in_repo(*cmds):
gl.status, gl.diff, gl.commit, gl.branch, gl.merge, gl.fuse, gl.remote,
gl.publish, gl.history)

class TestTrackEmptyDir(TestEndToEnd):
Copy link
Contributor Author

@embs embs Oct 21, 2017

Choose a reason for hiding this comment

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

Missing tests:

  • Track complex empty directories structures
  • Remove placeholder files when files are added to empty versioned directories

Update

  • List empty dirs on gl status

@embs embs force-pushed the track-empty-dirs branch 2 times, most recently from b7e973c to e2fcb52 Compare December 1, 2017 15:53
@@ -129,6 +129,9 @@ def process_paths():
self.skip_dir_cb(curr_dir_rel)
dirs[:] = []
continue
if not fps:
open(curr_dir + "/.glkeep.", "a").close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The . at the end of the filename is an attempt of fixing a problem on Windows. Reference: https://gist.github.com/ozh/4131243#1-rename

@embs embs force-pushed the track-empty-dirs branch 2 times, most recently from 30ba4e5 to e82cd1d Compare December 2, 2017 15:05
.appveyor.yml Outdated
@@ -5,25 +5,9 @@ environment:
PYTHON: 'C:\Python27\python.exe'
- GENERATOR: 'Visual Studio 10 Win64'
PYTHON: 'C:\Python27-x64\python.exe'
- GENERATOR: 'Visual Studio 10'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intend to remove these modifications after #158

Handle creating and removing placeholders files for versioning empty
directories as suggested in [1].

[1]: https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F
@embs embs force-pushed the track-empty-dirs branch 2 times, most recently from 155fc2d to 6b7a7ad Compare December 2, 2017 21:57
embs added 2 commits December 2, 2017 21:23
So users can operate (track, untrack, etc.) on them if they wish.
When tracking empty dirs.
empty_dir = self._mk_empty_dir('wanted_empty_dir')
gl.track(empty_dir)
gl.commit(_out='std.out', _bg=True)
while(sum(1 for line in open('std.out')) < 7):
Copy link
Contributor Author

@embs embs Dec 3, 2017

Choose a reason for hiding this comment

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

Couldn't find a better way for checking when commit dialogue is completely written to text editor. 😕

Update

This didn't work on Travis / AppVeyor (apparent infinite loop). I've switched for making multiple (many) file reads (following code) -- which was an advance but got this specific failure on Travis regarding many open files. I'll try handling the many open files issue.

out = ''
while(os.path.getsize('std.out') == 0 or out != open('std.out', 'r').read()):
  out = open('std.out', 'r').read()

@embs embs force-pushed the track-empty-dirs branch 2 times, most recently from c8f9d78 to 12a7202 Compare December 3, 2017 20:48
@embs embs changed the title [WORK IN PROGRESS] Allow tracking empty directories Allow tracking empty directories Dec 3, 2017
@embs
Copy link
Contributor Author

embs commented Dec 3, 2017

@spderosso what do you think about this (demo)? There are probably some uncovered edge cases but I think this PR addresses the use case which seems to be the most common one (tracking directories structures which will be populated later) as suggest by some people here.

I'd really appreciate to know if you think we're missing some important thing.

Thanks!

@spderosso
Copy link
Member

spderosso commented Feb 12, 2018

Sorry for my belated response, I got caught up with other things and I am just now catching up with Gitless. Thank you for the PR and for the demo (it really helps to see it working)! I think that adding support for dealing with empty directories is a great idea.

I am slightly concerned about implying that there are "tracked/untracked" directories. What's the difference between them? What does it mean for a directory to be tracked? I thought about this some time ago and I couldn't find a satisfying answer. For example, what happens if I untrack a directory that has files in it? There are lots of edge cases like this. If you have any thoughts, let me know!

Another alternative would be to retain the idea that files are the only things that can be tracked/untracked and we create the .glkeep file for users when they attempt to track a directory that has no files. As long as we are explicit about this I think that most users would understand what's going on. E.g, something like:

$ gl track empty-dir
! No files to track under empty-dir, creating .glkeep file
✓ .glkeep is now a tracked file

Then .glkeep behaves just like a normal file, so status would list it:

$ gl status
On branch ...

  empty-dir/.glkeep

But if you untrack a directory that only has the .glkeep file, we remove the file:

$ gl untrack empty-dir
! No files to untrack under empty-dir, removing .glkeep file
✓ .glkeep removed

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants