Skip to content

Instantly share code, notes, and snippets.

@jessehub
Last active December 12, 2015 10:09
Show Gist options
  • Save jessehub/4757180 to your computer and use it in GitHub Desktop.
Save jessehub/4757180 to your computer and use it in GitHub Desktop.
Helper for sorting out a lot of changes in between your repo and wc in svn. Triage before you start merging.
#!/usr/bin/perl
foreach (`svn status`) {
chomp;
/^(.)\s+(.*)$/;
($status, $file) = ($1, $2);
print "[$status]\t'$file'\n";
if ($status eq '?') {
newfile($file);
}
if ($status eq '!') {
gonefile($file);
}
if ($status eq 'M') {
modfile($file);
}
print "\n";
}
{
$response = 'w';
sub modfile($file) {
print "This is different. Keep the [r]epo version, or the [w]orking copy? (default is $resp)\n";
chomp($response = <STDIN>);
if ($response =~ /r/i) {
`svn revert $file` && print "\t[fetched from repo]\n";
}
}
}
sub gonefile($file) {
print "This file isn't in your working copy, but it exists in the repo.\n";
print "Fetch it [Y/n]\n>";
chomp($response = <STDIN>);
if ($response !~ /n/i) {
`svn revert $file` && print "\t[fetched from repo]\n";
}
}
sub newfile($file) {
print "This file is in your working copy, but not the repo.\n[I]gnore [a]dd [d]elete?\n>";
chomp($response = <STDIN>);
if ($response =~ /^a$/i) {
`svn add $file`;
} elseif ($response =~ /^d$/i) {
unlink ($file) && print "\t[deleted]\n" ;
} else {
print "[left alone...]\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment