All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] devtool: sdk-update: reset git metadata on update
@ 2016-04-14 18:03 Stephano Cetola
  0 siblings, 0 replies; 3+ messages in thread
From: Stephano Cetola @ 2016-04-14 18:03 UTC (permalink / raw)
  To: openembedded-core

Replace git pull with fetch and reset. Also add gitignore and committer
info during publish to avoid errors on update.

[ YOCTO #9368 ]

Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
---
 scripts/lib/devtool/sdk.py | 11 +++++++++--
 scripts/oe-publish-sdk     |  4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/scripts/lib/devtool/sdk.py b/scripts/lib/devtool/sdk.py
index b1905f9..d666341 100644
--- a/scripts/lib/devtool/sdk.py
+++ b/scripts/lib/devtool/sdk.py
@@ -17,6 +17,7 @@
 
 import os
 import subprocess
+from subprocess import check_output
 import logging
 import glob
 import shutil
@@ -186,9 +187,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 = 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:
diff --git a/scripts/oe-publish-sdk b/scripts/oe-publish-sdk
index e6cb7af..33bca8d 100755
--- a/scripts/oe-publish-sdk
+++ b/scripts/oe-publish-sdk
@@ -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; fi; git add -A .; git config user.email "oe@oe.oe" && 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; fi; git add -A .; git config user.email 'oe@oe.oe' && 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')
-- 
2.8.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] devtool: sdk-update: reset git metadata on update
  2016-04-14 18:15 Stephano Cetola
@ 2016-04-15  2:28 ` Paul Eggleton
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Eggleton @ 2016-04-15  2:28 UTC (permalink / raw)
  To: Stephano Cetola; +Cc: openembedded-core

Hi Stephano,

A few review comments below.

On Thu, 14 Apr 2016 11:15:41 Stephano Cetola wrote:
> Forgot to add in the .gitignore. It's in there now.

For future patches if you could mark them as "[PATCH v2]", "[PATCH v3]" etc 
that would be great. Additionally the commit message should be standalone - 
imagine you were reading it via "git log" in a year's time, things like the 
above don't really belong. If you do need to comment on the changes between 
versions then use a cover letter or alternatively edit the patch before 
sending and put the comments after the --- line.
 
> Replace git pull with fetch and reset. 

You ought to say why we're doing this here (i.e. 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 on update.
>
> [ YOCTO #9368 ]
> 
> Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
> ---
>  scripts/lib/devtool/sdk.py | 11 +++++++++--
>  scripts/oe-publish-sdk     |  4 ++--
>  2 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/lib/devtool/sdk.py b/scripts/lib/devtool/sdk.py
> index b1905f9..d666341 100644
> --- a/scripts/lib/devtool/sdk.py
> +++ b/scripts/lib/devtool/sdk.py
> @@ -17,6 +17,7 @@
> 
>  import os
>  import subprocess
> +from subprocess import check_output

We're already importing the entire subprocess module on the line above so you 
don't need this, just change the code to call subprocess.check_output() 
instead of just check_output().

>  import logging
>  import glob
>  import shutil
> @@ -186,9 +187,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 =
> 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

Please use four spaces for indentation in python code like this.

Thanks,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] devtool: sdk-update: reset git metadata on update
@ 2016-04-14 18:15 Stephano Cetola
  2016-04-15  2:28 ` Paul Eggleton
  0 siblings, 1 reply; 3+ messages in thread
From: Stephano Cetola @ 2016-04-14 18:15 UTC (permalink / raw)
  To: openembedded-core

Forgot to add in the .gitignore. It's in there now.

Replace git pull with fetch and reset. Also add gitignore and committer
info during publish to avoid errors on update.

[ YOCTO #9368 ]

Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
---
 scripts/lib/devtool/sdk.py | 11 +++++++++--
 scripts/oe-publish-sdk     |  4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/scripts/lib/devtool/sdk.py b/scripts/lib/devtool/sdk.py
index b1905f9..d666341 100644
--- a/scripts/lib/devtool/sdk.py
+++ b/scripts/lib/devtool/sdk.py
@@ -17,6 +17,7 @@
 
 import os
 import subprocess
+from subprocess import check_output
 import logging
 import glob
 import shutil
@@ -186,9 +187,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 = 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:
diff --git a/scripts/oe-publish-sdk b/scripts/oe-publish-sdk
index e6cb7af..55872f2 100755
--- a/scripts/oe-publish-sdk
+++ b/scripts/oe-publish-sdk
@@ -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 "oe@oe.oe" && 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 'oe@oe.oe' && 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')
-- 
2.8.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-15  2:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-14 18:03 [PATCH] devtool: sdk-update: reset git metadata on update Stephano Cetola
2016-04-14 18:15 Stephano Cetola
2016-04-15  2:28 ` Paul Eggleton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.