Re: [BUG] 'git mv a/fileA b/fileB' causes 'c/fileC' to be deleted

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [BUG] 'git mv a/fileA b/fileB' causes 'c/fileC' to be deleted

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:42

"Michael Cassar" [off-list ref] writes:
Is this just me being an idiot, or could there be a bigger problem
here?

Please CC me in any replies.
There could be a bigger problem, but it does not seem to easily
reproduce as you noted in the message.  It could be that some
unrelated thing in the working tree is playing a role in this
breakage, but I do not think of offhand what that is.

Here is what I just ran.

-- >8 cut >8 --
#!/bin/sh

report () {
	echo
	echo "* $*"
	echo
}

rm -fr test0
mkdir test0
cd test0

report working tree preparation
mkdir -p partA papers/unsorted papers/all-papers
echo outline >partA/outline.txt
echo Thesis >papers/unsorted/Thesis.pdf

report repository initialization
git init-db

report initial import
git add papers partA
git commit -m 'initial'
git show --root --stat --summary

report run mv
git mv papers/unsorted/Thesis.pdf papers/all-papers/Thesis.pdf

report before commit
git diff --stat HEAD

report make a commit
git commit -m 'moved a file'

report final result
git show --stat --summary
-- 8< cut 8< --

and I did not see the breakage.  Care to show a bit more details
on your working tree?  I do not think this depends on any
contents of the individual files, but
Here is a transcript. These results are reproducable using the same
files, but I can't seem to reproduce with different files.

## Create initial respository

[mike@simba ~] git version
git version 1.4.2.1

[mike@simba ~] mkdir repos; cd repos

[mike@simba ~/repos] git init-db
defaulting to local storage area

[mike@simba ~/repos] cp -r ~/thesis_work/* .

[mike@simba ~/repos] ls -a
.  ..  .git  metathesis  notes  papers  partA

[mike@simba ~/repos] git add metathesis notes papers partA

output from "find metathesis notes papers partA -ls" and "git
ls-files -s" at this step may be a starter.

Re: [BUG] 'git mv a/fileA b/fileB' causes 'c/fileC' to be deleted

From: Michael Cassar <hidden>
Date: 2016-06-15 22:42:42

On 10/2/06, Junio C Hamano [off-list ref] wrote:
There could be a bigger problem, but it does not seem to easily
reproduce as you noted in the message.  It could be that some
unrelated thing in the working tree is playing a role in this
breakage, but I do not think of offhand what that is.
[...]  Care to show a bit more details
on your working tree?
Okay, I should stop being lazy and actually produce a minimal test-case.

Here we go:

--CUT--
#!/bin/bash

git init-db

mkdir papers
mkdir papers/unsorted
mkdir papers/all-papers
mkdir partA
echo 'moo' > papers/unsorted/Thesis.pdf
echo 'cow' > partA/outline.txt
echo 'this file has brackets in its filename' > 'papers/unsorted/(brackets).pdf'

git add  papers partA
git commit -m 'intial commit'

git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf
git commit -m 'move a file'

cg log -f
--CUT--

The problem seems to have come from the fact that a file in the source
directory of the move contained brackets in its filename.Removing the
file causes the problem to go away.

Hope this helps a little,

Mike

Re: [BUG] 'git mv a/fileA b/fileB' causes 'c/fileC' to be deleted

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:42

Thanks.  I see it reproduces.

It is a bug in git-mv that fails to update cache-tree data
structure properly.  This patch should fix it.

-- >8 --
git-mv: do not write out a bogus cache-tree in the index

The command updates the cache without invalidating the cache
tree entries.  Since this is not as performance critical as
one-tree and two-tree git-read-tree and git-apply, disable
use of cache-tree entirely.

Signed-off-by: Junio C Hamano <redacted>
---
diff --git a/builtin-mv.c b/builtin-mv.c
index 4d21d88..9a4e2e0 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -83,6 +83,9 @@ int cmd_mv(int argc, const char **argv, 
 	if (read_cache() < 0)
 		die("index file corrupt");
 
+	/* This does not manage cache-tree properly */
+	cache_tree_free(&active_cache_tree);
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help