rebase command
authorTimo Savola <tsavola@movial.fi>
Fri, 4 Apr 2008 15:11:51 +0000 (18:11 +0300)
committerTimo Savola <tsavola@movial.fi>
Fri, 4 Apr 2008 15:11:51 +0000 (18:11 +0300)
matrix/git.py
matrix/matrix.py

index 3ed8347..ec02a13 100644 (file)
@@ -124,6 +124,14 @@ def clone(name, url, checkout=True):
 
        call(['clone'] + options + [url, name], fail=True)
 
+def remote_update(name):
+       call(['remote', 'update'], workdir=name)
+
+def rebase(name, refspec='origin'):
+       cmd = ['rebase', refspec]
+       if call(cmd, workdir=name) != 0:
+               raise Error(cmd, name)
+
 def pull(name, url=None, refspec=None):
        if url is None and refspec is None:
                cmd = ['pull']
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