Do not reset the source directory if there is modification.

We simply do a `git merge --ff-only` instead of a `git reset`. This way:

- No change on the local repository
    => update to `remote/master`
- If you switch branch and local branch is behind `remote/master`
    => fast forward to `remote/master`
- If you switch branch and branches diverge
    => No update of the directory
- On branch master (or a branch behind `origin/master`) with compatible
  change in the working tree.
    =>  update of the directory
- On branch master (or a branch behind `origin/master`) but incompatible
  change in the working tree.
    =>  No update.

This way, sources are keep up-to-date as far as possible.
This commit is contained in:
Matthieu Gautier 2020-02-25 15:46:09 +01:00
parent 3f50b1b069
commit f504cf54e1
3 changed files with 46 additions and 17 deletions

View File

@ -48,6 +48,10 @@ def parse_args():
help=("Specify the architecture to build for ios application/libraries.\n"
"Can be specified several times to build for several architectures.\n"
"If not specified, all architectures will be build."))
subgroup.add_argument('--fast-clone', action='store_true',
help=("Do not clone the whole repository.\n"
"This is useful for one shot build but it is not recommended if you want "
"to develop with the cloned sources."))
options = parser.parse_args()
if not options.android_arch:

View File

@ -3,7 +3,7 @@ import os
import shutil
import time
from kiwixbuild.utils import pj, Context, SkipCommand, extract_archive, Defaultdict, StopBuild, run_command
from kiwixbuild.utils import pj, Context, SkipCommand, WarningMessage, extract_archive, Defaultdict, StopBuild, run_command
from kiwixbuild.versions import main_project_versions, base_deps_versions
from kiwixbuild._global import neutralEnv, option
@ -78,6 +78,8 @@ class Source:
duration = time.time() - start_time
print("OK ({:.1f}s)".format(duration))
return ret
except WarningMessage as e:
print(e)
except SkipCommand:
print("SKIP")
except subprocess.CalledProcessError:
@ -152,22 +154,31 @@ class GitClone(Source):
else:
return self.base_git_ref
def _git_clone(self, context):
if os.path.exists(self.git_path):
raise SkipCommand()
command = "git clone --depth=1 --branch {} {} {}".format(
self.git_ref, self.git_remote, self.source_dir)
run_command(command, neutralEnv('source_dir'), context)
def _git_init(self, context):
if option('fast_clone'):
command = "git clone --depth=1 --branch {} {} {}".format(
self.git_ref, self.git_remote, self.source_dir)
run_command(command, neutralEnv('source_dir'), context)
else:
command = "git clone {} {}".format(self.git_remote, self.source_dir)
run_command(command, neutralEnv('source_dir'), context)
command = "git checkout {}".format(self.git_ref)
run_command(command, self.git_path, context)
def _git_update(self, context):
command = "git fetch origin {}".format(
self.git_ref)
command = "git fetch origin {}".format(self.git_ref)
run_command(command, self.git_path, context)
run_command("git checkout "+self.git_ref, self.git_path, context)
try:
command = "git merge --ff-only origin/{}".format(self.git_ref)
run_command(command, self.git_path, context)
except subprocess.CalledProcessError:
raise WarningMessage("Cannot update, please check log for information")
def prepare(self):
self.command('gitclone', self._git_clone)
self.command('gitupdate', self._git_update)
if not os.path.exists(self.git_path):
self.command('gitinit', self._git_init)
else:
self.command('gitupdate', self._git_update)
if hasattr(self, '_post_prepare_script'):
self.command('post_prepare_script', self._post_prepare_script)
@ -238,6 +249,8 @@ class Builder:
return ret
except SkipCommand:
print("SKIP")
except WarningMessage as e:
print(e)
except subprocess.CalledProcessError:
print("ERROR")
try:

View File

@ -134,11 +134,7 @@ def download_remote(what, where):
raise StopBuild("Sha 256 doesn't correspond")
class SkipCommand(Exception):
pass
class StopBuild(Exception):
class BaseCommandResult(Exception):
def __init__(self, msg=""):
self.msg = msg
@ -146,6 +142,22 @@ class StopBuild(Exception):
return self.msg
class SkipCommand(BaseCommandResult):
def __str__(self):
if self.msg:
return "SKIP : {}".format(self.msg)
return "SKIP"
class WarningMessage(BaseCommandResult):
def __str__(self):
return "WARNING : {}".format(self.msg)
class StopBuild(BaseCommandResult):
pass
class Remotefile(namedtuple('Remotefile', ('name', 'sha256', 'url'))):
def __new__(cls, name, sha256, url=None):
if url is None: