#!/bin/sh # # Copyright (c) 2014 Alfred Perlstein # global test_description := ''git svn propset tests'' source ./lib-git-svn.sh global foo_subdir2 := '"subdir/subdir2/foo_subdir2'" set -e mkdir import && shell {set -e ; cd import mkdir subdir mkdir subdir/subdir2 touch foo # for 'add props top level' touch subdir/foo_subdir # for 'add props relative' touch $foo_subdir2 # for 'add props subdir' svn_cmd import -m 'import for git svn' . $svnrepo >/dev/null } rm -rf import test_expect_success 'initialize git svn' ' git svn init "$svnrepo" ' test_expect_success 'fetch revisions from svn' ' git svn fetch ' proc set_props { global subdir := $1 global file := $2 shift;shift; shell {cd $subdir && while [ $# -gt 0 ] { git svn propset $1 $2 $file || exit 1 shift;shift; } && echo hello >> $file && git commit -m "testing propset" $file} } proc confirm_props { global subdir := $1 global file := $2 shift;shift; shell {set -e ; cd "svn_project/$subdir" && while [ $# -gt 0 ] { test $[svn_cmd propget $1 $file] = $2 || exit 1 shift;shift; }} } #The current implementation has a restriction: #svn propset will be taken as a delta for svn dcommit only #if the file content is also modified test_expect_success 'add props top level' ' set_props "." "foo" "svn:keywords" "FreeBSD=%H" && git svn dcommit && svn_cmd co "$svnrepo" svn_project && confirm_props "." "foo" "svn:keywords" "FreeBSD=%H" && rm -rf svn_project ' test_expect_success 'add multiple props' ' set_props "." "foo" \ "svn:keywords" "FreeBSD=%H" fbsd:nokeywords yes && git svn dcommit && svn_cmd co "$svnrepo" svn_project && confirm_props "." "foo" \ "svn:keywords" "FreeBSD=%H" fbsd:nokeywords yes && rm -rf svn_project ' test_expect_success 'add props subdir' ' set_props "." "$foo_subdir2" svn:keywords "FreeBSD=%H" && git svn dcommit && svn_cmd co "$svnrepo" svn_project && confirm_props "." "$foo_subdir2" "svn:keywords" "FreeBSD=%H" && rm -rf svn_project ' test_expect_success 'add props relative' ' set_props "subdir/subdir2" "../foo_subdir" \ svn:keywords "FreeBSD=%H" && git svn dcommit && svn_cmd co "$svnrepo" svn_project && confirm_props "subdir/subdir2" "../foo_subdir" \ svn:keywords "FreeBSD=%H" && rm -rf svn_project ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git svn propset tests">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./lib-git-svn.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:foo_subdir2) op: Equal rhs: {(DQ (subdir/subdir2/foo_subdir2))} spids: [24] ) ] spids: [24] ) (C {(set)} {(-e)}) (AndOr children: [ (C {(mkdir)} {(import)}) (Subshell child: (CommandList children: [ (Sentence child:(C {(set)} {(-e)}) terminator:) (C {(cd)} {(import)}) (C {(mkdir)} {(subdir)}) (C {(mkdir)} {(subdir/subdir2)}) (C {(touch)} {(foo)}) (C {(touch)} {(subdir/foo_subdir)}) (C {(touch)} {(DQ ($ VSub_Name "$foo_subdir2"))}) (SimpleCommand words: [ {(svn_cmd)} {(import)} {(-m)} {(SQ <"import for git svn">)} {(.)} {(DQ ($ VSub_Name "$svnrepo"))} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[104])] ) ] ) spids: [40 107] ) ] op_id: Op_DAmp ) (C {(rm)} {(-rf)} {(import)}) (C {(test_expect_success)} {(SQ <"initialize git svn">)} {(SQ <"\n"> <"\tgit svn init \"$svnrepo\"\n"> <"\t">)} ) (C {(test_expect_success)} {(SQ <"fetch revisions from svn">)} {(SQ <"\n"> <"\tgit svn fetch\n"> <"\t">)} ) (FuncDef name: set_props body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:subdir) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [150] ) ] spids: [150] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [156] ) ] spids: [156] ) (Sentence child:(C {(shift)}) terminator:) (Sentence child:(C {(shift)}) terminator:) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Name "$subdir"))}) (AndOr children: [ (While cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(-gt)} {(0)} {(Lit_Other "]")}) terminator: ) ] body: (DoGroup children: [ (AndOr children: [ (C {(git)} {(svn)} {(propset)} {(DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Number "$2"))} {(DQ ($ VSub_Name "$file"))} ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (Sentence child: (C {(shift)}) terminator: ) (Sentence child: (C {(shift)}) terminator: ) ] spids: [192 226] ) ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(hello)}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(DQ ($ VSub_Name "$file"))} spids: [235] ) ] ) (C {(git)} {(commit)} {(-m)} {(DQ ("testing propset"))} {(DQ ($ VSub_Name "$file"))} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [168 257] ) ] spids: [147] ) spids: [142 146] ) (FuncDef name: confirm_props body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:subdir) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [270] ) ] spids: [270] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [276] ) ] spids: [276] ) (Sentence child:(C {(shift)}) terminator:) (Sentence child:(C {(shift)}) terminator:) (Subshell child: (CommandList children: [ (Sentence child:(C {(set)} {(-e)}) terminator:) (AndOr children: [ (C {(cd)} {(DQ (svn_project/) ($ VSub_Name "$subdir"))}) (While cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(-gt)} {(0)} {(Lit_Other "]")}) terminator: ) ] body: (DoGroup children: [ (AndOr children: [ (C {(test)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(svn_cmd)} {(propget)} {(DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Name "$file"))} ) ] ) left_token: spids: [325 337] ) ) } {(Lit_Other "=")} {(DQ ($ VSub_Number "$2"))} ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (Sentence child: (C {(shift)}) terminator: ) (Sentence child: (C {(shift)}) terminator: ) ] spids: [319 359] ) ) ] op_id: Op_DAmp ) ] ) spids: [288 360] ) ] spids: [267] ) spids: [262 266] ) (C {(test_expect_success)} {(SQ <"add props top level">)} { (SQ <"\n"> <"\tset_props \".\" \"foo\" \"svn:keywords\" \"FreeBSD=%H\" &&\n"> <"\tgit svn dcommit &&\n"> <"\tsvn_cmd co \"$svnrepo\" svn_project &&\n"> <"\tconfirm_props \".\" \"foo\" \"svn:keywords\" \"FreeBSD=%H\" &&\n"> <"\trm -rf svn_project\n"> <"\t"> ) } ) (C {(test_expect_success)} {(SQ <"add multiple props">)} { (SQ <"\n"> <"\tset_props \".\" \"foo\" \\\n"> <"\t\t\"svn:keywords\" \"FreeBSD=%H\" fbsd:nokeywords yes &&\n"> <"\tgit svn dcommit &&\n"> <"\tsvn_cmd co \"$svnrepo\" svn_project &&\n"> <"\tconfirm_props \".\" \"foo\" \\\n"> <"\t\t\"svn:keywords\" \"FreeBSD=%H\" fbsd:nokeywords yes &&\n"> <"\trm -rf svn_project\n"> <"\t"> ) } ) (C {(test_expect_success)} {(SQ <"add props subdir">)} { (SQ <"\n"> <"\tset_props \".\" \"$foo_subdir2\" svn:keywords \"FreeBSD=%H\" &&\n"> <"\tgit svn dcommit &&\n"> <"\tsvn_cmd co \"$svnrepo\" svn_project &&\n"> <"\tconfirm_props \".\" \"$foo_subdir2\" \"svn:keywords\" \"FreeBSD=%H\" &&\n"> <"\trm -rf svn_project\n"> <"\t"> ) } ) (C {(test_expect_success)} {(SQ <"add props relative">)} { (SQ <"\n"> <"\tset_props \"subdir/subdir2\" \"../foo_subdir\" \\\n"> <"\t\tsvn:keywords \"FreeBSD=%H\" &&\n"> <"\tgit svn dcommit &&\n"> <"\tsvn_cmd co \"$svnrepo\" svn_project &&\n"> <"\tconfirm_props \"subdir/subdir2\" \"../foo_subdir\" \\\n"> <"\t\tsvn:keywords \"FreeBSD=%H\" &&\n"> <"\trm -rf svn_project\n"> <"\t"> ) } ) (C {(test_done)}) ] )