From a42792cf5c9730f3ce1f96b8f729915661495436 Mon Sep 17 00:00:00 2001 From: Eric Salter Date: Sun, 16 Nov 2014 22:02:09 -0500 Subject: [PATCH] add support for git clean Add passthrough support for git clean + tests --- src/repo.coffee | 13 ++++ test/fixtures/clean/a.coffee | 28 +++++++ test/fixtures/clean/b.coffee | 9 +++ test/fixtures/clean/d.js | 44 +++++++++++ test/fixtures/clean/git.git/HEAD | 1 + test/fixtures/clean/git.git/config | 5 ++ test/fixtures/clean/git.git/index | Bin 0 -> 334 bytes .../14/e5a1a3a459e05d486b98df2802ee4b30c33995 | Bin 0 -> 194 bytes .../41/2d321c36a34331125a77493b5dd41f5313a568 | Bin 0 -> 295 bytes .../55/80d8a9feeadf1c36a73a2778c62206314aebac | Bin 0 -> 28 bytes .../56/02c1d7079f5ff3f49f341722c6d5baf93bb26e | 3 + .../c2/dfadf4d76bea7fbe28086d95aa0c803237539e | Bin 0 -> 21 bytes .../fixtures/clean/git.git/objects/info/packs | 2 + ...f08ce8f755306c59b6d804345abf334b5586f8.idx | Bin 0 -> 1408 bytes ...08ce8f755306c59b6d804345abf334b5586f8.pack | Bin 0 -> 1499 bytes .../git.git/refs/heads/f-gitCheckoutFiles | 1 + test/fixtures/clean/git.git/refs/heads/master | 1 + .../fixtures/clean/iamuntracked/untracked.txt | 0 test/fixtures/clean/rawr.txt | 1 + test/repo.test.coffee | 71 ++++++++++++++++++ 20 files changed, 179 insertions(+) create mode 100644 test/fixtures/clean/a.coffee create mode 100644 test/fixtures/clean/b.coffee create mode 100644 test/fixtures/clean/d.js create mode 100644 test/fixtures/clean/git.git/HEAD create mode 100644 test/fixtures/clean/git.git/config create mode 100644 test/fixtures/clean/git.git/index create mode 100644 test/fixtures/clean/git.git/objects/14/e5a1a3a459e05d486b98df2802ee4b30c33995 create mode 100644 test/fixtures/clean/git.git/objects/41/2d321c36a34331125a77493b5dd41f5313a568 create mode 100644 test/fixtures/clean/git.git/objects/55/80d8a9feeadf1c36a73a2778c62206314aebac create mode 100644 test/fixtures/clean/git.git/objects/56/02c1d7079f5ff3f49f341722c6d5baf93bb26e create mode 100644 test/fixtures/clean/git.git/objects/c2/dfadf4d76bea7fbe28086d95aa0c803237539e create mode 100644 test/fixtures/clean/git.git/objects/info/packs create mode 100644 test/fixtures/clean/git.git/objects/pack/pack-70f08ce8f755306c59b6d804345abf334b5586f8.idx create mode 100644 test/fixtures/clean/git.git/objects/pack/pack-70f08ce8f755306c59b6d804345abf334b5586f8.pack create mode 100644 test/fixtures/clean/git.git/refs/heads/f-gitCheckoutFiles create mode 100644 test/fixtures/clean/git.git/refs/heads/master create mode 100644 test/fixtures/clean/iamuntracked/untracked.txt create mode 100644 test/fixtures/clean/rawr.txt diff --git a/src/repo.coffee b/src/repo.coffee index 9bcd5a4..404e6d9 100644 --- a/src/repo.coffee +++ b/src/repo.coffee @@ -355,6 +355,19 @@ module.exports = class Repo checkout: (treeish, callback) -> @git "checkout", {}, treeish, callback + # Public: Clean the git repo by removing untracked files + # + # options - The {Object} containing any of the options available to git clean: + # :force - {Boolean) In the default repo config, clean will not take effect unless this option is given. + # :d - {Boolean) also removes untracked directories + # :n - {Boolean) Dry run - don't actually delete, just report what would be deleted + # :quiet - {Boolean) only report errors + # callback - The {Function} to callback. + # + clean: (options, callback) -> + options ?= {} + @git "clean", options, callback + # Public: Reset the git repo. # # treeish - The {String} to reset to. diff --git a/test/fixtures/clean/a.coffee b/test/fixtures/clean/a.coffee new file mode 100644 index 0000000..0db65dd --- /dev/null +++ b/test/fixtures/clean/a.coffee @@ -0,0 +1,28 @@ +# Assignment: +number = 42 +opposite = true + +# Conditions: +number = -42 if opposite + +# Functions: +square = (x) -> x * x + +# Arrays: +list = [1, 2, 3, 4, 5] + +# Objects: +math = + root: Math.sqrt + square: square + cube: (x) -> x * square x + +# Splats: +race = (winner, runners...) -> + print winner, runners + +# Existence: +alert "I knew it!" if elvis? + +# Array comprehensions: +cubes = (math.cube num for num in list) diff --git a/test/fixtures/clean/b.coffee b/test/fixtures/clean/b.coffee new file mode 100644 index 0000000..3463c49 --- /dev/null +++ b/test/fixtures/clean/b.coffee @@ -0,0 +1,9 @@ +grade = (student) -> + if student.excellentWork + "A+" + else if student.okayStuff + if student.triedHard then "B" else "B-" + else + "C" + +eldest = if 24 > 21 then "Liz" else "Ike" diff --git a/test/fixtures/clean/d.js b/test/fixtures/clean/d.js new file mode 100644 index 0000000..83357ab --- /dev/null +++ b/test/fixtures/clean/d.js @@ -0,0 +1,44 @@ +var cubes, list, math, num, number, opposite, race, square, + __slice = [].slice; + +number = 42; + +opposite = true; + +if (opposite) { + number = -42; +} + +square = function(x) { + return x * x; +}; + +list = [1, 2, 3, 4, 5]; + +math = { + root: Math.sqrt, + square: square, + cube: function(x) { + return x * square(x); + } +}; + +race = function() { + var runners, winner; + winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return print(winner, runners); +}; + +if (typeof elvis !== "undefined" && elvis !== null) { + alert("I knew it!"); +} + +cubes = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = list.length; _i < _len; _i++) { + num = list[_i]; + _results.push(math.cube(num)); + } + return _results; +})(); diff --git a/test/fixtures/clean/git.git/HEAD b/test/fixtures/clean/git.git/HEAD new file mode 100644 index 0000000..cb089cd --- /dev/null +++ b/test/fixtures/clean/git.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/fixtures/clean/git.git/config b/test/fixtures/clean/git.git/config new file mode 100644 index 0000000..515f483 --- /dev/null +++ b/test/fixtures/clean/git.git/config @@ -0,0 +1,5 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true diff --git a/test/fixtures/clean/git.git/index b/test/fixtures/clean/git.git/index new file mode 100644 index 0000000000000000000000000000000000000000..936ee3b3d27dc1141763f15679e406061eb4499e GIT binary patch literal 334 zcmZ?q402{*U|<4bmf)Rh&na$`)DPad#+OTaZ2(YAg5jQo4Ff~t5(Wn57ZA)ik9S+_ zCD+W4e>ORNyIaDQUEh;aqs73HsF$3dmX?~zz<|RXTU2uxcAF$0nY&48cFdfjrtfFD zrb@B;zMa6pkwnNGJ5+O+*_%zPb~hZ@M5WQ zVV{fbFd8T%$#8~M6xAFCwnO*Vez~6gs(zmaNAA>BJPk(X!Sfh6iW19<^hzp97#Ko= kTwQ^B*%)*U6%4pO-FToo%T%l4WtONxb%7 literal 0 HcmV?d00001 diff --git a/test/fixtures/clean/git.git/objects/14/e5a1a3a459e05d486b98df2802ee4b30c33995 b/test/fixtures/clean/git.git/objects/14/e5a1a3a459e05d486b98df2802ee4b30c33995 new file mode 100644 index 0000000000000000000000000000000000000000..7ca6048e91ec922d64d4dcd7f42bb29cca55f2d0 GIT binary patch literal 194 zcmV;z06qVB0TqtHN&`UP=VOBxkVav&@UoBTZzr?tY7hZj0UilPJyFzNj}{C|JE*;N0%Et?S>XCH}4G9{_7h|A0SdPXGV_ literal 0 HcmV?d00001 diff --git a/test/fixtures/clean/git.git/objects/41/2d321c36a34331125a77493b5dd41f5313a568 b/test/fixtures/clean/git.git/objects/41/2d321c36a34331125a77493b5dd41f5313a568 new file mode 100644 index 0000000000000000000000000000000000000000..e4969ec0e6f49449e76e9d9024f3afb3f4c3076d GIT binary patch literal 295 zcmV+?0oeX{0bP+nPs1<_g*oR}Jhlr%T?M1NR2pbPAaOt(I3f;h=dnPWbdI}~e^1

