Skip to contentSkip to conversation

devtool: sdk-update: reset git metadata on update

PATCH New Stephano Cetola 1 participant 1 message Apr 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 devtool: sdk-update: reset git metadata on update

Replace git pull with fetch and reset to avoid the merge logic in the event that the layers repo in the published SDK we're updating to isn't fast-forward merge from the local repo.

Also add gitignore and committer info during publish to avoid errors and to be sure that the first commit has a dummy user in it.

[ YOCTO #9368 ]

---
 scripts/lib/devtool/sdk.py | 10 ++++++++--
 scripts/oe-publish-sdk     |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)
scripts/lib/devtool/sdk.py +8 -2
index b1905f9..a22841d 100644
@@ -186,9 +186,15 @@ def sdk_update(args, config, basepath, workspace):
                 return 0
             # Update metadata
             logger.debug("Updating metadata via git ...")
-            # Try using 'git pull', if failed, use 'git clone'
+            #Check for the status before doing a fetch and reset
             if os.path.exists(os.path.join(basepath, 'layers/.git')):
-                ret = subprocess.call("git pull %s/layers/.git" % updateserver, shell=True, cwd=layers_dir)
+                out = subprocess.check_output("git status --porcelain", shell=True, cwd=layers_dir)
+                if not out:
+                    ret = subprocess.call("git fetch --all; git reset --hard", shell=True, cwd=layers_dir)
+                else:
+                    logger.error("Failed to update metadata as there have been changes made to it. Aborting.");
+                    logger.error("Changed files:\n%s" % out);
+                    return -1
             else:
                 ret = -1
             if ret != 0:
scripts/oe-publish-sdk +2 -2
index e6cb7af..55872f2 100755
@@ -114,9 +114,9 @@ def publish(args):
 
     # Setting up the git repo
     if not is_remote:
-        cmd = 'set -e; mkdir -p %s/layers; cd %s/layers; if [ ! -e .git ]; then git init .; mv .git/hooks/post-update.sample .git/hooks/post-update; fi; git add -A .; git commit -q -m "init repo" || true; git update-server-info' % (destination, destination)
+        cmd = 'set -e; mkdir -p %s/layers; cd %s/layers; if [ ! -e .git ]; then git init .; mv .git/hooks/post-update.sample .git/hooks/post-update; echo "*.pyc\n*.pyo" > .gitignore; fi; git add -A .; git config user.email "[email protected]" && git config user.name "OE" && git commit -q -m "init repo" || true; git update-server-info' % (destination, destination)
     else:
-        cmd = "ssh %s 'set -e; mkdir -p %s/layers; cd %s/layers; if [ ! -e .git ]; then git init .; mv .git/hooks/post-update.sample .git/hooks/post-update; fi; git add -A .; git commit -q -m \"init repo\" || true; git update-server-info'" % (host, destdir, destdir)
+        cmd = "ssh %s 'set -e; mkdir -p %s/layers; cd %s/layers; if [ ! -e .git ]; then git init .; mv .git/hooks/post-update.sample .git/hooks/post-update; echo '*.pyc\n*.pyo' > .gitignore; fi; git add -A .; git config user.email '[email protected]' && git config user.name 'OE' && git commit -q -m \"init repo\" || true; git update-server-info'" % (host, destdir, destdir)
     ret = subprocess.call(cmd, shell=True)
     if ret == 0:
         logger.info('SDK published successfully')
Signature · 1 line
2.8.0