git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/7] remote-bzr: fix directory renaming

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 8, 2013, 17:27 UTC
Message-ID
<1365442036-25732-2-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1365442036-25732-1-git-send-email-felipe.contreras@gmail.com>
From: Christophe Simonis <christophe@kn.gl>

Git does not handle directories, renaming a directory is renaming every files in this directory.

[fc: added tests]
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr |  8 +++++++-
 contrib/remote-helpers/test-bzr.sh    | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index c5822e4..a7d041b 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -191,7 +191,13 @@ def get_filechanges(cur, prev):
         modified[path] = fid
     for oldpath, newpath, fid, kind, mod, _ in changes.renamed:
         removed[oldpath] = None
-        modified[newpath] = fid
+        if kind == 'directory':
+            lst = cur.list_files(from_dir=newpath, recursive=True)
+            for path, file_class, kind, fid, entry in lst:
+                if kind != 'directory':
+                    modified[newpath + '/' + path] = fid
+        else:
+            modified[newpath] = fid
 
     return modified, removed
 
diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh
index 8450432..d26e5c7 100755
--- a/contrib/remote-helpers/test-bzr.sh
+++ b/contrib/remote-helpers/test-bzr.sh
@@ -126,4 +126,28 @@ test_expect_success 'special modes' '
   test_cmp expected actual
 '
 
+cat > expected <<EOF
+100644 blob 54f9d6da5c91d556e6b54340b1327573073030af	content
+100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb	executable
+120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea	link
+040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b	movedir-new
+EOF
+
+test_expect_success 'moving directory' '
+  (cd bzrrepo &&
+  mkdir movedir &&
+  echo one > movedir/one &&
+  echo two > movedir/two &&
+  bzr add movedir &&
+  bzr commit -m movedir &&
+  bzr mv movedir movedir-new &&
+  bzr commit -m movedir-new) &&
+
+  (cd gitrepo &&
+  git pull &&
+  git ls-tree HEAD > ../actual) &&
+
+  test_cmp expected actual
+'
+
 test_done
-- 
1.8.2
Previous: Felipe ContrerasNext: Felipe Contreras
Message 2 of 12 in “remote-bzr: generic updates”
  1. 0/7 remote-bzr: generic updatesFelipe Contreras, Apr 8, 2013
  2. 1/7 remote-bzr: fix directory renamingFelipe Contreras, Apr 8, 2013
  3. 2/7 remote-bzr: remove files before modificationsFelipe Contreras, Apr 8, 2013
  4. 3/7 remote-bzr: set author if availableFelipe Contreras, Apr 8, 2013
  5. 4/7 remote-bzr: only update workingtree on local reposFelipe Contreras, Apr 8, 2013
  6. 5/7 remote-bzr: improve tag handlingFelipe Contreras, Apr 8, 2013
  7. 6/7 remote-bzr: add utf-8 support for fetchingFelipe Contreras, Apr 8, 2013
  8. Torsten BögershausenApr 8, 2013
  9. 7/7 remote-bzr: add utf-8 support for pushingFelipe Contreras, Apr 8, 2013
  10. Junio C HamanoApr 8, 2013
  11. Felipe ContrerasApr 8, 2013
  12. Junio C HamanoApr 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.