from mono_master import MonoMasterPackage
from bockbuild.util.util import *

class MonoMasterEncryptedPackage (MonoMasterPackage):
    
    def __init__(self):
        MonoMasterPackage.__init__ (self)

        self.configure_flags.extend(['--enable-extension-module=crypto --enable-native-types'])

    def prep(self):
        MonoMasterPackage.prep(self)
        retry (self.checkout_mono_extensions)

    def checkout_mono_extensions(self):
        ext = 'git@github.com:xamarin/mono-extensions.git'
        dirname = os.path.join(self.profile.build_root, "mono-extensions")

        if not os.path.exists(dirname):
            self.sh('%' + '{git} clone --local --shared "%s" "%s"' % (ext, dirname))

        self.pushd(dirname)

        try:
            self.sh('%{git} clean -xffd')
            self.sh('%{git} fetch --all --prune')
            if "pr/" not in self.git_branch:
                self.sh('%' + '{git} checkout origin/%s' % self.git_branch)
            else:
                self.sh('%{git} checkout origin/master')
            self.sh ('%{git} reset --hard')
        except Exception as e:
            self.popd ()
            self.rm_if_exists (dirname)
            raise
        finally:
            info ('Mono crypto extensions (rev. %s)' % git_get_revision (self))

        self.popd ()

MonoMasterEncryptedPackage()
from mono_master import MonoMasterPackage
from bockbuild.util.util import *

class MonoMasterEncryptedPackage (MonoMasterPackage):
    
    def __init__(self):
        MonoMasterPackage.__init__ (self)

        self.configure_flags.extend(['--enable-extension-module=crypto --enable-native-types'])

    def prep(self):
        MonoMasterPackage.prep(self)
        retry (self.checkout_mono_extensions)

    def checkout_mono_extensions(self):
        ext = 'git@github.com:xamarin/mono-extensions.git'
        dirname = os.path.join(self.profile.build_root, "mono-extensions")

        if not os.path.exists(dirname):
            self.sh('%' + '{git} clone --local --shared "%s" "%s"' % (ext, dirname))

        self.pushd(dirname)

        try:
            self.sh('%{git} clean -xffd')
            self.sh('%{git} fetch --all --prune')
            if 'pull/' in self.git_branch: # pull request
                self.sh('%{git} checkout origin/master')
            else:
                self.sh('%' + '{git} checkout origin/%s' % self.git_branch)

            self.sh ('%{git} reset --hard')
        except Exception as e:
            self.popd ()
            self.rm_if_exists (dirname)
            raise
        finally:
            info ('Mono crypto extensions (rev. %s)' % git_get_revision (self))

        self.popd ()

MonoMasterEncryptedPackage()
Fix mono-extensions checkout for PR branches ('origin/pull/N/merge')
Fix mono-extensions checkout for PR branches ('origin/pull/N/merge')
