From 5287d5e9e351cfbe36283d8629926cec1ee1587e Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Wed, 25 Jan 2017 12:46:26 -0800 Subject: [PATCH 1/2] Add `copied-file` fixture repo --- .../repo-copied-file/dot-git/COMMIT_EDITMSG | 1 + test/fixtures/repo-copied-file/dot-git/HEAD | 1 + .../repo-copied-file/dot-git/audit_log | 3 + test/fixtures/repo-copied-file/dot-git/config | 6 ++ .../repo-copied-file/dot-git/description | 1 + test/fixtures/repo-copied-file/dot-git/index | Bin 0 -> 209 bytes .../repo-copied-file/dot-git/info/exclude | 6 ++ .../repo-copied-file/dot-git/info/refs | 1 + .../repo-copied-file/dot-git/logs/HEAD | 3 + .../dot-git/logs/refs/heads/master | 3 + .../72/19822bbcd976b5245f4f37dfdc6243ead0749a | Bin 0 -> 171 bytes .../9e/7baca78529e5cd097daeea202f5633045e3cdf | Bin 0 -> 80 bytes .../e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | Bin 0 -> 15 bytes .../dot-git/objects/info/packs | 2 + ...0f2ad2197fb098b6fa2c0ee25a414e21875b0d.idx | Bin 0 -> 1212 bytes ...f2ad2197fb098b6fa2c0ee25a414e21875b0d.pack | Bin 0 -> 876 bytes .../repo-copied-file/dot-git/packed-refs | 2 + .../dot-git/refs/heads/master | 1 + test/fixtures/repo-copied-file/one.cc | 0 test/fixtures/repo-copied-file/two.cc | 83 ++++++++++++++++++ 20 files changed, 113 insertions(+) create mode 100644 test/fixtures/repo-copied-file/dot-git/COMMIT_EDITMSG create mode 100644 test/fixtures/repo-copied-file/dot-git/HEAD create mode 100644 test/fixtures/repo-copied-file/dot-git/audit_log create mode 100644 test/fixtures/repo-copied-file/dot-git/config create mode 100644 test/fixtures/repo-copied-file/dot-git/description create mode 100644 test/fixtures/repo-copied-file/dot-git/index create mode 100644 test/fixtures/repo-copied-file/dot-git/info/exclude create mode 100644 test/fixtures/repo-copied-file/dot-git/info/refs create mode 100644 test/fixtures/repo-copied-file/dot-git/logs/HEAD create mode 100644 test/fixtures/repo-copied-file/dot-git/logs/refs/heads/master create mode 100644 test/fixtures/repo-copied-file/dot-git/objects/72/19822bbcd976b5245f4f37dfdc6243ead0749a create mode 100644 test/fixtures/repo-copied-file/dot-git/objects/9e/7baca78529e5cd097daeea202f5633045e3cdf create mode 100644 test/fixtures/repo-copied-file/dot-git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 create mode 100644 test/fixtures/repo-copied-file/dot-git/objects/info/packs create mode 100644 test/fixtures/repo-copied-file/dot-git/objects/pack/pack-9a0f2ad2197fb098b6fa2c0ee25a414e21875b0d.idx create mode 100644 test/fixtures/repo-copied-file/dot-git/objects/pack/pack-9a0f2ad2197fb098b6fa2c0ee25a414e21875b0d.pack create mode 100644 test/fixtures/repo-copied-file/dot-git/packed-refs create mode 100644 test/fixtures/repo-copied-file/dot-git/refs/heads/master create mode 100644 test/fixtures/repo-copied-file/one.cc create mode 100644 test/fixtures/repo-copied-file/two.cc diff --git a/test/fixtures/repo-copied-file/dot-git/COMMIT_EDITMSG b/test/fixtures/repo-copied-file/dot-git/COMMIT_EDITMSG new file mode 100644 index 0000000000..99c732f855 --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/COMMIT_EDITMSG @@ -0,0 +1 @@ +Add copied file diff --git a/test/fixtures/repo-copied-file/dot-git/HEAD b/test/fixtures/repo-copied-file/dot-git/HEAD new file mode 100644 index 0000000000..cb089cd89a --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/fixtures/repo-copied-file/dot-git/audit_log b/test/fixtures/repo-copied-file/dot-git/audit_log new file mode 100644 index 0000000000..fd092070bd --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/audit_log @@ -0,0 +1,3 @@ +refs/heads/master 0000000000000000000000000000000000000000 e25ea76910cdc213d19ca4de30f64f54dded0f3b Michelle Tilley 1485376931 -0800 { "program":"commit", "via":"commit (initial): Add one.cc\n" } +refs/heads/master e25ea76910cdc213d19ca4de30f64f54dded0f3b 5d336c2d72005417e5c84ac691a518a4f053e39b Michelle Tilley 1485376941 -0800 { "program":"commit", "via":"commit (amend): Add one.cc\n" } +refs/heads/master 5d336c2d72005417e5c84ac691a518a4f053e39b 7219822bbcd976b5245f4f37dfdc6243ead0749a Michelle Tilley 1485376979 -0800 { "program":"commit", "via":"commit: Add copied file\n" } diff --git a/test/fixtures/repo-copied-file/dot-git/config b/test/fixtures/repo-copied-file/dot-git/config new file mode 100644 index 0000000000..1f0486d27a --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + ignorecase = true + precomposeunicode = true diff --git a/test/fixtures/repo-copied-file/dot-git/description b/test/fixtures/repo-copied-file/dot-git/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/fixtures/repo-copied-file/dot-git/index b/test/fixtures/repo-copied-file/dot-git/index new file mode 100644 index 0000000000000000000000000000000000000000..e3a7ef8cffc9c4a64308bf0be3bfecdd51b2b55c GIT binary patch literal 209 zcmZ?q402{*U|<5_h)&*pK$-zYGcqu+GC4KtF)%bPVPIhV3X~E7$v>O>X!fRy*POk( zHP@9#-8l55CwL+QTYg@uUUD)>9;kl@G7U9H3e_B*rUjR0eVtT3>BAqUbIjY9ZoBX) ze-|$UTS<97)SQqYS684pk_<))23+&1*DP< 1485376931 -0800 commit (initial): Add one.cc +e25ea76910cdc213d19ca4de30f64f54dded0f3b 5d336c2d72005417e5c84ac691a518a4f053e39b Michelle Tilley 1485376941 -0800 commit (amend): Add one.cc +5d336c2d72005417e5c84ac691a518a4f053e39b 7219822bbcd976b5245f4f37dfdc6243ead0749a Michelle Tilley 1485376979 -0800 commit: Add copied file diff --git a/test/fixtures/repo-copied-file/dot-git/logs/refs/heads/master b/test/fixtures/repo-copied-file/dot-git/logs/refs/heads/master new file mode 100644 index 0000000000..ddbfabb052 --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/logs/refs/heads/master @@ -0,0 +1,3 @@ +0000000000000000000000000000000000000000 e25ea76910cdc213d19ca4de30f64f54dded0f3b Michelle Tilley 1485376931 -0800 commit (initial): Add one.cc +e25ea76910cdc213d19ca4de30f64f54dded0f3b 5d336c2d72005417e5c84ac691a518a4f053e39b Michelle Tilley 1485376941 -0800 commit (amend): Add one.cc +5d336c2d72005417e5c84ac691a518a4f053e39b 7219822bbcd976b5245f4f37dfdc6243ead0749a Michelle Tilley 1485376979 -0800 commit: Add copied file diff --git a/test/fixtures/repo-copied-file/dot-git/objects/72/19822bbcd976b5245f4f37dfdc6243ead0749a b/test/fixtures/repo-copied-file/dot-git/objects/72/19822bbcd976b5245f4f37dfdc6243ead0749a new file mode 100644 index 0000000000000000000000000000000000000000..4bc42d945b8917877735a7021526a757a4ff774f GIT binary patch literal 171 zcmV;c095~Y0i}*h4#F@D1zG15z5vKg;wF(0f&;MQ0b(`6e7r^ek;^ zn3~AGM{?>?XLzr}vca>+pyR0UD#w1|+Lf8N@3epP{w{UcyNfK-4H_TGg*Jr*XN-vE ZpvTdweqWP3KB$qh%$Z*47;BuPTf`6|{`7>`v58A1mV5|)JbS_ASzjlWPx|nO=^XR+rQ0ri z%HPF%^zIbdiZ=_l?tb@Y5pS9LG`?2`XCK8a&lEU&NciHMCHD-z`G?$n%Wr+0v5`;l z{N}=Yca`LBK963KEZ*}K81+Aa{^bE?2{B;wYXI4kXYp%YlC0k_W7{tszDH4xev0kU byjL$i&02i%toZNu`TO?TS|(;Pbe;nM&6!$t literal 0 HcmV?d00001 diff --git a/test/fixtures/repo-copied-file/dot-git/objects/pack/pack-9a0f2ad2197fb098b6fa2c0ee25a414e21875b0d.pack b/test/fixtures/repo-copied-file/dot-git/objects/pack/pack-9a0f2ad2197fb098b6fa2c0ee25a414e21875b0d.pack new file mode 100644 index 0000000000000000000000000000000000000000..3cfdf5ad38381b7e7f953805c162376422550585 GIT binary patch literal 876 zcmV-y1C#tvK|@Ob00062000G@3wWHB%&`r_AP_*&o+)mDSP;N~6j{jt>9PPE=YV94 zM4<5Yagzbk{Nfj{HzLs9*;TDUOA)o=7>&8c5FK%Y!b>-!GsY>w{OGARcxFtrZ3M4; z_JCW+yKhGsAG*JDPa{lN%K}1KEzRttfD5;rv-6hRJN-|nAHg0mLfvUXWM3H{I^>-T zc$}roy$!=45J2IcDQk`UqW6&J*HXLiU~ zBVRllqe!%*MK}NG%q|#H{0+^V3xqTXJ{fzC;|MOp@R1wy5$iAzu`&dP!d}mimg=Pm z2KBoXc*LMOR&3@%#EGKqHqW!FEh`1!VLT>IiLrZ@(>YlAx3~~9E|t}IjS96Ch1C1W z-Q9{h8%K7YPK4@(W$rvembN8Y$7LK;Rru zYm31+5dw|rv#*TVYot9eTiVvH(E1+B5Zdm4YYmqCb5M+;iP{B4Orht3OBZDr)!VJ*Pxw4FucndU2MX2XC=t*!xXDPWBAl<$Q zoZQw?2HdiKiLV>Nx1mNH#5RMXlr30>lsrZ{!5>3iVT6R+cxsJ>(t}o%jBpCl&U>}R zPJFQgW9-BkJFo_LU!-?n(>?k|YpgH^gOzwVmQqTCBJ*H4vMbz_mbUF6j<&6EU(*EE zkiND*{7EMq?-@V;X5ilqYC*sMPVl>ZistYI(CtF?-+_GtiI)7bq5^oF0U`k1|1mHy zHZ(LKZ*FBSV`BiI)0*{?care@0?q@srMA%WZ@LZW2oLO|0(hJOBLLk0F)%PTG&CS@ zZe=cGV`BiI)0*{?care@0?q@srMA%WZ@LZi5D-tA4=U0bf3TRg`YaCOT0u@Bhg%Jk CQKhN? literal 0 HcmV?d00001 diff --git a/test/fixtures/repo-copied-file/dot-git/packed-refs b/test/fixtures/repo-copied-file/dot-git/packed-refs new file mode 100644 index 0000000000..d21cf9e43a --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/packed-refs @@ -0,0 +1,2 @@ +# pack-refs with: peeled fully-peeled +5d336c2d72005417e5c84ac691a518a4f053e39b refs/heads/master diff --git a/test/fixtures/repo-copied-file/dot-git/refs/heads/master b/test/fixtures/repo-copied-file/dot-git/refs/heads/master new file mode 100644 index 0000000000..ebb39bd235 --- /dev/null +++ b/test/fixtures/repo-copied-file/dot-git/refs/heads/master @@ -0,0 +1 @@ +7219822bbcd976b5245f4f37dfdc6243ead0749a diff --git a/test/fixtures/repo-copied-file/one.cc b/test/fixtures/repo-copied-file/one.cc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/repo-copied-file/two.cc b/test/fixtures/repo-copied-file/two.cc new file mode 100644 index 0000000000..a0d39af592 --- /dev/null +++ b/test/fixtures/repo-copied-file/two.cc @@ -0,0 +1,83 @@ +#include "keytar.h" + +#include + +namespace keytar { + +bool AddPassword(const std::string& service, + const std::string& account, + const std::string& password) { + OSStatus status = SecKeychainAddGenericPassword(NULL, + service.length(), + service.data(), + account.length(), + account.data(), + password.length(), + password.data(), + NULL); + return status == errSecSuccess; +} + +bool GetPassword(const std::string& service, + const std::string& account, + std::string* password) { + void *data; + UInt32 length; + OSStatus status = SecKeychainFindGenericPassword(NULL, + service.length(), + service.data(), + account.length(), + account.data(), + &length, + &data, + NULL); + if (status != errSecSuccess) { + return false; + } + + *password = std::string(reinterpret_cast(data), length); + SecKeychainItemFreeContent(NULL, data); + return true; +} + +bool DeletePassword(const std::string& service, const std::string& account) { + SecKeychainItemRef item; + OSStatus status = SecKeychainFindGenericPassword(NULL, + service.length(), + service.data(), + account.length(), + account.data(), + NULL, + NULL, + &item); + if (status != errSecSuccess) + return false; + + status = SecKeychainItemDelete(item); + CFRelease(item); + return status == errSecSuccess; +} + +bool FindPassword(const std::string& service, std::string* password) { + SecKeychainItemRef item; + void *data; + UInt32 length; + + OSStatus status = SecKeychainFindGenericPassword(NULL, + service.length(), + service.data(), + 0, + NULL, + &length, + &data, + &item); + if (status != errSecSuccess) + return false; + + *password = std::string(reinterpret_cast(data), length); + SecKeychainItemFreeContent(NULL, data); + CFRelease(item); + return true; +} + +} // namespace keytar From 3b92df33fef6108e377c18f97f3f2a78bf284a3b Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Wed, 25 Jan 2017 12:46:47 -0800 Subject: [PATCH 2/2] Fix error when status contains a "copied" file --- lib/git-shell-out-strategy.js | 5 +++++ test/git-shell-out-strategy.test.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/git-shell-out-strategy.js b/lib/git-shell-out-strategy.js index 50c2788298..9e26213b5e 100644 --- a/lib/git-shell-out-strategy.js +++ b/lib/git-shell-out-strategy.js @@ -164,6 +164,7 @@ export default class GitShellOutStrategy { const statusMap = { 'A': 'added', + 'C': 'added', // technically copied, but we'll treat as added 'M': 'modified', 'D': 'deleted', 'U': 'modified', @@ -204,6 +205,10 @@ export default class GitShellOutStrategy { if (x !== ' ' && x !== '?') { stagedFiles[filePath] = statusMap[x]; } + if (x === 'C') { + // skip the next line, which is the copied file + i++; + } } } diff --git a/test/git-shell-out-strategy.test.js b/test/git-shell-out-strategy.test.js index b8d1a9b035..1b8cb5d4da 100644 --- a/test/git-shell-out-strategy.test.js +++ b/test/git-shell-out-strategy.test.js @@ -101,6 +101,23 @@ describe('Git commands', function() { assert.deepEqual(mergeConflictFiles, {}); }); + it('displays copied files as an added file', async function() { + // This repo is carefully constructed after much experimentation + // to cause git to detect `two.cc` as a copy of `one.cc`. + const workingDirPath = await cloneRepository('copied-file'); + const git = new GitShellOutStrategy(workingDirPath); + // Undo the last commit, which is where we copied one.cc to two.cc + // and then emptied one.cc. + await git.exec(['reset', '--soft', 'head^']); + const {stagedFiles, unstagedFiles, mergeConflictFiles} = await git.getStatusesForChangedFiles(); + assert.deepEqual(stagedFiles, { + 'one.cc': 'modified', + 'two.cc': 'added', + }); + assert.deepEqual(unstagedFiles, {}); + assert.deepEqual(mergeConflictFiles, {}); + }); + it('returns an object for merge conflict files, including ours/theirs/file status information', async function() { const workingDirPath = await cloneRepository('merge-conflict'); const git = new GitShellOutStrategy(workingDirPath);