action_sync: fix git_sync_timestamps KeyError
authorZac Medico <zmedico@gentoo.org>
Tue, 6 Dec 2011 18:52:50 +0000 (10:52 -0800)
committerZac Medico <zmedico@gentoo.org>
Tue, 6 Dec 2011 18:52:50 +0000 (10:52 -0800)
This fixes the case where $PORTDIR doesn't exist prior to sync.

pym/_emerge/actions.py

index a62b305107c42c6bca836236802377e36960b905..87610a693d8147621baf2c258e9058f6d9dad8fb 100644 (file)
@@ -1971,6 +1971,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
        os.umask(0o022)
        dosyncuri = syncuri
        updatecache_flg = False
+       git = False
        if myaction == "metadata":
                print("skipping sync")
                updatecache_flg = True
@@ -1999,9 +2000,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                msg = ">>> Git pull in %s successful" % myportdir
                emergelog(xterm_titles, msg)
                writemsg_level(msg + "\n")
-               exitcode = git_sync_timestamps(portdb, myportdir)
-               if exitcode == os.EX_OK:
-                       updatecache_flg = True
+               git = True
        elif syncuri[:8]=="rsync://" or syncuri[:6]=="ssh://":
                for vcs_dir in vcs_dirs:
                        writemsg_level(("!!! %s appears to be under revision " + \
@@ -2443,17 +2442,25 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                        noiselevel=-1, level=logging.ERROR)
                return 1
 
-       if updatecache_flg and  \
-               myaction != "metadata" and \
-               "metadata-transfer" not in settings.features:
-               updatecache_flg = False
-
        # Reload the whole config from scratch.
        settings, trees, mtimedb = load_emerge_config(trees=trees)
        adjust_configs(myopts, trees)
        root_config = trees[settings['EROOT']]['root_config']
        portdb = trees[settings['EROOT']]['porttree'].dbapi
 
+       if git:
+               # NOTE: Do this after reloading the config, in case
+               # it did not exist prior to sync, so that the config
+               # and portdb properly account for its existence.
+               exitcode = git_sync_timestamps(portdb, myportdir)
+               if exitcode == os.EX_OK:
+                       updatecache_flg = True
+
+       if updatecache_flg and  \
+               myaction != "metadata" and \
+               "metadata-transfer" not in settings.features:
+               updatecache_flg = False
+
        if updatecache_flg and \
                os.path.exists(os.path.join(myportdir, 'metadata', 'cache')):