diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 7e916c2c9a4c1d64eaf26921696170c719ee269e..0d64998e13aae120509c82429424f97093f2401d 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -252,6 +252,12 @@ def check_top_directory():
         if not os.path.exists(f):
             sys.exit('Please run at the top of source directory.')
 
+def check_clean_directory():
+    """Exit if the source tree is not clean."""
+    for f in ('.config', 'include/config'):
+        if os.path.exists(f):
+            sys.exit("source tree is not clean, please run 'make mrproper'")
+
 def get_make_cmd():
     """Get the command name of GNU Make.
 
@@ -932,6 +938,8 @@ def main():
 
     check_top_directory()
 
+    check_clean_directory()
+
     update_cross_compile(options.color)
 
     if not options.cleanup_headers_only: