Skip to content

Instantly share code, notes, and snippets.

@RayMPerry
Last active September 26, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RayMPerry/bb94cad1277e5e6de1f9b8b193766e79 to your computer and use it in GitHub Desktop.
Save RayMPerry/bb94cad1277e5e6de1f9b8b193766e79 to your computer and use it in GitHub Desktop.
Spinoff script
#!/usr/bin/env perl6
sub MAIN(
Str :$folder!, #= The subdirectory you wish to spinoff.
Str :$branch!, #= The branch you'd like to spinoff.
Str :repo(:$repository)! #= The URL of the remote repository
) {
loop {
my $answer = prompt "Would you like to spinoff $folder from $branch into $repository? [y/N] ";
redo unless $answer ~~ /:i y|n/;
if ($answer ~~ /:i n/) { return; }
last;
}
my Str constant $ORIGINAL_REPO_NAME = "git@github.com:RayMPerry/prototypes.git";
say "Spinning off subdirectory.";
my @commandsToRun = <<filter-branch -f --prune-empty --subdirectory-filter $folder $branch>>,
<<remote set-url origin $repository>>,
<push -u origin master>,
<<remote set-url origin $ORIGINAL_REPO_NAME>>,
<fetch --all>,
<reset --hard origin/master>;
for @commandsToRun -> @command {
last if so run("git", |@command);
}
}
# Local Variables:
# compile-command: "perl6 spinoffSubdirectory.p6"
# End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment