{"thread":{"id":"34837","subject":"[PATCH v4 00/11] Check replacement object type and minor updates","startedAt":"2013-09-03T07:10:14Z","lastAt":"2013-09-05T19:13:49Z","messageCount":20,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":11},"messages":[{"id":"226583","messageId":"20130903070551.29838.43576.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":null,"subject":"[PATCH v4 00/11] Check replacement object type and minor updates","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:14Z","receivedAt":"2013-09-03T07:10:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"The only changes in this new version are:\n\n\t- removed useless redirections in 8/11\n\t- improved commit message in 11/11 (s/litlle/little/)\n\nI may add examples and more in a new patch series later.\n\nChristian Couder (11):\n  replace: forbid replacing an object with one of a different type\n  Documentation/replace: state that objects must be of the same type\n  t6050-replace: test that objects are of the same type\n  t6050-replace: add test to clean up all the replace refs\n  Documentation/replace: add Creating Replacement Objects section\n  replace: bypass the type check if -f option is used\n  Documentation/replace: tell that -f option bypasses the type check\n  t6050-replace: check that -f option bypasses the type check\n  replace: allow long option names\n  Documentation/replace: list long option names\n  t6050-replace: use some long option names\n\n Documentation/git-replace.txt | 28 +++++++++++++++++++++++++---\n builtin/replace.c             | 16 +++++++++++++---\n t/t6050-replace.sh            | 31 ++++++++++++++++++++++++++++---\n 3 files changed, 66 insertions(+), 9 deletions(-)\n\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226584","messageId":"20130903071026.29838.65139.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 01/11] replace: forbid replacing an object with one of a different type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:15Z","receivedAt":"2013-09-03T07:10:15Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Users replacing an object with one of a different type were not\nprevented to do so, even if it was obvious, and stated in the doc,\nthat bad things would result from doing that.\n\nTo avoid mistakes, it is better to just forbid that though.\n\nIf one object is replaced with one of a different type, the only way\nto keep the history valid is to also replace all the other objects\nthat point to the replaced object. That's because:\n\n* Annotated tags contain the type of the tagged object.\n\n* The tree/parent lines in commits must be a tree and commits, resp.\n\n* The object types referred to by trees are specified in the 'mode'\n  field:\n    100644 and 100755    blob\n    160000               commit\n    040000               tree\n  (these are the only valid modes)\n\n* Blobs don't point at anything.\n\nThe doc will be updated in a later patch.\n\nAcked-by: Philip Oakley <philipoakley@iee.org>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/replace.c | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 59d3115..9a94769 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -85,6 +85,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,\n \t\t\t  int force)\n {\n \tunsigned char object[20], prev[20], repl[20];\n+\tenum object_type obj_type, repl_type;\n \tchar ref[PATH_MAX];\n \tstruct ref_lock *lock;\n \n@@ -100,6 +101,15 @@ static int replace_object(const char *object_ref, const char *replace_ref,\n \tif (check_refname_format(ref, 0))\n \t\tdie(\"'%s' is not a valid ref name.\", ref);\n \n+\tobj_type = sha1_object_info(object, NULL);\n+\trepl_type = sha1_object_info(repl, NULL);\n+\tif (obj_type != repl_type)\n+\t\tdie(\"Objects must be of the same type.\\n\"\n+\t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n+\t\t    \"while '%s' points to a replacement object of type '%s'.\",\n+\t\t    object_ref, typename(obj_type),\n+\t\t    replace_ref, typename(repl_type));\n+\n \tif (read_ref(ref, prev))\n \t\thashclr(prev);\n \telse if (!force)\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226592","messageId":"20130903071026.29838.93434.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 02/11] Documentation/replace: state that objects must be of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:16Z","receivedAt":"2013-09-03T07:10:16Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"A previous patch ensures that both the replaced and the replacement\nobjects passed to git replace must be of the same type.\n\nWhile at it state that there is no other restriction on both objects.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex e0b4057..aa66d27 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -20,6 +20,9 @@ The name of the 'replace' reference is the SHA-1 of the object that is\n replaced. The content of the 'replace' reference is the SHA-1 of the\n replacement object.\n \n+The replaced object and the replacement object must be of the same type.\n+There is no other restriction on them.\n+\n Unless `-f` is given, the 'replace' reference must not yet exist.\n \n Replacement references will be used by default by all Git commands\n@@ -69,9 +72,7 @@ go back to a replaced commit will move the branch to the replacement\n commit instead of the replaced commit.\n \n There may be other problems when using 'git rev-list' related to\n-pending objects. And of course things may break if an object of one\n-type is replaced by an object of another type (for example a blob\n-replaced by a commit).\n+pending objects.\n \n SEE ALSO\n --------\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226587","messageId":"20130903071026.29838.76131.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 03/11] t6050-replace: test that objects are of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:17Z","receivedAt":"2013-09-03T07:10:17Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex decdc33..5c352c4 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -263,4 +263,17 @@ test_expect_success 'not just commits' '\n \ttest_cmp file.replaced file\n '\n \n+test_expect_success 'replaced and replacement objects must be of the same type' '\n+\ttest_must_fail git replace mytag $HASH1 2>err &&\n+\tgrep \"mytag. points to a replaced object of type .tag\" err &&\n+\tgrep \"$HASH1. points to a replacement object of type .commit\" err &&\n+\ttest_must_fail git replace HEAD^{tree} HEAD~1 2>err &&\n+\tgrep \"HEAD^{tree}. points to a replaced object of type .tree\" err &&\n+\tgrep \"HEAD~1. points to a replacement object of type .commit\" err &&\n+\tBLOB=$(git rev-parse :file) &&\n+\ttest_must_fail git replace HEAD^ $BLOB 2>err &&\n+\tgrep \"HEAD^. points to a replaced object of type .commit\" err &&\n+\tgrep \"$BLOB. points to a replacement object of type .blob\" err\n+'\n+\n test_done\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226586","messageId":"20130903071026.29838.37890.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 04/11] t6050-replace: add test to clean up all the replace refs","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:18Z","receivedAt":"2013-09-03T07:10:18Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 5c352c4..05be228 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -276,4 +276,10 @@ test_expect_success 'replaced and replacement objects must be of the same type'\n \tgrep \"$BLOB. points to a replacement object of type .blob\" err\n '\n \n+test_expect_success 'replace ref cleanup' '\n+\ttest -n \"$(git replace)\" &&\n+\tgit replace -d $(git replace) &&\n+\ttest -z \"$(git replace)\"\n+'\n+\n test_done\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226595","messageId":"20130903071026.29838.56822.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 05/11] Documentation/replace: add Creating Replacement Objects section","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:19Z","receivedAt":"2013-09-03T07:10:19Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"There were no hints in the documentation about how to create\nreplacement objects.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex aa66d27..736b48c 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -64,6 +64,19 @@ OPTIONS\n \tTyping \"git replace\" without arguments, also lists all replace\n \trefs.\n \n+CREATING REPLACEMENT OBJECTS\n+----------------------------\n+\n+linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and\n+linkgit:git-rebase[1], among other git commands, can be used to create\n+replacement objects from existing objects.\n+\n+If you want to replace many blobs, trees or commits that are part of a\n+string of commits, you may just want to create a replacement string of\n+commits and then only replace the commit at the tip of the target\n+string of commits with the commit at the tip of the replacement string\n+of commits.\n+\n BUGS\n ----\n Comparing blobs or trees that have been replaced with those that\n@@ -76,6 +89,9 @@ pending objects.\n \n SEE ALSO\n --------\n+linkgit:git-hash-object[1]\n+linkgit:git-filter-branch[1]\n+linkgit:git-rebase[1]\n linkgit:git-tag[1]\n linkgit:git-branch[1]\n linkgit:git[1]\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226594","messageId":"20130903071026.29838.76437.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 06/11] replace: bypass the type check if -f option is used","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:20Z","receivedAt":"2013-09-03T07:10:20Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"If -f option, which means '--force', is used, we can allow an object\nto be replaced with one of a different type, as the user should know\nwhat (s)he is doing.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/replace.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 9a94769..95736d9 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -103,7 +103,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,\n \n \tobj_type = sha1_object_info(object, NULL);\n \trepl_type = sha1_object_info(repl, NULL);\n-\tif (obj_type != repl_type)\n+\tif (!force && obj_type != repl_type)\n \t\tdie(\"Objects must be of the same type.\\n\"\n \t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n \t\t    \"while '%s' points to a replacement object of type '%s'.\",\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226593","messageId":"20130903071026.29838.52710.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:21Z","receivedAt":"2013-09-03T07:10:21Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex 736b48c..a2bd2ee 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -21,10 +21,12 @@ replaced. The content of the 'replace' reference is the SHA-1 of the\n replacement object.\n \n The replaced object and the replacement object must be of the same type.\n-There is no other restriction on them.\n+This restriction can be bypassed using `-f`.\n \n Unless `-f` is given, the 'replace' reference must not yet exist.\n \n+There is no other restriction on the replaced and replacement objects.\n+\n Replacement references will be used by default by all Git commands\n except those doing reachability traversal (prune, pack transfer and\n fsck).\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226590","messageId":"20130903071026.29838.23234.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 08/11] t6050-replace: check that -f option bypasses the type check","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:22Z","receivedAt":"2013-09-03T07:10:22Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 05be228..622b751 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -276,6 +276,12 @@ test_expect_success 'replaced and replacement objects must be of the same type'\n \tgrep \"$BLOB. points to a replacement object of type .blob\" err\n '\n \n+test_expect_success '-f option bypasses the type check' '\n+\tgit replace -f mytag $HASH1 &&\n+\tgit replace -f HEAD^{tree} HEAD~1 &&\n+\tgit replace -f HEAD^ $BLOB\n+'\n+\n test_expect_success 'replace ref cleanup' '\n \ttest -n \"$(git replace)\" &&\n \tgit replace -d $(git replace) &&\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226591","messageId":"20130903071026.29838.44765.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 09/11] replace: allow long option names","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:23Z","receivedAt":"2013-09-03T07:10:23Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"It is now standard practice in Git to have both short and long option\nnames. So let's give a long option name to the git replace options too.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/replace.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 95736d9..d4d1b75 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -128,9 +128,9 @@ int cmd_replace(int argc, const char **argv, const char *prefix)\n {\n \tint list = 0, delete = 0, force = 0;\n \tstruct option options[] = {\n-\t\tOPT_BOOLEAN('l', NULL, &list, N_(\"list replace refs\")),\n-\t\tOPT_BOOLEAN('d', NULL, &delete, N_(\"delete replace refs\")),\n-\t\tOPT_BOOLEAN('f', NULL, &force, N_(\"replace the ref if it exists\")),\n+\t\tOPT_BOOLEAN('l', \"list\", &list, N_(\"list replace refs\")),\n+\t\tOPT_BOOLEAN('d', \"delete\", &delete, N_(\"delete replace refs\")),\n+\t\tOPT_BOOLEAN('f', \"force\", &force, N_(\"replace the ref if it exists\")),\n \t\tOPT_END()\n \t};\n \n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226589","messageId":"20130903071026.29838.46822.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 10/11] Documentation/replace: list long option names","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:24Z","receivedAt":"2013-09-03T07:10:24Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex a2bd2ee..414000e 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -54,13 +54,16 @@ achieve the same effect as the `--no-replace-objects` option.\n OPTIONS\n -------\n -f::\n+--force::\n \tIf an existing replace ref for the same object exists, it will\n \tbe overwritten (instead of failing).\n \n -d::\n+--delete::\n \tDelete existing replace refs for the given objects.\n \n -l <pattern>::\n+--list <pattern>::\n \tList replace refs for objects that match the given pattern (or\n \tall if no pattern is given).\n \tTyping \"git replace\" without arguments, also lists all replace\n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226588","messageId":"20130903071026.29838.37918.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"20130903070551.29838.43576.chriscool@tuxfamily.org","subject":"[PATCH v4 11/11] t6050-replace: use some long option names","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-03T07:10:25Z","receivedAt":"2013-09-03T07:10:25Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"So that they are tested a little bit too.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 622b751..1fe5c1b 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -122,9 +122,9 @@ test_expect_success '\"git replace\" listing and deleting' '\n      test \"$HASH2\" = \"$(git replace -l)\" &&\n      test \"$HASH2\" = \"$(git replace)\" &&\n      aa=${HASH2%??????????????????????????????????????} &&\n-     test \"$HASH2\" = \"$(git replace -l \"$aa*\")\" &&\n+     test \"$HASH2\" = \"$(git replace --list \"$aa*\")\" &&\n      test_must_fail git replace -d $R &&\n-     test_must_fail git replace -d &&\n+     test_must_fail git replace --delete &&\n      test_must_fail git replace -l -d $HASH2 &&\n      git replace -d $HASH2 &&\n      git show $HASH2 | grep \"A U Thor\" &&\n@@ -147,7 +147,7 @@ test_expect_success '\"git replace\" resolves sha1' '\n      git show $HASH2 | grep \"O Thor\" &&\n      test_must_fail git replace $HASH2 $R &&\n      git replace -f $HASH2 $R &&\n-     test_must_fail git replace -f &&\n+     test_must_fail git replace --force &&\n      test \"$HASH2\" = \"$(git replace)\"\n '\n \n@@ -278,7 +278,7 @@ test_expect_success 'replaced and replacement objects must be of the same type'\n \n test_expect_success '-f option bypasses the type check' '\n \tgit replace -f mytag $HASH1 &&\n-\tgit replace -f HEAD^{tree} HEAD~1 &&\n+\tgit replace --force HEAD^{tree} HEAD~1 &&\n \tgit replace -f HEAD^ $BLOB\n '\n \n-- \n1.8.4.rc1.31.g530f5ce.dirty\n"},{"id":"226762","messageId":"xmqqa9jsmich.fsf@gitster.dls.corp.google.com","threadId":"34837","inReplyTo":"20130903071026.29838.76131.chriscool@tuxfamily.org","subject":"Re: [PATCH v4 03/11] t6050-replace: test that objects are of the same type","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-04T20:39:58Z","receivedAt":"2013-09-04T20:39:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  t/t6050-replace.sh | 13 +++++++++++++\n>  1 file changed, 13 insertions(+)\n>\n> diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\n> index decdc33..5c352c4 100755\n> --- a/t/t6050-replace.sh\n> +++ b/t/t6050-replace.sh\n> @@ -263,4 +263,17 @@ test_expect_success 'not just commits' '\n>  \ttest_cmp file.replaced file\n>  '\n>  \n> +test_expect_success 'replaced and replacement objects must be of the same type' '\n> +\ttest_must_fail git replace mytag $HASH1 2>err &&\n> +\tgrep \"mytag. points to a replaced object of type .tag\" err &&\n> +\tgrep \"$HASH1. points to a replacement object of type .commit\" err &&\n\nHmm, would these messages ever get translated?  I think it is\nsufficient to make sure that the proposed replacement fails for\nthese cases.\n\n> +\ttest_must_fail git replace HEAD^{tree} HEAD~1 2>err &&\n> +\tgrep \"HEAD^{tree}. points to a replaced object of type .tree\" err &&\n> +\tgrep \"HEAD~1. points to a replacement object of type .commit\" err &&\n> +\tBLOB=$(git rev-parse :file) &&\n> +\ttest_must_fail git replace HEAD^ $BLOB 2>err &&\n> +\tgrep \"HEAD^. points to a replaced object of type .commit\" err &&\n> +\tgrep \"$BLOB. points to a replacement object of type .blob\" err\n> +'\n> +\n>  test_done\n"},{"id":"226764","messageId":"xmqq4na0mi51.fsf@gitster.dls.corp.google.com","threadId":"34837","inReplyTo":"20130903071026.29838.76437.chriscool@tuxfamily.org","subject":"Re: [PATCH v4 06/11] replace: bypass the type check if -f option is used","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-04T20:44:26Z","receivedAt":"2013-09-04T20:44:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> If -f option, which means '--force', is used, we can allow an object\n> to be replaced with one of a different type, as the user should know\n> what (s)he is doing.\n>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n\nThis does not matter in a larger picture, but between 1/11 and this\npatch, there is a window where an operation that has been useful in\nsome workflows becomes unavailable to the user.\n\nFor future reference, it would be better to do this as a part of\n1/11, to make sure that there always is an escape hatch available to\nthe users.\n\n>  builtin/replace.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/builtin/replace.c b/builtin/replace.c\n> index 9a94769..95736d9 100644\n> --- a/builtin/replace.c\n> +++ b/builtin/replace.c\n> @@ -103,7 +103,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,\n>  \n>  \tobj_type = sha1_object_info(object, NULL);\n>  \trepl_type = sha1_object_info(repl, NULL);\n> -\tif (obj_type != repl_type)\n> +\tif (!force && obj_type != repl_type)\n>  \t\tdie(\"Objects must be of the same type.\\n\"\n>  \t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n>  \t\t    \"while '%s' points to a replacement object of type '%s'.\",\n"},{"id":"226765","messageId":"xmqqzjrsl3jl.fsf@gitster.dls.corp.google.com","threadId":"34837","inReplyTo":"20130903071026.29838.52710.chriscool@tuxfamily.org","subject":"Re: [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-04T20:45:02Z","receivedAt":"2013-09-04T20:45:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  Documentation/git-replace.txt | 4 +++-\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\n> index 736b48c..a2bd2ee 100644\n> --- a/Documentation/git-replace.txt\n> +++ b/Documentation/git-replace.txt\n> @@ -21,10 +21,12 @@ replaced. The content of the 'replace' reference is the SHA-1 of the\n>  replacement object.\n>  \n>  The replaced object and the replacement object must be of the same type.\n> -There is no other restriction on them.\n> +This restriction can be bypassed using `-f`.\n>  \n>  Unless `-f` is given, the 'replace' reference must not yet exist.\n>  \n> +There is no other restriction on the replaced and replacement objects.\n> +\n>  Replacement references will be used by default by all Git commands\n>  except those doing reachability traversal (prune, pack transfer and\n>  fsck).\n\nAnd this should be in the same patch as the one that makes the code\nchange.\n"},{"id":"226766","messageId":"xmqqvc2gl3i5.fsf@gitster.dls.corp.google.com","threadId":"34837","inReplyTo":"20130903071026.29838.46822.chriscool@tuxfamily.org","subject":"Re: [PATCH v4 10/11] Documentation/replace: list long option names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-04T20:45:54Z","receivedAt":"2013-09-04T20:45:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  Documentation/git-replace.txt | 3 +++\n>  1 file changed, 3 insertions(+)\n>\n> diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\n> index a2bd2ee..414000e 100644\n> --- a/Documentation/git-replace.txt\n> +++ b/Documentation/git-replace.txt\n> @@ -54,13 +54,16 @@ achieve the same effect as the `--no-replace-objects` option.\n>  OPTIONS\n>  -------\n>  -f::\n> +--force::\n>  \tIf an existing replace ref for the same object exists, it will\n>  \tbe overwritten (instead of failing).\n>  \n>  -d::\n> +--delete::\n>  \tDelete existing replace refs for the given objects.\n>  \n>  -l <pattern>::\n> +--list <pattern>::\n>  \tList replace refs for objects that match the given pattern (or\n>  \tall if no pattern is given).\n>  \tTyping \"git replace\" without arguments, also lists all replace\n\nThis should be in the same commit as what adds them.\n"},{"id":"226767","messageId":"xmqqppsol3ds.fsf@gitster.dls.corp.google.com","threadId":"34837","inReplyTo":"20130903071026.29838.52710.chriscool@tuxfamily.org","subject":"Re: [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-04T20:48:31Z","receivedAt":"2013-09-04T20:48:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  Documentation/git-replace.txt | 4 +++-\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\n> index 736b48c..a2bd2ee 100644\n> --- a/Documentation/git-replace.txt\n> +++ b/Documentation/git-replace.txt\n> @@ -21,10 +21,12 @@ replaced. The content of the 'replace' reference is the SHA-1 of the\n>  replacement object.\n>  \n>  The replaced object and the replacement object must be of the same type.\n> -There is no other restriction on them.\n> +This restriction can be bypassed using `-f`.\n>  \n>  Unless `-f` is given, the 'replace' reference must not yet exist.\n>  \n> +There is no other restriction on the replaced and replacement objects.\n> +\n\nThis is outside the scope of this topic, but I wonder if we want to\nrestrict a replacement operation that causes a cycle in the object\ngraph (a commit reaches itself after following its parent pointer,\na tree reaches itself after looking into trees within, a tag reaches\nitself after following its \"object\" reference), and if we do want\nit, it is feasible to implement it.\n\n>  Replacement references will be used by default by all Git commands\n>  except those doing reachability traversal (prune, pack transfer and\n>  fsck).\n"},{"id":"226847","messageId":"CAP8UFD33DdRjpZnQmPkexpGsKOm7=zouuteMpioGRJ+6LyjVNw@mail.gmail.com","threadId":"34837","inReplyTo":"xmqq4na0mi51.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v4 06/11] replace: bypass the type check if -f option is used","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2013-09-05T12:56:30Z","receivedAt":"2013-09-05T12:56:30Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Sep 4, 2013 at 10:44 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Christian Couder <chriscool@tuxfamily.org> writes:\n>\n>> If -f option, which means '--force', is used, we can allow an object\n>> to be replaced with one of a different type, as the user should know\n>> what (s)he is doing.\n>>\n>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>> ---\n>\n> This does not matter in a larger picture, but between 1/11 and this\n> patch, there is a window where an operation that has been useful in\n> some workflows becomes unavailable to the user.\n>\n> For future reference, it would be better to do this as a part of\n> 1/11, to make sure that there always is an escape hatch available to\n> the users.\n\nOk, I will squash patchs 6/11, 7/11 and 8/11 with 1/11, 2/11 and 3/11\nrespectively.\n\nThanks,\nChristian.\n"},{"id":"226848","messageId":"CAP8UFD1u=mh68WBcfd_O-bSRb0LsaPJdPhqFd47xx=zESxFU7g@mail.gmail.com","threadId":"34837","inReplyTo":"xmqqvc2gl3i5.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v4 10/11] Documentation/replace: list long option names","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2013-09-05T13:03:19Z","receivedAt":"2013-09-05T13:03:19Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Sep 4, 2013 at 10:45 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Christian Couder <chriscool@tuxfamily.org> writes:\n>\n>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>> ---\n>>  Documentation/git-replace.txt | 3 +++\n>>  1 file changed, 3 insertions(+)\n>>\n>> diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\n>> index a2bd2ee..414000e 100644\n>> --- a/Documentation/git-replace.txt\n>> +++ b/Documentation/git-replace.txt\n>> @@ -54,13 +54,16 @@ achieve the same effect as the `--no-replace-objects` option.\n>>  OPTIONS\n>>  -------\n>>  -f::\n>> +--force::\n>>       If an existing replace ref for the same object exists, it will\n>>       be overwritten (instead of failing).\n>>\n>>  -d::\n>> +--delete::\n>>       Delete existing replace refs for the given objects.\n>>\n>>  -l <pattern>::\n>> +--list <pattern>::\n>>       List replace refs for objects that match the given pattern (or\n>>       all if no pattern is given).\n>>       Typing \"git replace\" without arguments, also lists all replace\n>\n> This should be in the same commit as what adds them.\n\nOk, I will squash 10/11 into 9/11.\n\nThanks,\nChristian.\n"},{"id":"226874","messageId":"20130905.211349.627536889681040925.chriscool@tuxfamily.org","threadId":"34837","inReplyTo":"xmqqa9jsmich.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v4 03/11] t6050-replace: test that objects are of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-05T19:13:49Z","receivedAt":"2013-09-05T19:13:49Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n>\n> Christian Couder <chriscool@tuxfamily.org> writes:\n>>  \n>> +test_expect_success 'replaced and replacement objects must be of the same type' '\n>> +\ttest_must_fail git replace mytag $HASH1 2>err &&\n>> +\tgrep \"mytag. points to a replaced object of type .tag\" err &&\n>> +\tgrep \"$HASH1. points to a replacement object of type .commit\" err &&\n> \n> Hmm, would these messages ever get translated?  I think it is\n> sufficient to make sure that the proposed replacement fails for\n> these cases.\n\nOk, I will get rid of the grep statements.\n\nThanks,\nChristian.\n"}]}