K3Jic33p`7828?-tXS{D zFTB7so58Me!j*gMTy@04wkud?T=Wx6Z_(oty)sMY;ycc%ZIIZ0yG}4maFZZQFn?F# zrTnByBGMGH!NLISz2s5fb1bA`%Mxpc1^F??Le-U|(4U1z5yRfswk~ui7u6tZZ=EAf zz@5gBrm5lqV+tQ+$?08?!TH~;_u literal 0 HcmV?d00001 diff --git a/test/fixtures/clean/git.git/objects/info/packs b/test/fixtures/clean/git.git/objects/info/packs new file mode 100644 index 0000000..e1c1d46 --- /dev/null +++ b/test/fixtures/clean/git.git/objects/info/packs @@ -0,0 +1,2 @@ +P pack-70f08ce8f755306c59b6d804345abf334b5586f8.pack + diff --git a/test/fixtures/clean/git.git/objects/pack/pack-70f08ce8f755306c59b6d804345abf334b5586f8.idx b/test/fixtures/clean/git.git/objects/pack/pack-70f08ce8f755306c59b6d804345abf334b5586f8.idx new file mode 100644 index 0000000000000000000000000000000000000000..dd0977380a84cc287d2311f819e957b0f4676e9f GIT binary patch literal 1408 zcmexg;-AdGz`z8=^r4?oan$3;}a{%Rr0_Fs| z6CdUR%EK@>kUbbN571pS$GqEOFS%xZ{IkjF+uahb?E0RZ8ZGVjEy`|B0%a7BPWro? z_e!+vsT0X2$w%gHQkoqzr>N=sS+1#4tiEq2I4I_dXm$UPGpY~dobbuC_OF9WTaHK) zV}QQ2Y=H9hl=}}A8p z4^ID9KiI?3z3$_d)kiACyBU0wm}S2I%iZ>qd8@zHLY3W(Tit&}>wK+Qugsp?`hV~7 zjMVc7FLb{1Q*JO_+QuAyIF;>y8h?3g@cG}xCuKhH+c-azwA+65+1y97H(k8u?A@)o zt~~0-p(j1T6MbC@YadV9VYpW?^j>M>NB8`T6IOqm*|C{lExYmC&pfTgPWc-{Qm+Lu49I>0%!1p2xDv>>fW#AP8<4-Q;6u-g@1X`c mk=t&tm_+S2_6}|P5hoyI_km6H+r_9y-cBcuw*I|0LmvQe{jaG2 literal 0 HcmV?d00001 diff --git a/test/fixtures/clean/git.git/objects/pack/pack-70f08ce8f755306c59b6d804345abf334b5586f8.pack b/test/fixtures/clean/git.git/objects/pack/pack-70f08ce8f755306c59b6d804345abf334b5586f8.pack new file mode 100644 index 0000000000000000000000000000000000000000..8fdeedee7bb520ddaf3d34347fb5ba936f2b8b79 GIT binary patch literal 1499 zcmV<11tj`VK|@Ob00062000b^5O|!ej7ti_FcbjyIYstD$xHKTLBtEV>Iq(w7h7l= zNmKAPUc_B5WlR#75? zRL*s9n2o5N^if-nQMSUG(CHW%ZgtFs-|#u5X`XQ5gCFC(Ql$xrL zY+z(&kY;Xfnqq34oR*ekZk%jsn4D%{kY=20Vw`GdXl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ean", -> + repo = null + git_dir = __dirname + "/fixtures/junk_clean" + status = null + file = "bla.txt" + dir = 'blah' + + # given a fresh new repo + beforeEach (done) -> + status = null + fs.remove git_dir, (err) -> + return done err if err + fs.copy "#{__dirname}/fixtures/clean", "#{git_dir}", (err) -> + return done err if err + fs.rename "#{git_dir}/git.git", "#{git_dir}/.git", (err) -> + return done err if err + git.init git_dir, (err) -> + repo = git git_dir + fs.writeFile "#{git_dir}/#{file}", "hello", (err) -> + return done err if err? + fs.mkdir "#{git_dir}/#{dir}", (err) -> + done err + + after (done) -> + fs.remove git_dir, (err) -> + done err + + describe "clean with no args shouldn't do anything", -> + beforeEach (done) -> + repo.clean -> + repo.status (err, _status) -> + status = _status + done err + + it "leaves the untracked file alone", -> + fs.existsSync("#{git_dir}/iamuntracked").should.be.true + fs.existsSync("#{git_dir}/iamuntracked/untracked.txt").should.be.true + fs.existsSync("#{git_dir}/#{dir}").should.be.true + status.files.should.have.a.property file + status.files[file].staged.should.be.false + status.files[file].tracked.should.be.false + status.files[file].should.not.have.a.property 'type' + + describe "clean --force", -> + beforeEach (done) -> + repo.clean {force: true}, -> + repo.status (err, _status) -> + status = _status + done err + + it "should remove the file but not the directory", -> + status.files.should.not.have.a.property file + fs.existsSync("#{git_dir}/#{dir}").should.be.true + fs.existsSync("#{git_dir}/iamuntracked").should.be.true + + # git does not clean untracked files in untracked directories + fs.existsSync("#{git_dir}/iamuntracked/untracked.txt").should.be.true + + describe "clean -df", -> + beforeEach (done) -> + repo.clean {force: true, d: true}, -> + repo.status (err, _status) -> + status = _status + done err + + it "removes the file and directory", -> + status.files.should.not.have.a.property file + fs.existsSync("#{git_dir}/#{dir}").should.be.false + fs.existsSync("#{git_dir}/iamuntracked").should.be.false + fs.existsSync("#{git_dir}/iamuntracked/untracked.txt").should.be.false + describe "#reset", -> repo = null git_dir = __dirname + "/fixtures/junk_reset"