-
-
Save RayMPerry/bb94cad1277e5e6de1f9b8b193766e79 to your computer and use it in GitHub Desktop.
Spinoff script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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