comparison tests/test-convert-git.t @ 30660:1f21a6835604

convert: add config option to copy extra keys from Git commits Git commit objects support storing arbitrary key-value metadata. While there is no user-facing mechanism in Git to record these values, some tools do record data here. Currently, `hg convert` only handles the "author," "committer," and "parent" keys in Git commit objects. All other keys are ignored. This means that any custom keys are lost when converting Git repos to Mercurial. This patch implements support for copying a whitelist of extra keys from Git commit objects to the "extras" dict of the destination. As the added tests demonstate, this allows extra metadata to be preserved during the conversion process. This patch stops short of converting all metadata to "extras." We could potentially implement this via `convert.git.extrakeys=*` or similar. But copying everything by default is a bit dangerous because if Git adds new keys to commit objects, we could find ourselves copying things that shouldn't be copied! This patch also assumes the source key is the same as the destination key. We could implement support for prefixing the output key to distinguish it as coming from Git. But until this feature is needed, I'm inclined to hold off implementing it.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 22 Dec 2016 23:28:11 -0700
parents 73b1a209b5b8
children ced0d686ecb3
comparison
equal deleted inserted replaced
30659:1404146157d9 30660:1f21a6835604
802 $ test -f GIT-EXT-COMMAND-INJECTION 802 $ test -f GIT-EXT-COMMAND-INJECTION
803 [1] 803 [1]
804 804
805 #endif 805 #endif
806 806
807 Conversion of extra commit metadata to extras works
808
809 $ git init gitextras >/dev/null 2>/dev/null
810 $ cd gitextras
811 $ touch foo
812 $ git add foo
813 $ commit -m initial
814 $ echo 1 > foo
815 $ tree=`git write-tree`
816
817 Git doesn't provider a user-facing API to write extra metadata into the
818 commit, so create the commit object by hand
819
820 $ git hash-object -t commit -w --stdin << EOF
821 > tree ${tree}
822 > parent ba6b1344e977ece9e00958dbbf17f1f09384b2c1
823 > author test <test@example.com> 1000000000 +0000
824 > committer test <test@example.com> 1000000000 +0000
825 > extra-1 extra-1
826 > extra-2 extra-2 with space
827 > convert_revision 0000aaaabbbbccccddddeeee
828 >
829 > message with extras
830 > EOF
831 8123727c8361a4117d1a2d80e0c4e7d70c757f18
832
833 $ git reset --hard 8123727c8361a4117d1a2d80e0c4e7d70c757f18 > /dev/null
834
835 $ cd ..
836
837 convert will not retain custom metadata keys by default
838
839 $ hg convert gitextras hgextras1
840 initializing destination hgextras1 repository
841 scanning source...
842 sorting...
843 converting...
844 1 initial
845 0 message with extras
846 updating bookmarks
847
848 $ hg -R hgextras1 log --debug -r 1
849 changeset: 1:e13a39880f68479127b2a80fa0b448cc8524aa09
850 bookmark: master
851 tag: tip
852 phase: draft
853 parent: 0:dcb68977c55cd02cbd13b901df65c4b6e7b9c4b9
854 parent: -1:0000000000000000000000000000000000000000
855 manifest: 0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50
856 user: test <test@example.com>
857 date: Sun Sep 09 01:46:40 2001 +0000
858 extra: branch=default
859 extra: convert_revision=8123727c8361a4117d1a2d80e0c4e7d70c757f18
860 description:
861 message with extras
862
863
864
865 Attempting to convert a banned extra is disallowed
866
867 $ hg convert --config convert.git.extrakeys=tree,parent gitextras hgextras-banned
868 initializing destination hgextras-banned repository
869 abort: copying of extra key is forbidden: parent, tree
870 [255]
871
872 Converting a specific extra works
873
874 $ hg convert --config convert.git.extrakeys=extra-1 gitextras hgextras2
875 initializing destination hgextras2 repository
876 scanning source...
877 sorting...
878 converting...
879 1 initial
880 0 message with extras
881 updating bookmarks
882
883 $ hg -R hgextras2 log --debug -r 1
884 changeset: 1:d40fb205d58597e6ecfd55b16f198be5bf436391
885 bookmark: master
886 tag: tip
887 phase: draft
888 parent: 0:dcb68977c55cd02cbd13b901df65c4b6e7b9c4b9
889 parent: -1:0000000000000000000000000000000000000000
890 manifest: 0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50
891 user: test <test@example.com>
892 date: Sun Sep 09 01:46:40 2001 +0000
893 extra: branch=default
894 extra: convert_revision=8123727c8361a4117d1a2d80e0c4e7d70c757f18
895 extra: extra-1=extra-1
896 description:
897 message with extras
898
899
900
901 Converting multiple extras works
902
903 $ hg convert --config convert.git.extrakeys=extra-1,extra-2 gitextras hgextras3
904 initializing destination hgextras3 repository
905 scanning source...
906 sorting...
907 converting...
908 1 initial
909 0 message with extras
910 updating bookmarks
911
912 $ hg -R hgextras3 log --debug -r 1
913 changeset: 1:0105af33379e7b6491501fd34141b7af700fe125
914 bookmark: master
915 tag: tip
916 phase: draft
917 parent: 0:dcb68977c55cd02cbd13b901df65c4b6e7b9c4b9
918 parent: -1:0000000000000000000000000000000000000000
919 manifest: 0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50
920 user: test <test@example.com>
921 date: Sun Sep 09 01:46:40 2001 +0000
922 extra: branch=default
923 extra: convert_revision=8123727c8361a4117d1a2d80e0c4e7d70c757f18
924 extra: extra-1=extra-1
925 extra: extra-2=extra-2 with space
926 description:
927 message with extras
928
929
930