vcsh icon indicating copy to clipboard operation
vcsh copied to clipboard

vcsh delete should remove delete empty directories it leaves behind.

Open mek-apelsin opened this issue 12 years ago • 6 comments

mek-apelsin avatar Oct 07 '12 20:10 mek-apelsin

Which directories do you mean, exactly?

After some testing, only $XDG_CONFIG_HOME/vcsh/repo.d after the last repo being deleted comes to mind.

RichiH avatar Jul 19 '13 14:07 RichiH

FWIW, this could be fixed with rmdir -p.

RichiH avatar Jul 19 '13 14:07 RichiH

Note for future RichiH:

This patch:

diff --git a/vcsh b/vcsh
index 3fa63d7..42b38c4 100755
--- a/vcsh
+++ b/vcsh
@@ -174,6 +174,8 @@ To continue, type 'Yes, do as I say'"
                rm -f $file || info "could not delete '$file', continuing with deletion"
        done
        rm -rf "$GIT_DIR" || error "could not delete '$GIT_DIR'"
+       echo $GIT_DIR
+       rmdir -p "$GIT_DIR"
 }

 enter() {

does not work because of:

richih@rockhopper  ~ % work/git/vcsh/vcsh delete test
vcsh: info: This operation WILL DESTROY DATA!
These files will be deleted:

vcsh_test

AGAIN, THIS WILL DELETE YOUR DATA!
To continue, type 'Yes, do as I say'
Yes, do as I say
/home/richih/.config/vcsh/repo.d/test.git
rmdir: failed to remove `/home/richih/.config/vcsh/repo.d/test.git': No such file or directory
%

Sadly, there's no basedir on CLI, only basefile. I would like to avoid manually parsing & stripping that last bit so I'll need to ponder a bit if that's feasible.

RichiH avatar Jul 19 '13 14:07 RichiH

PS: rmdir -p should be safe in all cases even if I happen to make a mistake in parsing the basedir out.

RichiH avatar Jul 19 '13 14:07 RichiH

This barfs unless we delete the very last repo. There is no -q option for rmdir and --ignore-fail-on-non-empty is a GNU extension.

diff --git a/vcsh b/vcsh
index 3fa63d7..723e840 100755
--- a/vcsh
+++ b/vcsh
@@ -174,6 +174,7 @@ To continue, type 'Yes, do as I say'"
                rm -f $file || info "could not delete '$file', continuing with deletion"
        done
        rm -rf "$GIT_DIR" || error "could not delete '$GIT_DIR'"
+       rmdir -p "${0%/*}"
 }

 enter() {

RichiH avatar Jul 20 '13 11:07 RichiH

I think @mek-apelsin was referring to directories in the repository working tree, not to GIT_DIR.

The problem seems to be that git ls-files does not list directories by their own.

Maybe something like the following can be added to the delete command:

$dirs=$(git ls-tree --name-only -d -r HEAD | sort -r)

for dir in $dirs; do
   rmdir $dir ||  info "could not delete '$dir', continuing with deletion"
done

Inspired by https://superuser.com/a/450115

ao2 avatar Dec 14 '18 17:12 ao2