|
| 1 | +#!/usr/bin/perl |
| 2 | + |
| 3 | +use strict; |
| 4 | + |
| 5 | +my $sourcedir = shift @ARGV; |
| 6 | + |
| 7 | +unless ($sourcedir) { |
| 8 | + print <<XXX; |
| 9 | += CSSWG Cross-Level Commit Script = |
| 10 | +
|
| 11 | +This script takes diffs from the specified directory, |
| 12 | +applies them to all of that module’s specs with a higher level number, |
| 13 | +and issues a `git commit` command if requested. |
| 14 | +
|
| 15 | +cross-commit.pl SPECDIR |
| 16 | +
|
| 17 | +For example, |
| 18 | + xcommit.pl css-grid-1 |
| 19 | +or |
| 20 | + xcommit.pl . # e.g. css-grid-1 as current dir |
| 21 | +
|
| 22 | +Your system’s `git` and `patch` commands are used. |
| 23 | +Failed patches will be handled as usual for `patch`, |
| 24 | +and will cause the commit to abort so you can fix it up |
| 25 | +and commit manually. |
| 26 | +
|
| 27 | +Note: Assumes shortname-N naming scheme for SPECDIR and friends |
| 28 | +at only one level of depth below git repo root. |
| 29 | +XXX |
| 30 | + exit; |
| 31 | +} |
| 32 | + |
| 33 | +# Too lazy to look up the right way to do this |
| 34 | +chdir $sourcedir || die "Invalid source directory: $!"; |
| 35 | +$sourcedir = `pwd`; |
| 36 | +chomp $sourcedir; |
| 37 | + |
| 38 | +# extract info |
| 39 | +$sourcedir =~ m#(.*)/([^/]+)-([\d+])$#; |
| 40 | +my $rootdir = $1; |
| 41 | +my $specname = $2; |
| 42 | +my $speclevel = $3; |
| 43 | +my @failed = (); |
| 44 | + |
| 45 | +# confirm before continuing |
| 46 | +print "Sourcing diffs from $specname level $speclevel under root $rootdir:\n"; |
| 47 | +chdir $rootdir; |
| 48 | +$_ = `ls -d $specname-*`; |
| 49 | +my @dirlist = split; |
| 50 | +print "Matching specs: @dirlist\n"; |
| 51 | + |
| 52 | +print "Press enter to continue, q to quit:"; |
| 53 | +$_ = <STDIN>; |
| 54 | +chomp; |
| 55 | +exit if ($_); |
| 56 | + |
| 57 | +# main patching loop |
| 58 | +foreach (@dirlist) { |
| 59 | + /(\d+)$/; |
| 60 | + my $level = $1; |
| 61 | + if ($level > $speclevel) { |
| 62 | + print "\nPatching $_ ...\n"; |
| 63 | + chdir $_; |
| 64 | + print `git diff $sourcedir | patch -p2`; |
| 65 | + push @failed, $specname . '-' . $speclevel if $?; |
| 66 | + chdir $rootdir; |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +# wrap it up |
| 71 | +if (@failed == 0) { |
| 72 | + my $dirs = join ' ', @dirlist; |
| 73 | + print "\n\nWould you like me to issue `git commit $dirs`?\n"; |
| 74 | + print "Enter arguments (e.g. -m 'message' --amend) or leave blank to skip commit.\n"; |
| 75 | + print "git commit : "; |
| 76 | + my $args = <STDIN>; |
| 77 | + chomp $args; |
| 78 | + if ($args) { |
| 79 | + print "Executing git commit $args $dirs ...\n\n"; |
| 80 | + exec "git commit $args $dirs"; |
| 81 | + } |
| 82 | +} |
| 83 | +else { |
| 84 | + die "Patching failed for @failed, please fix and commit manually.\n"; |
| 85 | +} |
0 commit comments