Skip to contentSkip to conversation

bitbake-setup: use non-destructive 'update' mode of the git fetcher

PATCH Superseded Alexander Kanavin 1 participant 1 message Mar 20

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 bitbake-setup: use non-destructive 'update' mode of the git fetcher

From: Alexander Kanavin <[email protected]>

This allows removing the git hook that prohibited making commits in repositories under layers/, significantly improving user experience.

bitbake-setup logic is adjusted to account for these situations:

- if a git checkout is being replaced with a local symlink, that checkout is moved to a backup location, regardless of whether it has local changes or not
- if a git checkout has uncommited changes, the 'update' mode is going to fail. Bitbake-setup anticipates this, and stashes these changes, with a warning.

The tests are modified so that:

- the check for layer backups is run earlier, and check that backups happen when they're supposed to (which should be just once).

- the test that previously checked that local commits are rejected is adjusted to check that such a commit is accepted, and layer is updated from remote without creating a backup directory.

- a test is added to force a rebase conflict on update, and check that it indeed happens. We can think of better ways to handle rebase conflicts in bitbake-setup later on; right now it simply stops at that point.

---
v2: removed bogus empty 'aaaa' file which was from a local experiment
v3: removed auto-stashing of uncommitted changes

---
 bin/bitbake-setup     | 40 ++--------------------------------------
 lib/bb/tests/setup.py | 42 +++++++++++++++++++++++++++---------------
 2 files changed, 29 insertions(+), 53 deletions(-)
bin/bitbake-setup +2 -38
index ca4461b1e..dcad9c169 100755
@@ -191,39 +191,6 @@ def checkout_layers(layers, confdir, layerdir, d):
         logger.plain("Making a symbolic link {} pointing to {}".format(dst, src))
         os.symlink(src, dst)
 
-    def _has_local_modifications(r_name, r_path):
-        fixed_revisions = json.load(open(os.path.join(confdir, "sources-fixed-revisions.json")))
-
-        if not r_name in fixed_revisions['sources']:
-            logger.warning("""Source {} is added with path {}.
-This path already exists, but it has no entry in a fixed revisions
-record. To ensure possible local modifications are not lost, it will
-be preserved in a backup directory.""".format(r_name, r_path))
-            return True
-
-        rev = fixed_revisions['sources'][r_name]['git-remote']['rev']
-        status = bb.process.run('git -C {} status --porcelain'.format(r_path))[0]
-        if status:
-            return True
-        diff = bb.process.run('git -C {} diff {} {}'.format(r_path, get_diff_color_param(), rev))[0]
-        if diff:
-            return True
-        return False
-
-    def _restrict_commits(r_name, r_path):
-        hook_path = os.path.join(r_path, '.git', 'hooks', 'pre-commit')
-        restrict_hook = """#!/bin/sh
-echo "This repository is managed by bitbake-setup, and making commits is restricted.
-If you wish to make local modifications, clone it separately, and re-initialize using
-bitbake-setup init -L {} /path/to/repo/checkout"
-exit 1
-""".format(r_name)
-        with open(hook_path, 'w') as f:
-            f.write(restrict_hook)
-        import stat
-        st = os.stat(hook_path)
-        os.chmod(hook_path, st.st_mode | stat.S_IEXEC)
-
     layers_fixed_revisions = copy.deepcopy(layers)
     repodirs = []
     oesetupbuild = None
@@ -242,19 +209,16 @@ exit 1
         if os.path.lexists(repodir_path):
             if os.path.islink(repodir_path):
                 os.remove(repodir_path)
-            elif _has_local_modifications(r_name, repodir_path):
+            elif r_local:
                 backup_path = add_unique_timestamp_to_path(repodir_path + '-backup')
                 logger.warning("""Source {} in {} contains local modifications. Renaming to {} to preserve them.
 For local development work it is recommended to clone the needed layers separately and re-initialize using -L option:
 bitbake-setup init -L {} /path/to/repo/checkout""".format(
                     r_name, repodir_path, backup_path, r_name))
                 os.rename(repodir_path, backup_path)
-            else:
-                shutil.rmtree(repodir_path)
 
         if r_remote:
             _checkout_git_remote(r_remote, repodir, layers_fixed_revisions)
-            _restrict_commits(r_name, repodir_path)
         if r_local:
             _symlink_local(os.path.expanduser(r_local["path"]), repodir_path)
 
@@ -830,7 +794,7 @@ def do_fetch(fetcher, dir):
         oldstdout = sys.stdout
         sys.stdout = f
         fetcher.download()
-        fetcher.unpack(dir)
+        fetcher.unpack_update(dir)
         sys.stdout = oldstdout
 
 def update_registry(registry, cachedir, d):
lib/bb/tests/setup.py +27 -15

82 lines not on this page · raw message

Signature · 1 line
2.47.3