git-off

git off handles large files in git repos
git clone https://noulin.net/git/git-off.git
Log | Files | Refs | README

commit 09d79a013603878607b5b094346040ecfc8264b6
parent eaff8699a44c36aea649c95677ff500e7f028b9d
Author: Remy Noulin (Spartatek) <remy.noulin@spartatek.se>
Date:   Fri,  2 Dec 2016 08:15:29 +0100

create directory for log file and use path dirname, basename

package.json      |  2 +-
src/git-off       | 63 +++++++++++++++++++++++++++++--------------------------
src/gitoff.coffee | 60 ++++++++++++++++++++++++++--------------------------
3 files changed, 64 insertions(+), 61 deletions(-)

Diffstat:
Mpackage.json | 2+-
Msrc/git-off | 63+++++++++++++++++++++++++++++++++------------------------------
Msrc/gitoff.coffee | 60++++++++++++++++++++++++++++++------------------------------
3 files changed, 64 insertions(+), 61 deletions(-)

diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "git-off", - "version": "0.0.9", + "version": "0.0.10", "description": "large file handler for git", "bin": "./src/git-off", "scripts": { diff --git a/src/git-off b/src/git-off @@ -40,12 +40,14 @@ /* * modules */ -var COMMAND_MAP, StringDecoder, copy, exec, expandHome, externalHelpers, fs, fssync, gitConfig, mkdirParents, mkdirp, offCommands, offDEFAULTS, offHelpers, offLog, offLogRepo, oiNAME, oiOID, oiPERMISSIONS, oiPREVIOUSOID, oiPREVIOUSPERMISSIONS, readline, rimraf, rmAll, runtimeConfig, showCommandHelp, syncexec, thisrepo, transport, walkSync; +var COMMAND_MAP, StringDecoder, copy, exec, expandHome, externalHelpers, fs, fssync, gitConfig, mkdirParents, mkdirp, offCommands, offDEFAULTS, offHelpers, offLog, offLogRepo, oiNAME, oiOID, oiPERMISSIONS, oiPREVIOUSOID, oiPREVIOUSPERMISSIONS, path, readline, rimraf, rmAll, runtimeConfig, showCommandHelp, syncexec, thisrepo, transport, walkSync; require('colors'); fs = require('fs'); +path = require('path'); + fssync = require('fs-sync'); syncexec = require('sync-exec'); @@ -139,11 +141,11 @@ offDEFAULTS = { * helpers */ -expandHome = function(path) { - if (path.slice(0, 2) === '~/') { - path = process.env.HOME + '/' + path.slice(2); +expandHome = function(p) { + if (p.slice(0, 2) === '~/') { + p = process.env.HOME + '/' + p.slice(2); } - return path; + return p; }; gitConfig = { @@ -194,6 +196,18 @@ gitConfig = { } }; +mkdirParents = function(p) { + p = expandHome(p); + mkdirp.sync(p, function(err) { + console.error(err); + }); +}; + +rmAll = function(p) { + p = expandHome(p); + rimraf.sync(p); +}; + offLog = function(s) { var r; if (runtimeConfig.log === '') { @@ -204,6 +218,9 @@ offLog = function(s) { process.exit(1); } } + if (fs.existsSync(path.dirname(runtimeConfig.log)) === false) { + mkdirParents(path.dirname(runtimeConfig.log)); + } fs.appendFileSync(runtimeConfig.log, s + '\n'); }; @@ -228,18 +245,6 @@ exec = function(cmdName, paramsArray, ignoreStderr) { return r; }; -mkdirParents = function(path) { - path = expandHome(path); - mkdirp.sync(path, function(err) { - console.error(err); - }); -}; - -rmAll = function(path) { - path = expandHome(path); - rimraf.sync(path); -}; - copy = function(src, dst) { fssync.copy(src, dst); }; @@ -424,10 +429,10 @@ offHelpers = { } return [user + host, storePath, port]; }, - 'mkdirStore': function(path) { + 'mkdirStore': function(p) { var h_l, pem, sshCmd; h_l = offHelpers.getSSHConfig(); - sshCmd = '"mkdir -p ' + h_l[1] + '/' + path; + sshCmd = '"mkdir -p ' + h_l[1] + '/' + p; sshCmd += '"'; if (offHelpers.offPem() === '' || offHelpers.offPem() === 'offNoValue') { pem = ''; @@ -440,7 +445,7 @@ offHelpers = { exec('ssh', [offHelpers.offSshOptions(), pem, '-p ' + h_l[2], h_l[0], sshCmd], true); } }, - 'rmAllStore': function(path) { + 'rmAllStore': function(p) { var h_l, pem, sshCmd; if (offHelpers.offPem() === '' || offHelpers.offPem() === 'offNoValue') { pem = ''; @@ -448,7 +453,7 @@ offHelpers = { pem = '-i ' + offHelpers.offPem(); } h_l = offHelpers.getSSHConfig(); - sshCmd = '"rm -rf ' + h_l[1] + '/' + path; + sshCmd = '"rm -rf ' + h_l[1] + '/' + p; sshCmd += '"'; if (isNaN(h_l[2])) { exec('ssh', [offHelpers.offSshOptions(), pem, h_l[0], sshCmd], true); @@ -469,17 +474,16 @@ offHelpers = { transport.send(f); } }, - 'checkIntegrity': function(path) { - var path_l, r, receivedSha, result; + 'checkIntegrity': function(p) { + var r, receivedSha, result; result = true; if (offHelpers.offIntegrity() === 'disable') { return true; } - r = exec('sha', [path]); + r = exec('sha', [p]); receivedSha = r.stdout.split(' ')[0].trim(); - path_l = path.split('/'); - if (path_l[path_l.length - 1] !== receivedSha) { - console.log('git-off: The file ' + path + ' differs from the one that was pushed.'); + if (path.basename(p) !== receivedSha) { + console.log('git-off: The file ' + p + ' differs from the one that was pushed.'); result = false; } return result; @@ -662,9 +666,8 @@ transport = { 'send': function(src) {}, 'receive': function(src) {}, 'transformFrom': function(file) { - var cmd, f_l, offFile, offFilePath, r; - f_l = file.split('/'); - offFile = f_l[f_l.length - 1]; + var cmd, offFile, offFilePath, r; + offFile = path.basename(file); offFilePath = offHelpers.getOffFilePath(offFile); if (fs.existsSync(offHelpers.objectPath() + '/../tmp/' + offFilePath[1]) === false) { mkdirParents(offHelpers.objectPath() + '/../tmp/' + offFilePath[1]); diff --git a/src/gitoff.coffee b/src/gitoff.coffee @@ -75,6 +75,7 @@ require('colors') fs = require('fs') +path = require('path') fssync = require('fs-sync') syncexec = require('sync-exec') mkdirp = require('mkdirp') @@ -162,10 +163,10 @@ offDEFAULTS = ### # expands ~/ -expandHome = (path) -> - if path.slice(0,2) == '~/' - path = process.env.HOME + '/' + path.slice(2) - path +expandHome = (p) -> + if p.slice(0,2) == '~/' + p = process.env.HOME + '/' + p.slice(2) + p # handles global git config gitConfig = @@ -214,6 +215,20 @@ gitConfig = # always global git config syncexec externalHelpers.gitConfig + ' ' + key +# recursive mkdir +mkdirParents = (p) -> + p = expandHome p + mkdirp.sync(p, (err) -> + console.error err + return) + return + +# delete recursively files and directories +rmAll = (p) -> + p = expandHome p + rimraf.sync p + return + # appends log to git config off.log offLog = (s) -> if runtimeConfig.log == '' @@ -226,6 +241,8 @@ offLog = (s) -> console.error 'Missing off.log config. Run "git config --global off.log ~/.git-off/log".'.red.bold process.exit(1) # append log (s) + if fs.existsSync(path.dirname(runtimeConfig.log)) == false + mkdirParents path.dirname(runtimeConfig.log) fs.appendFileSync(runtimeConfig.log, s + '\n') return @@ -254,20 +271,6 @@ exec = (cmdName, paramsArray=[], ignoreStderr=false) -> process.exit(1) r -# recursive mkdir -mkdirParents = (path) -> - path = expandHome path - mkdirp.sync(path, (err) -> - console.error err - return) - return - -# delete recursively files and directories -rmAll = (path) -> - path = expandHome path - rimraf.sync path - return - # copies files # file modes are not kept copy = (src, dst) -> @@ -440,13 +443,13 @@ offHelpers = [user + host, storePath, port] - 'mkdirStore': (path) -> + 'mkdirStore': (p) -> # mkdir in remote store # TODO handle multiple transports h_l = offHelpers.getSSHConfig() # bug in coffeescript - cant have '"mkdir '+ h_l[1] +'"' - sshCmd = '"mkdir -p '+ h_l[1] + '/' + path + sshCmd = '"mkdir -p '+ h_l[1] + '/' + p sshCmd += '"' # setup ssh/scp private key @@ -462,7 +465,7 @@ offHelpers = exec 'ssh', [offHelpers.offSshOptions(), pem, '-p ' + h_l[2], h_l[0], sshCmd], true return - 'rmAllStore': (path) -> + 'rmAllStore': (p) -> # rm in remote store # setup ssh/scp private key @@ -474,7 +477,7 @@ offHelpers = # scphost format is host:path h_l = offHelpers.getSSHConfig() # bug in coffeescript - cant have '"mkdir '+ h_l[1] +'"' - sshCmd = '"rm -rf '+ h_l[1] + '/' + path + sshCmd = '"rm -rf '+ h_l[1] + '/' + p sshCmd += '"' # ignore error from rm if isNaN h_l[2] @@ -500,7 +503,7 @@ offHelpers = transport.send f return - 'checkIntegrity': (path) -> + 'checkIntegrity': (p) -> # check integrity of files coming from the store result = true @@ -508,15 +511,13 @@ offHelpers = if offHelpers.offIntegrity() == 'disable' return true - r = exec 'sha', [path] + r = exec 'sha', [p] # trim because git hash-object adds \n receivedSha = r.stdout.split(' ')[0].trim() - path_l = path.split('/') - - if path_l[path_l.length-1] != receivedSha + if path.basename(p) != receivedSha # the file received is different from the one that was sent. - console.log 'git-off: The file ' + path + ' differs from the one that was pushed.' + console.log 'git-off: The file ' + p + ' differs from the one that was pushed.' result = false result @@ -710,8 +711,7 @@ transport = 'transformFrom': (file) -> # transform file in objectPath to objectPath/../tmp/file # create directories in tmp - f_l = file.split('/') - offFile = f_l[f_l.length-1] + offFile = path.basename file offFilePath = offHelpers.getOffFilePath(offFile) if fs.existsSync(offHelpers.objectPath() + '/../tmp/' + offFilePath[1]) == false # create the file directory