git-update: Use --force when checking out manifest
authorNirbheek Chauhan <nirbheek@centricular.com>
Mon, 15 Jun 2020 18:28:17 +0000 (23:58 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Mon, 15 Jun 2020 19:08:53 +0000 (00:38 +0530)
When we have a manifest, we DEFINITELY want exactly that, please throw
away any local changes, thanks. Fixes CI:

https://gitlab.freedesktop.org/alatiera/gst-ci/-/jobs/3105690

```
 Checking out f5b44d31284cfa1b6d029fdfe69d6cdb9a8aeb36 in gst-devtools
Could not rebase subprojects\gst-devtools, please fix and try again. Error:
error: Your local changes to the following files would be overwritten by checkout:
docs/plugins/fakesrc.simple.validatetest.yaml
Please commit your changes or stash them before you switch branches.
Aborting
 Command '['git', 'checkout', '--detach', 'f5b44d31284cfa1b6d029fdfe69d6cdb9a8aeb36']' returned non-zero exit status 1.
 ```

This is probably caused by some shared cache shenanigans, but forcing
is also what we want anyway in this case.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/162>

git-update

index 37d9a43..3cd604e 100755 (executable)
@@ -12,6 +12,8 @@ from scripts.common import get_meson
 
 
 SCRIPTDIR = os.path.normpath(os.path.dirname(__file__))
+# Force a checkout to happen and throw away local changes
+FORCE_CHECKOUT = False
 
 
 def manifest_get_commits(manifest):
@@ -90,7 +92,9 @@ def update_repo(repo_name, repo_dir, revision, no_interaction, fetch_args=[], re
         if revision:
             print("Checking out %s in %s" % (revision, repo_name))
             git("fetch", *fetch_args, repository_path=repo_dir)
-            git("checkout", "--detach", revision, repository_path=repo_dir)
+            checkout_args = ["--force"] if FORCE_CHECKOUT else []
+            checkout_args += ["--detach", revision]
+            git("checkout", *checkout_args, repository_path=repo_dir)
         else:
             print("Updating branch %s in %s" % (get_branch_name(repo_dir), repo_name))
             git("pull", "--rebase", repository_path=repo_dir)
@@ -187,6 +191,7 @@ if __name__ == "__main__":
         meson = get_meson()
         targets_s = subprocess.check_output(meson + ['subprojects', 'download'])
         repos_commits = manifest_get_commits(options.manifest)
+        FORCE_CHECKOUT = True
     else:
         repos_commits = {}