rebase command
[matrix.git] / matrix / matrix.py
index 0f39691..345f00b 100644 (file)
@@ -47,6 +47,8 @@ def main():
                clone_components(targets)
        elif command == 'clean':
                clean_components(targets)
+       elif command == 'rebase':
+               rebase_components(targets)
        elif command == 'pull':
                pull_components(targets)
        elif command == 'source-dist':
@@ -82,7 +84,8 @@ Commands and parameters:
                -mj N           Run component builds with make -j N.
        clean           Remove all non-tracked files from the component git
                        repository directories.
-       pull            Run git pull for the components.
+       rebase          Update repositories from server by rebasing.
+       pull            Update repositories from server by merging.
        source-dist     Download and package the component sources.
        rootfs          Build a rootfs from the current target installation.
                -n              Do not clean env.faked and stripped directory.
@@ -578,14 +581,26 @@ def clean_components(targets):
                        if files:
                                print len(files), 'dirty files left in', repo.path
 
-def pull_components(targets):
+def for_each_repository(func, targets=None):
        if not targets:
                targets = config.components.keys()
 
        for name in targets:
                c = config.components[name]
-               pull_repository(c.repo)
-               pull_repository(c.meta)
+               if git.contains_database(c.repo.path):
+                       func(c.repo)
+               func(c.meta)
+
+def rebase_components(targets):
+       for_each_repository(rebase_repository, targets)
+
+def pull_components(targets):
+       for_each_repository(pull_repository, targets)
+
+def rebase_repository(repo):
+       print 'Rebasing', repo.path
+       git.remote_update(repo.path)
+       git.rebase(repo.path)
 
 def pull_repository(repo):
        print 'Pulling', repo.path