 
 (defun straight--merge-with-upstream (upstream)
   "Merge the current branch with an UPSTREAM ref.
-If the command fails, raise an error."
-  (straight--ensure-call "git" "merge" upstream))
+If the command fails, raise an error. After this function
+returns, the working directory will perfectly reflect the state
+of UPSTREAM."
+  (straight--ensure-call "git" "merge" upstream)
+  (straight--ensure-call "git" "submodule" "update")
+  (straight--ensure-call "git" "clean" "-f"))
 
 (defun straight--update-package (recipe)
   "Attempt to update the package specified by the RECIPE.

       (concat "Repository %S is not version-controlled with Git, "
               "cannot set HEAD")
       local-repo))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Figuring out whether packages need to be rebuilt

                            ;; creating forks).
                            (format "https://github.com/%s.git" repo)
                            (format "git@github.com:%s.git" repo))))))
                  (if (straight--validate-head-is-reachable
                       local-repo head remote-urls)
                      (if (straight--working-directory-dirty-p
                           local-repo)
                          (straight--warn
                           (concat "Repository %S has a dirty "
                                   "working directory")
                           local-repo)
                        (unless nomsg
                          (message "Package %S is all good" package))
                        t) ; the only path where the package is valid
                    (straight--warn
                     "HEAD of repository %S%s is not reachable from remote"
                     local-repo
                     (if-let ((branch (straight--get-branch)))
                         (format " (on branch %S)" branch)
                       "")))
                (straight--warn "Repository %S uses non-Git fetcher `%S'"
                                local-repo fetcher))
            (straight--warn "Repository %S has a detached HEAD" local-repo))
