chiark / gitweb /
Merge branch 'stable'
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 27 May 2008 22:18:22 +0000 (23:18 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 27 May 2008 22:18:22 +0000 (23:18 +0100)
Conflicts:

t/t2700-refresh.sh

stgit/git.py
t/t2700-refresh.sh

index 4dc4dcfef738ed3dcaef3b7c1072899af9b1c1d0..570003cae1feb2b941a74db3217815da588cd341 100644 (file)
@@ -167,7 +167,7 @@ def exclude_files():
         files.append(user_exclude)
     return files
 
-def ls_files(files, tree = None, full_name = True):
+def ls_files(files, tree = 'HEAD', full_name = True):
     """Return the files known to GIT or raise an error otherwise. It also
     converts the file to the full path relative the the .git directory.
     """
@@ -206,6 +206,8 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
 
     refresh_index()
 
+    if files is None:
+        files = []
     cache_files = []
 
     # unknown files
@@ -228,26 +230,39 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
     cache_files += [('C', filename) for filename in conflicts
                     if not files or filename in files]
     reported_files = set(conflicts)
-
-    # files in the index
-    args = diff_flags + [tree_id]
-    if files:
-        args += ['--'] + files
-    for line in GRun('diff-index', *args).output_lines():
-        fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
-        if fs[1] not in reported_files:
-            cache_files.append(fs)
-            reported_files.add(fs[1])
-
-    # files in the index but changed on (or removed from) disk
-    args = list(diff_flags)
-    if files:
-        args += ['--'] + files
-    for line in GRun('diff-files', *args).output_lines():
-        fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
-        if fs[1] not in reported_files:
-            cache_files.append(fs)
-            reported_files.add(fs[1])
+    files_left = [f for f in files if f not in reported_files]
+
+    # files in the index. Only execute this code if no files were
+    # specified when calling the function (i.e. report all files) or
+    # files were specified but already found in the previous step
+    if not files or files_left:
+        args = diff_flags + [tree_id]
+        if files_left:
+            args += ['--'] + files_left
+        for line in GRun('diff-index', *args).output_lines():
+            fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
+            # the condition is needed in case files is emtpy and
+            # diff-index lists those already reported
+            if fs[1] not in reported_files:
+                cache_files.append(fs)
+                reported_files.add(fs[1])
+        files_left = [f for f in files if f not in reported_files]
+
+    # files in the index but changed on (or removed from) disk. Only
+    # execute this code if no files were specified when calling the
+    # function (i.e. report all files) or files were specified but
+    # already found in the previous step
+    if not files or files_left:
+        args = list(diff_flags)
+        if files_left:
+            args += ['--'] + files_left
+        for line in GRun('diff-files', *args).output_lines():
+            fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
+            # the condition is needed in case files is empty and
+            # diff-files lists those already reported
+            if fs[1] not in reported_files:
+                cache_files.append(fs)
+                reported_files.add(fs[1])
 
     if verbose:
         out.done()
@@ -853,7 +868,6 @@ def refspec_remotepart(refspec):
         return m.group(1)
     else:
         raise GitException, 'Cannot parse refspec "%s"' % line
-    
 
 def __remotes_from_config():
     return config.sections_matching(r'remote\.(.*)\.url')
index 3759d0e98e9a2c1a9c0bf56b908cfb66cc9d5089..aad6d4500577b1dc11c4dc38b9921b3dceffa38d 100755 (executable)
@@ -117,4 +117,10 @@ test_expect_success 'Refresh --index' '
     stg new p5 -m "cleanup again" &&
     stg refresh
 '
+
+test_expect_success 'Refresh moved files' '
+    git mv foo1.txt foo1-new.txt &&
+    stg refresh
+'
+
 test_done