'fetch' and 'new' can take branch names as arguments (defaulting to 'origin')
[ghc-hetmet.git] / sync-all
index 743d3e6..2f47974 100755 (executable)
--- a/sync-all
+++ b/sync-all
@@ -215,6 +215,8 @@ sub scmall {
     my $scm;
     my $upstream;
     my $line;
+    my $branch_name;
+    my $subcommand;
 
     my $path;
     my $wd_before = getcwd;
@@ -227,6 +229,23 @@ sub scmall {
 
     parsePackages;
 
+    if ($command =~ /^remote$/) {
+        if (@_ < 2) {
+            help();
+        }
+        $subcommand = shift;
+        $branch_name = shift;
+        if ($subcommand ne 'add' && $subcommand ne 'rm') {
+            help();
+        }
+    } elsif ($command eq 'new' || $command eq 'fetch') {
+        if (@_ < 1) {
+            $branch_name = 'origin';
+        } else {
+            $branch_name = shift;
+        }
+    }
+
     for $line (@packages) {
 
             $localpath  = $$line{"localpath"};
@@ -275,7 +294,7 @@ sub scmall {
                 }
                 
                 # The first time round the loop, default the get-mode
-                if (not defined($get_mode)) {
+                if ($scm eq "darcs" && not defined($get_mode)) {
                     warning("adding --partial, to override use --complete");
                     $get_mode = "--partial";
                 }
@@ -299,11 +318,21 @@ sub scmall {
             elsif ($command =~ /^set-origin$/) {
                 @scm_args = ("remote", "set-url", "origin", $path);
             }
+            elsif ($command =~ /^set-push$/) {
+                @scm_args = ("remote", "set-url", "--push", "origin", $path);
+            }
             elsif ($command =~ /^fetch$/) {
-                @scm_args = ("fetch", "origin");
+                @scm_args = ("fetch", "$branch_name");
             }
             elsif ($command =~ /^new$/) {
-                @scm_args = ("log", "origin..");
+                @scm_args = ("log", "$branch_name..");
+            }
+            elsif ($command =~ /^remote$/) {
+                if ($subcommand eq 'add') {
+                    @scm_args = ("remote", "add", $branch_name, $path);
+                } elsif ($subcommand eq 'rm') {
+                    @scm_args = ("remote", "rm", $branch_name);
+                }
             }
             else {
                 die "Unknown command: $command";
@@ -337,6 +366,54 @@ sub scmall {
     }
 }
 
+
+sub help()
+{
+        # Get the built in help
+        my $help = <<END;
+What do you want to do?
+Supported commands:
+
+ * whatsnew
+ * push
+ * pull
+ * get, with options:
+  * --<package-tag>
+  * --complete
+  * --partial
+ * fetch
+ * send
+ * set-origin
+ * set-push
+ * new
+ * remote add <branch-name>
+ * remote rm <branch-name>
+
+Available package-tags are:
+END
+
+        # Collect all the tags in the packages file
+        my %available_tags;
+        open IN, "< packages" or die "Can't open packages file";
+        while (<IN>) {
+            chomp;
+            if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)/) {
+                if (defined($2) && $2 ne "-") {
+                    $available_tags{$2} = 1;
+                }
+            }
+            elsif (! /^(#.*)?$/) {
+                die "Bad line: $_";
+            }
+        }
+        close IN;
+        
+        # Show those tags and the help text
+        my @available_tags = keys %available_tags;
+        print "$help@available_tags\n";
+        exit 1;
+}
+
 sub main {
     if (! -d ".git" || ! -d "compiler") {
         die "error: sync-all must be run from the top level of the ghc tree."
@@ -385,46 +462,7 @@ sub main {
     }
 
     if ($#_ eq -1) {
-        # Get the built in help
-        my $help = <<END;
-What do you want to do?
-Supported commands:
-
- * whatsnew
- * push
- * pull
- * get, with options:
-  * --<package-tag>
-  * --complete
-  * --partial
- * fetch
- * send
- * set-origin
- * new
-
-Available package-tags are:
-END
-
-        # Collect all the tags in the packages file
-        my %available_tags;
-        open IN, "< packages" or die "Can't open packages file";
-        while (<IN>) {
-            chomp;
-            if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)/) {
-                if (defined($2) && $2 ne "-") {
-                    $available_tags{$2} = 1;
-                }
-            }
-            elsif (! /^(#.*)?$/) {
-                die "Bad line: $_";
-            }
-        }
-        close IN;
-        
-        # Show those tags and the help text
-        my @available_tags = keys %available_tags;
-        print "$help@available_tags\n";
-        exit 1;
+        help();
     }
     else {
         # Give the command and rest of the arguments to the main loop