vcsh
vcsh copied to clipboard
vcsh delete should remove delete empty directories it leaves behind.
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.
FWIW, this could be fixed with rmdir -p
.
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.
PS: rmdir -p
should be safe in all cases even if I happen to make a mistake in parsing the basedir out.
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() {
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