diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2019-12-14 15:43:08 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2019-12-14 15:57:51 -0700 |
commit | 3f038f24daabf38358902dafdddeb168130483ce (patch) | |
tree | 55d885a138808909d3452cc36b0bbfaa733788b0 /bin/annex-drop-files-deleted-by-commit | |
parent | 576c1109cec7affd17931b9197ac37cc5802ecae (diff) | |
download | dotfiles-3f038f24daabf38358902dafdddeb168130483ce.tar.gz |
mostly untested annex-drop-files-deleted-by-commit script
Diffstat (limited to 'bin/annex-drop-files-deleted-by-commit')
-rwxr-xr-x | bin/annex-drop-files-deleted-by-commit | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/annex-drop-files-deleted-by-commit b/bin/annex-drop-files-deleted-by-commit new file mode 100755 index 00000000..bc2eac16 --- /dev/null +++ b/bin/annex-drop-files-deleted-by-commit @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +# Copyright (C) 2019 Sean Whitton +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +use 5.028; +use strict; +use warnings; + +use File::Path qw(rmtree); +use File::Temp qw(tempdir); +use Git::Wrapper; +use Try::Tiny; + +# git wrapper setup +my $git = Git::Wrapper->new("."); +try { + $git->rev_parse({ git_dir => 1 }); +} +catch { + die "pwd doesn't look like a git repository ..\n"; +}; + +# process command line +# TODO support --from so can drop from special remotes too +my %drop_args = (); +if ($ARGV[0] eq '--force') { + $drop_args{force} = 1; + shift @ARGV; +} + +# go for it +my $temp = tempdir(CLEANUP => 1); +chmod 0700, $temp; +$git->worktree("add", { force => 1, no_checkout => 1 }, $temp); +my $worktree = Git::Wrapper->new($temp); +for (@ARGV) { + my ($commit) = $git->rev_parse($_); + my @deleted_files + = $git->diff({ name_only => 1, diff_filter => 'D' }, + "$commit~1..$commit"); + $worktree->checkout("$commit~1"); + # bypass Git::Wrapper so output goes to terminal + system('git', '-C', $temp, 'annex', 'drop', %drop_args, @deleted_files); +} +# we can't use `git worktree remove` because the way git-annex +# worktree support works breaks that command: git annex replaces the +# .git worktree file with a symlink +rmtree($temp); +$git->worktree("prune"); |