#!/bin/sh global test_description := ''Clone repositories and store files in Mock LFS'' source ./lib-git-p4.sh proc test_file_is_not_in_mock_lfs { global FILE := $1 && global CONTENT := $2 && echo $CONTENT >expect_content && test_path_is_file $FILE && test_cmp expect_content $FILE } proc test_file_is_in_mock_lfs { global FILE := $1 && global CONTENT := $2 && global LOCAL_STORAGE := "".git/mock-storage/local/$CONTENT"" && global SERVER_STORAGE := "".git/mock-storage/remote/$CONTENT"" && echo "pointer-$CONTENT" >expect_pointer && echo $CONTENT >expect_content && test_path_is_file $FILE && test_path_is_file $LOCAL_STORAGE && test_path_is_file $SERVER_STORAGE && test_cmp expect_pointer $FILE && test_cmp expect_content $LOCAL_STORAGE && test_cmp expect_content $SERVER_STORAGE } proc test_file_is_deleted_in_mock_lfs { global FILE := $1 && global CONTENT := $2 && global LOCAL_STORAGE := "".git/mock-storage/local/$CONTENT"" && global SERVER_STORAGE := "".git/mock-storage/remote/$CONTENT"" && echo "pointer-$CONTENT" >expect_pointer && echo $CONTENT >expect_content && test_path_is_missing $FILE && test_path_is_file $LOCAL_STORAGE && test_path_is_file $SERVER_STORAGE && test_cmp expect_content $LOCAL_STORAGE && test_cmp expect_content $SERVER_STORAGE } proc test_file_count_in_dir { global DIR := $1 && global EXPECTED_COUNT := $2 && find $DIR -type f >actual && test_line_count = $EXPECTED_COUNT actual } test_expect_success 'start p4d' ' start_p4d ' test_expect_success 'Create repo with binary files' ' client_view "//depot/... //client/..." && ( cd "$cli" && echo "content 1 txt 23 bytes" >file1.txt && p4 add file1.txt && echo "content 2-3 bin 25 bytes" >file2.dat && p4 add file2.dat && p4 submit -d "Add text and binary file" && mkdir "path with spaces" && echo "content 2-3 bin 25 bytes" >"path with spaces/file3.bin" && p4 add "path with spaces/file3.bin" && p4 submit -d "Add another binary file with same content and spaces in path" && echo "content 4 bin 26 bytes XX" >file4.bin && p4 add file4.bin && p4 submit -d "Add another binary file with different content" ) ' test_expect_success 'Store files in Mock LFS based on size (>24 bytes)' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && ( cd "$git" && git init . && git config git-p4.useClientSpec true && git config git-p4.largeFileSystem MockLFS && git config git-p4.largeFileThreshold 24 && git config git-p4.largeFilePush True && git p4 clone --destination="$git" //depot@all && test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" && test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" && test_file_is_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" && test_file_is_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" && test_file_count_in_dir ".git/mock-storage/local" 2 && test_file_count_in_dir ".git/mock-storage/remote" 2 ) ' test_expect_success 'Store files in Mock LFS based on extension (dat)' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && ( cd "$git" && git init . && git config git-p4.useClientSpec true && git config git-p4.largeFileSystem MockLFS && git config git-p4.largeFileExtensions dat && git config git-p4.largeFilePush True && git p4 clone --destination="$git" //depot@all && test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" && test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" && test_file_is_not_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" && test_file_is_not_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" && test_file_count_in_dir ".git/mock-storage/local" 1 && test_file_count_in_dir ".git/mock-storage/remote" 1 ) ' test_expect_success 'Store files in Mock LFS based on extension (dat) and use git p4 sync and no client spec' ' test_when_finished cleanup_git && ( cd "$git" && git init && git config git-p4.useClientSpec true && git config git-p4.largeFileSystem MockLFS && git config git-p4.largeFileExtensions dat && git config git-p4.largeFilePush True && git p4 sync //depot && git checkout p4/master && test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" && test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" && test_file_is_not_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" && test_file_is_not_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" && test_file_count_in_dir ".git/mock-storage/local" 1 && test_file_count_in_dir ".git/mock-storage/remote" 1 ) ' test_expect_success 'Remove file from repo and store files in Mock LFS based on size (>24 bytes)' ' client_view "//depot/... //client/..." && ( cd "$cli" && p4 delete file4.bin && p4 submit -d "Remove file" ) && client_view "//depot/... //client/..." && test_when_finished cleanup_git && ( cd "$git" && git init . && git config git-p4.useClientSpec true && git config git-p4.largeFileSystem MockLFS && git config git-p4.largeFileThreshold 24 && git config git-p4.largeFilePush True && git p4 clone --destination="$git" //depot@all && test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" && test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" && test_file_is_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" && test_file_is_deleted_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" && test_file_count_in_dir ".git/mock-storage/local" 2 && test_file_count_in_dir ".git/mock-storage/remote" 2 ) ' test_expect_success 'Run git p4 submit in repo configured with large file system' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && ( cd "$git" && git init . && git config git-p4.useClientSpec true && git config git-p4.largeFileSystem MockLFS && git config git-p4.largeFileThreshold 24 && git config git-p4.largeFilePush True && git p4 clone --destination="$git" //depot@all && test_must_fail git p4 submit ) ' test_expect_success 'kill p4d' ' kill_p4d ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Clone repositories and store files in Mock LFS">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./lib-git-p4.sh)}) (FuncDef name: test_file_is_not_in_mock_lfs body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FILE) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [23] ) ] spids: [23] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONTENT) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [31] ) ] spids: [31] ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$CONTENT"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(expect_content)} spids: [45] ) ] ) (AndOr children: [ (C {(test_path_is_file)} {(DQ ($ VSub_Name "$FILE"))}) (C {(test_cmp)} {(expect_content)} {(DQ ($ VSub_Name "$FILE"))}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [20] ) spids: [15 19] ) (FuncDef name: test_file_is_in_mock_lfs body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FILE) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [79] ) ] spids: [79] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONTENT) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [87] ) ] spids: [87] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LOCAL_STORAGE) op: Equal rhs: {(DQ (.git/mock-storage/local/) ($ VSub_Name "$CONTENT"))} spids: [95] ) ] spids: [95] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SERVER_STORAGE) op: Equal rhs: {(DQ (.git/mock-storage/remote/) ($ VSub_Name "$CONTENT"))} spids: [104] ) ] spids: [104] ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ (pointer-) ($ VSub_Name "$CONTENT"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(expect_pointer)} spids: [120] ) ] ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$CONTENT"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(expect_content)} spids: [132] ) ] ) (AndOr children: [ (C {(test_path_is_file)} {(DQ ($ VSub_Name "$FILE"))}) (AndOr children: [ (C {(test_path_is_file)} {(DQ ($ VSub_Name "$LOCAL_STORAGE"))} ) (AndOr children: [ (C {(test_path_is_file)} {(DQ ($ VSub_Name "$SERVER_STORAGE"))} ) (AndOr children: [ (C {(test_cmp)} {(expect_pointer)} {(DQ ($ VSub_Name "$FILE"))} ) (AndOr children: [ (C {(test_cmp)} {(expect_content)} {(DQ ($ VSub_Name "$LOCAL_STORAGE"))} ) (C {(test_cmp)} {(expect_content)} {(DQ ($ VSub_Name "$SERVER_STORAGE"))} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [76] ) spids: [71 75] ) (FuncDef name: test_file_is_deleted_in_mock_lfs body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FILE) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [206] ) ] spids: [206] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONTENT) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [214] ) ] spids: [214] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LOCAL_STORAGE) op: Equal rhs: {(DQ (.git/mock-storage/local/) ($ VSub_Name "$CONTENT"))} spids: [222] ) ] spids: [222] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SERVER_STORAGE) op: Equal rhs: {(DQ (.git/mock-storage/remote/) ($ VSub_Name "$CONTENT"))} spids: [231] ) ] spids: [231] ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ (pointer-) ($ VSub_Name "$CONTENT"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(expect_pointer)} spids: [247] ) ] ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$CONTENT"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(expect_content)} spids: [259] ) ] ) (AndOr children: [ (C {(test_path_is_missing)} {(DQ ($ VSub_Name "$FILE"))}) (AndOr children: [ (C {(test_path_is_file)} {(DQ ($ VSub_Name "$LOCAL_STORAGE"))} ) (AndOr children: [ (C {(test_path_is_file)} {(DQ ($ VSub_Name "$SERVER_STORAGE"))} ) (AndOr children: [ (C {(test_cmp)} {(expect_content)} {(DQ ($ VSub_Name "$LOCAL_STORAGE"))} ) (C {(test_cmp)} {(expect_content)} {(DQ ($ VSub_Name "$SERVER_STORAGE"))} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [203] ) spids: [198 202] ) (FuncDef name: test_file_count_in_dir body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DIR) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [322] ) ] spids: [322] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:EXPECTED_COUNT) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [330] ) ] spids: [330] ) (AndOr children: [ (SimpleCommand words: [{(find)} {(DQ ($ VSub_Name "$DIR"))} {(-type)} {(f)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(actual)} spids:[348])] ) (C {(test_line_count)} {(Lit_Other "=")} {($ VSub_Name "$EXPECTED_COUNT")} {(actual)} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [319] ) spids: [314 318] ) (C {(test_expect_success)} {(SQ <"start p4d">)} {(SQ <"\n"> <"\tstart_p4d\n">)}) (C {(test_expect_success)} {(SQ <"Create repo with binary files">)} { (SQ <"\n"> <"\tclient_view \"//depot/... //client/...\" &&\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\n"> <"\t\techo \"content 1 txt 23 bytes\" >file1.txt &&\n"> <"\t\tp4 add file1.txt &&\n"> <"\t\techo \"content 2-3 bin 25 bytes\" >file2.dat &&\n"> <"\t\tp4 add file2.dat &&\n"> <"\t\tp4 submit -d \"Add text and binary file\" &&\n"> <"\n"> <"\t\tmkdir \"path with spaces\" &&\n"> <"\t\techo \"content 2-3 bin 25 bytes\" >\"path with spaces/file3.bin\" &&\n"> <"\t\tp4 add \"path with spaces/file3.bin\" &&\n"> <"\t\tp4 submit -d \"Add another binary file with same content and spaces in path\" &&\n"> <"\n"> <"\t\techo \"content 4 bin 26 bytes XX\" >file4.bin &&\n"> <"\t\tp4 add file4.bin &&\n"> <"\t\tp4 submit -d \"Add another binary file with different content\"\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"Store files in Mock LFS based on size (>24 bytes)">)} { (SQ <"\n"> <"\tclient_view \"//depot/... //client/...\" &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit init . &&\n"> <"\t\tgit config git-p4.useClientSpec true &&\n"> <"\t\tgit config git-p4.largeFileSystem MockLFS &&\n"> <"\t\tgit config git-p4.largeFileThreshold 24 &&\n"> <"\t\tgit config git-p4.largeFilePush True &&\n"> <"\t\tgit p4 clone --destination=\"$git\" //depot@all &&\n"> <"\n"> <"\t\ttest_file_is_not_in_mock_lfs file1.txt \"content 1 txt 23 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs file2.dat \"content 2-3 bin 25 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs \"path with spaces/file3.bin\" \"content 2-3 bin 25 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs file4.bin \"content 4 bin 26 bytes XX\" &&\n"> <"\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/local\" 2 &&\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/remote\" 2\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"Store files in Mock LFS based on extension (dat)">)} { (SQ <"\n"> <"\tclient_view \"//depot/... //client/...\" &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit init . &&\n"> <"\t\tgit config git-p4.useClientSpec true &&\n"> <"\t\tgit config git-p4.largeFileSystem MockLFS &&\n"> <"\t\tgit config git-p4.largeFileExtensions dat &&\n"> <"\t\tgit config git-p4.largeFilePush True &&\n"> <"\t\tgit p4 clone --destination=\"$git\" //depot@all &&\n"> <"\n"> <"\t\ttest_file_is_not_in_mock_lfs file1.txt \"content 1 txt 23 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs file2.dat \"content 2-3 bin 25 bytes\" &&\n"> <"\t\ttest_file_is_not_in_mock_lfs \"path with spaces/file3.bin\" \"content 2-3 bin 25 bytes\" &&\n"> <"\t\ttest_file_is_not_in_mock_lfs file4.bin \"content 4 bin 26 bytes XX\" &&\n"> <"\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/local\" 1 &&\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/remote\" 1\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} { (SQ < "Store files in Mock LFS based on extension (dat) and use git p4 sync and no client spec" > ) } { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit init &&\n"> <"\t\tgit config git-p4.useClientSpec true &&\n"> <"\t\tgit config git-p4.largeFileSystem MockLFS &&\n"> <"\t\tgit config git-p4.largeFileExtensions dat &&\n"> <"\t\tgit config git-p4.largeFilePush True &&\n"> <"\t\tgit p4 sync //depot &&\n"> <"\t\tgit checkout p4/master &&\n"> <"\n"> <"\t\ttest_file_is_not_in_mock_lfs file1.txt \"content 1 txt 23 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs file2.dat \"content 2-3 bin 25 bytes\" &&\n"> < "\t\ttest_file_is_not_in_mock_lfs \"path with spaces/file3.bin\" \"content 2-3 bin 25 bytes\" &&\n" > <"\t\ttest_file_is_not_in_mock_lfs file4.bin \"content 4 bin 26 bytes XX\" &&\n"> <"\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/local\" 1 &&\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/remote\" 1\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"Remove file from repo and store files in Mock LFS based on size (>24 bytes)">)} { (SQ <"\n"> <"\tclient_view \"//depot/... //client/...\" &&\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\tp4 delete file4.bin &&\n"> <"\t\tp4 submit -d \"Remove file\"\n"> <"\t) &&\n"> <"\n"> <"\tclient_view \"//depot/... //client/...\" &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit init . &&\n"> <"\t\tgit config git-p4.useClientSpec true &&\n"> <"\t\tgit config git-p4.largeFileSystem MockLFS &&\n"> <"\t\tgit config git-p4.largeFileThreshold 24 &&\n"> <"\t\tgit config git-p4.largeFilePush True &&\n"> <"\t\tgit p4 clone --destination=\"$git\" //depot@all &&\n"> <"\n"> <"\t\ttest_file_is_not_in_mock_lfs file1.txt \"content 1 txt 23 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs file2.dat \"content 2-3 bin 25 bytes\" &&\n"> <"\t\ttest_file_is_in_mock_lfs \"path with spaces/file3.bin\" \"content 2-3 bin 25 bytes\" &&\n"> <"\t\ttest_file_is_deleted_in_mock_lfs file4.bin \"content 4 bin 26 bytes XX\" &&\n"> <"\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/local\" 2 &&\n"> <"\t\ttest_file_count_in_dir \".git/mock-storage/remote\" 2\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"Run git p4 submit in repo configured with large file system">)} { (SQ <"\n"> <"\tclient_view \"//depot/... //client/...\" &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit init . &&\n"> <"\t\tgit config git-p4.useClientSpec true &&\n"> <"\t\tgit config git-p4.largeFileSystem MockLFS &&\n"> <"\t\tgit config git-p4.largeFileThreshold 24 &&\n"> <"\t\tgit config git-p4.largeFilePush True &&\n"> <"\t\tgit p4 clone --destination=\"$git\" //depot@all &&\n"> <"\n"> <"\t\ttest_must_fail git p4 submit\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"kill p4d">)} {(SQ <"\n"> <"\tkill_p4d\n">)}) (C {(test_done)}) ] )