git-off

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

commit 55397deefe68a7e25065e5d62b1df4267b580910
parent 391af40500153f10c779a29266b577b62d96d065
Author: Remy Noulin (Spartatek) <remy.noulin@spartatek.se>
Date:   Wed, 23 Nov 2016 21:28:49 +0100

add help

README.md         |  57 +++--------
package.json      |   2 +-
src/git-off       | 276 ++++++++++++++++++++++++++++++++++--------------------
src/gitoff.coffee | 248 +++++++++++++++++++++++++++++++-----------------
4 files changed, 352 insertions(+), 231 deletions(-)

Diffstat:
MREADME.md | 57++++++++++++++-------------------------------------------
Mpackage.json | 2+-
Msrc/git-off | 276++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/gitoff.coffee | 248+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
4 files changed, 352 insertions(+), 231 deletions(-)

diff --git a/README.md b/README.md @@ -25,38 +25,23 @@ Setup: ``` git off track '*.bin' - git off now handles files with bin extensions git add . - use git normally - git off caches bin files git commit - git off caches new bin files git push - git off sends bin files to store git checkout master - checkout commit with bin files - git off downloads bin files from store ``` # Other ``` git off install - setup git config (default global) git off mode scp - store object in a remote sshhost, setup host and path with git off scp git off scp localhost:/tmp/offStore - setup host and path git off scpuser username - setup scp username config git off cc - clear cache in current repo git off ca - clear store and cache git off env - shows current config git off defaults - shows first time config ``` # Configuration @@ -126,67 +111,53 @@ host localhost git off install [thisrepo] setup git config (default global) thisrepo sets up config in current repo - git off mode [thisrepo] [copy|scp] set/show git off mode - +git off scp [thisrepo] [host] + setup scp config + host has format host:path, user@host:path, user@host:port/path + Example: localhost:/tmp/offStore git off integrity [thisrepo] [enable|disable] set/show git off integrity. when enabled, the SHA of the file received from the store is checked again the SHA of the original file - git off pem [thisrepo] [pathToPrivateKey] set/show git off pem. off.pem is the private key for ssh and scp - git off sshoptions [thisrepo] [options] - set/show git off sshoptions. - + set/show git off sshoptions git off scpoptions [thisrepo] [options] - set/show git off scpoptions. - -git off scp [thisrepo] [host] - setup scp config - host has format host:path - Example: localhost:/tmp/offStore - + set/show git off scpoptions git off scpuser [thisrepo] [username] setup scp username config - git off track setup gitattribute filters example: git off track '*.bin' without parameter, list git off attributes calls git off install - git off clean internal filter - -git off smudge - internal filter - + dont use directly git off pre-push internal filter - + dont use directly git off smudge internal filter - + dont use directly git off clearAll + delete store, cache and log git off ca delete store, cache and log - git off clearCache + delete cache in current git git off cc - deletes cache in current git - + delete cache in current git git off defaults shows first time config - git off env shows config - -git off help - shows git off help +git off help [cmd] + git off help. Run git off help command to get help for a specific command. ``` # Dependencies diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "git-off", - "version": "0.0.4", + "version": "0.0.5", "description": "large file handler for git", "bin": "./src/git-off", "scripts": { diff --git a/src/git-off b/src/git-off @@ -40,7 +40,7 @@ /* * modules */ -var StringDecoder, copy, exec, expandHome, externalHelpers, fs, gitConfig, mkdirParents, mkdirp, offCommands, offDEFAULTS, offHelpers, offLog, offLogRepo, oiNAME, oiOID, oiPERMISSIONS, oiPREVIOUSOID, oiPREVIOUSPERMISSIONS, readline, rimraf, rmAll, runtimeConfig, syncexec, thisrepo, transport; +var COMMAND_MAP, StringDecoder, copy, exec, expandHome, externalHelpers, fs, gitConfig, mkdirParents, mkdirp, offCommands, offDEFAULTS, offHelpers, offLog, offLogRepo, oiNAME, oiOID, oiPERMISSIONS, oiPREVIOUSOID, oiPREVIOUSPERMISSIONS, readline, rimraf, rmAll, runtimeConfig, showCommandHelp, syncexec, thisrepo, transport; require('colors'); @@ -135,10 +135,21 @@ gitConfig = { exec('gitConfig', ['--file ' + offHelpers.gitRepoRoot() + '/.git-off', key, '"' + value + '"']); }, 'get': function(key) { + var r; + if (process.env.GIT_OFF_CONFIG !== void 0 && fs.existsSync(process.env.GIT_OFF_CONFIG) === true) { + r = exec('gitConfig', ['--file ' + process.env.GIT_OFF_CONFIG, key]).stdout.trim(); + if (r !== '') { + return r; + } + } if (fs.existsSync(offHelpers.gitRepoRoot(true) + '/.git-off') === false) { return exec('gitConfig', [key]).stdout.trim(); } else { - return exec('gitConfig', ['--file ' + offHelpers.gitRepoRoot() + '/.git-off', key]).stdout.trim(); + r = exec('gitConfig', ['--file ' + offHelpers.gitRepoRoot() + '/.git-off', key]).stdout.trim(); + if (r !== '') { + return r; + } + return exec('gitConfig', [key]).stdout.trim(); } }, 'getSyncexec': function(key) { @@ -712,6 +723,40 @@ offCommands = { console.log('off.scphost '.blue.bold + offHelpers.offScp()); console.log('off.scpuser '.blue.bold + offHelpers.offScpUser()); console.log('off.log '.blue.bold + offHelpers.getLog()); + }, + 'help': function() { + var c, i, len1, ref; + console.log('git-off help\n'.green.bold); + if (process.argv[3] === void 0) { + console.log('# Quick Start'.green.bold); + console.log('Setup:'); + console.log("git off track '*.bin'"); + console.log('git add .'); + console.log('git commit'); + console.log('git push'); + console.log('git checkout master'); + console.log('\n# Other'.green.bold); + console.log('git off install'); + console.log('git off mode scp'); + console.log('git off scp localhost:/tmp/offStore'); + console.log('git off scpuser username'); + console.log('git off cc'); + console.log('git off ca'); + console.log('git off env'); + console.log('git off defaults\n'); + ref = Object.keys(COMMAND_MAP); + for (i = 0, len1 = ref.length; i < len1; i++) { + c = ref[i]; + showCommandHelp(c); + } + console.log('\nGo to https://github.com/RemyNoulin/git-off for more information'.green.bold); + } else { + if (COMMAND_MAP[process.argv[3]] === void 0) { + console.log(COMMAND_MAP.help.h.green); + } else { + showCommandHelp(process.argv[3]); + } + } } }; @@ -728,106 +773,137 @@ thisrepo = function(cmd) { } }; -if (process.argv[2] === 'install') { - thisrepo(offCommands['install']); -} - -if (process.argv[2] === 'mode') { - thisrepo(offCommands['mode']); -} - -if (process.argv[2] === 'scp') { - thisrepo(offCommands['scp']); -} - -if (process.argv[2] === 'integrity') { - thisrepo(offCommands['integrity']); -} - -if (process.argv[2] === 'pem') { - thisrepo(offCommands['pem']); -} - -if (process.argv[2] === 'sshoptions') { - thisrepo(offCommands['sshoptions']); -} - -if (process.argv[2] === 'scpoptions') { - thisrepo(offCommands['scpoptions']); -} - -if (process.argv[2] === 'scpuser') { - thisrepo(offCommands['scpUser']); -} - -if (process.argv[2] === 'track') { - offCommands.track(); -} - -if (process.argv[2] === 'clean') { - offCommands.clean(); -} - -if (process.argv[2] === 'pre-push') { - offCommands.prepush(); -} - -if (process.argv[2] === 'smudge') { - offCommands.smudge(); -} - -if ((process.argv[2] === 'clearAll') || (process.argv[2] === 'ca')) { - offCommands.clearAll(); -} - -if ((process.argv[2] === 'clearCache') || (process.argv[2] === 'cc')) { - offCommands.clearCache(); -} - -if (process.argv[2] === 'defaults') { - offCommands.defaults(); -} +showCommandHelp = function(cmd) { + var l_l; + l_l = COMMAND_MAP[cmd].h.split('\n'); + console.log(l_l[0]); + l_l = l_l.slice(1); + console.log(l_l.join('\n').green); +}; -if (process.argv[2] === 'env') { - offCommands.env(); -} +COMMAND_MAP = { + 'install': { + f: function() { + thisrepo(offCommands['install']); + }, + h: 'git off install [thisrepo]\n setup git config (default global)\n thisrepo sets up config in current repo' + }, + 'mode': { + f: function() { + thisrepo(offCommands['mode']); + }, + h: 'git off mode [thisrepo] [copy|scp]\n set/show git off mode' + }, + 'scp': { + f: function() { + thisrepo(offCommands['scp']); + }, + h: 'git off scp [thisrepo] [host]\n setup scp config\n host has format host:path, user@host:path, user@host:port/path\n Example: localhost:/tmp/offStore' + }, + 'integrity': { + f: function() { + thisrepo(offCommands['integrity']); + }, + h: 'git off integrity [thisrepo] [enable|disable]\n set/show git off integrity.\n when enabled, the SHA of the file received from the store is\n checked again the SHA of the original file' + }, + 'pem': { + f: function() { + thisrepo(offCommands['pem']); + }, + h: 'git off pem [thisrepo] [pathToPrivateKey]\n set/show git off pem.\n off.pem is the private key for ssh and scp' + }, + 'sshoptions': { + f: function() { + thisrepo(offCommands['sshoptions']); + }, + h: 'git off sshoptions [thisrepo] [options]\n set/show git off sshoptions' + }, + 'scpoptions': { + f: function() { + thisrepo(offCommands['scpoptions']); + }, + h: 'git off scpoptions [thisrepo] [options]\n set/show git off scpoptions' + }, + 'scpuser': { + f: function() { + thisrepo(offCommands['scpUser']); + }, + h: 'git off scpuser [thisrepo] [username]\n setup scp username config' + }, + 'track': { + f: function() { + offCommands.track(); + }, + h: "git off track\n setup gitattribute filters\n example: git off track '*.bin'\n without parameter, list git off attributes\n calls git off install" + }, + 'clean': { + f: function() { + offCommands.clean(); + }, + h: 'git off clean\n internal filter\n dont use directly' + }, + 'pre-push': { + f: function() { + offCommands.prepush(); + }, + h: 'git off pre-push\n internal filter\n dont use directly' + }, + 'smudge': { + f: function() { + offCommands.smudge(); + }, + h: 'git off smudge\n internal filter\n dont use directly' + }, + 'clearAll': { + f: function() { + offCommands.clearAll(); + }, + h: 'git off clearAll\n delete store, cache and log' + }, + 'ca': { + f: function() { + offCommands.clearAll(); + }, + h: 'git off ca\n delete store, cache and log' + }, + 'clearCache': { + f: function() { + offCommands.clearCache(); + }, + h: 'git off clearCache\n delete cache in current git' + }, + 'cc': { + f: function() { + offCommands.clearCache(); + }, + h: 'git off cc\n delete cache in current git' + }, + 'defaults': { + f: function() { + offCommands.defaults(); + }, + h: 'git off defaults\n shows first time config' + }, + 'env': { + f: function() { + offCommands.env(); + }, + h: 'git off env\n shows config' + }, + 'help': { + f: function() { + offCommands.help(); + }, + h: 'git off help [cmd]\n git off help. Run git off help command to get help for a specific command.' + } +}; -if (process.argv[2] === 'help' || process.argv[2] === void 0) { - console.log('git-off help\n'.green.bold); - if (process.argv[3] === void 0) { - console.log('# USAGE'.green.bold); - console.log('Setup:'); - console.log("git off track '*.bin'"); - console.log(" git off now handles files with bin extensions".green); - console.log('git add .'); - console.log(' use git normally'.green); - console.log(' git off caches bin files'.green); - console.log('git commit'); - console.log(' git off caches new bin files'.green); - console.log('git push'); - console.log(' git off sends bin files to store'.green); - console.log('git checkout master'); - console.log(' checkout commit with bin files'.green); - console.log(' git off downloads bin files from store'.green); - console.log('\n# Other\n'.green.bold); - console.log('git off install'); - console.log(' setup git config (default global)'.green); - console.log('git off mode scp'); - console.log(' store object in a remote sshhost, setup host and path with git off scp'.green); - console.log('git off scp localhost:/tmp/offStore'); - console.log(' setup host, port and path'.green); - console.log(' user@localhost:port/path'.green); - console.log('git off scpuser username'); - console.log(' setup scp username config'.green); - console.log('git off cc'); - console.log(' clear cache in current repo'.green); - console.log('git off ca'); - console.log(' clear store and cache'.green); - console.log('git off env'); - console.log(' shows current config'.green); - console.log('git off defaults'); - console.log(' shows first time config'.green); +if (process.argv[2] === void 0) { + COMMAND_MAP.help.f(); +} else { + if (COMMAND_MAP[process.argv[2]] === void 0) { + COMMAND_MAP['help'].f(); } else { - console.log('Command help TODO'); + COMMAND_MAP[process.argv[2]].f(); } } diff --git a/src/gitoff.coffee b/src/gitoff.coffee @@ -1,7 +1,6 @@ #! /usr/bin/env coffee # TODO -# add help # handle wrong config like getLog # add a command to copy stores # check parameters from CLI @@ -21,6 +20,7 @@ # # How to add a new transport # add transport functions in offHelpers.setTransport +# update git off mode help # if needed, add store creation in offCommands.install # # How to add a new command @@ -862,6 +862,37 @@ offCommands = console.log 'off.log '.blue.bold + offHelpers.getLog() return + 'help': -> + console.log 'git-off help\n'.green.bold + if process.argv[3] == undefined + console.log '# Quick Start'.green.bold + console.log 'Setup:' + console.log "git off track '*.bin'" + console.log 'git add .' + console.log 'git commit' + console.log 'git push' + console.log 'git checkout master' + console.log '\n# Other'.green.bold + console.log 'git off install' + console.log 'git off mode scp' + console.log 'git off scp localhost:/tmp/offStore' + console.log 'git off scpuser username' + console.log 'git off cc' + console.log 'git off ca' + console.log 'git off env' + console.log 'git off defaults\n' + + for c in Object.keys(COMMAND_MAP) + showCommandHelp(c) + + console.log '\nGo to https://github.com/RemyNoulin/git-off for more information'.green.bold + else + if COMMAND_MAP[process.argv[3]] == undefined + console.log COMMAND_MAP.help.h.green + else + showCommandHelp(process.argv[3]) + return + # list offCommands, run 'git off' #console.log Object.keys(offCommands) @@ -879,90 +910,133 @@ thisrepo = (cmd) -> cmd(gitConfig['setThisRepo']) return -if process.argv[2] == 'install' - thisrepo offCommands['install'] - -if process.argv[2] == 'mode' - thisrepo offCommands['mode'] - -if process.argv[2] == 'scp' - thisrepo offCommands['scp'] - -if process.argv[2] == 'integrity' - thisrepo offCommands['integrity'] - -if process.argv[2] == 'pem' - thisrepo offCommands['pem'] - -if process.argv[2] == 'sshoptions' - thisrepo offCommands['sshoptions'] - -if process.argv[2] == 'scpoptions' - thisrepo offCommands['scpoptions'] - -if process.argv[2] == 'scpuser' - thisrepo offCommands['scpUser'] - -if process.argv[2] == 'track' - offCommands.track() - -if process.argv[2] == 'clean' - offCommands.clean() - -if process.argv[2] == 'pre-push' - offCommands.prepush() - -if process.argv[2] == 'smudge' - offCommands.smudge() - -if (process.argv[2] == 'clearAll') || (process.argv[2] == 'ca') - offCommands.clearAll() - -if (process.argv[2] == 'clearCache') || (process.argv[2] == 'cc') - offCommands.clearCache() - -if process.argv[2] == 'defaults' - offCommands.defaults() - -if process.argv[2] == 'env' - offCommands.env() - -if process.argv[2] == 'help' or process.argv[2] == undefined - console.log 'git-off help\n'.green.bold - if process.argv[3] == undefined - console.log '# USAGE'.green.bold - console.log 'Setup:' - console.log "git off track '*.bin'" - console.log " git off now handles files with bin extensions".green - console.log 'git add .' - console.log ' use git normally'.green - console.log ' git off caches bin files'.green - console.log 'git commit' - console.log ' git off caches new bin files'.green - console.log 'git push' - console.log ' git off sends bin files to store'.green - console.log 'git checkout master' - console.log ' checkout commit with bin files'.green - console.log ' git off downloads bin files from store'.green - console.log '\n# Other\n'.green.bold - console.log 'git off install' - console.log ' setup git config (default global)'.green - console.log 'git off mode scp' - console.log ' store object in a remote sshhost, setup host and path with git off scp'.green - console.log 'git off scp localhost:/tmp/offStore' - console.log ' setup host, port and path'.green - console.log ' user@localhost:port/path'.green - console.log 'git off scpuser username' - console.log ' setup scp username config'.green - console.log 'git off cc' - console.log ' clear cache in current repo'.green - console.log 'git off ca' - console.log ' clear store and cache'.green - console.log 'git off env' - console.log ' shows current config'.green - console.log 'git off defaults' - console.log ' shows first time config'.green - console.log '\nGo to https://github.com/RemyNoulin/git-off for more information'.green.bold +showCommandHelp = (cmd) -> + l_l = COMMAND_MAP[cmd].h.split('\n') + console.log l_l[0] + l_l = l_l.slice(1) + console.log l_l.join('\n').green + return + +COMMAND_MAP = + 'install': + f: -> + thisrepo offCommands['install'] + return + h: 'git off install [thisrepo]\n setup git config (default global)\n thisrepo sets up config in current repo' + + 'mode': + f: -> + thisrepo offCommands['mode'] + return + h: 'git off mode [thisrepo] [copy|scp]\n set/show git off mode' + + 'scp': + f: -> + thisrepo offCommands['scp'] + return + h: 'git off scp [thisrepo] [host]\n setup scp config\n host has format host:path, user@host:path, user@host:port/path\n Example: localhost:/tmp/offStore' + + 'integrity': + f: -> + thisrepo offCommands['integrity'] + return + h: 'git off integrity [thisrepo] [enable|disable]\n set/show git off integrity.\n when enabled, the SHA of the file received from the store is\n checked again the SHA of the original file' + + 'pem': + f: -> + thisrepo offCommands['pem'] + return + h: 'git off pem [thisrepo] [pathToPrivateKey]\n set/show git off pem.\n off.pem is the private key for ssh and scp' + + 'sshoptions': + f: -> + thisrepo offCommands['sshoptions'] + return + h: 'git off sshoptions [thisrepo] [options]\n set/show git off sshoptions' + + 'scpoptions': + f: -> + thisrepo offCommands['scpoptions'] + return + h: 'git off scpoptions [thisrepo] [options]\n set/show git off scpoptions' + + 'scpuser': + f: -> + thisrepo offCommands['scpUser'] + return + h: 'git off scpuser [thisrepo] [username]\n setup scp username config' + + 'track': + f: -> + offCommands.track() + return + h: "git off track\n setup gitattribute filters\n example: git off track '*.bin'\n without parameter, list git off attributes\n calls git off install" + + 'clean': + f: -> + offCommands.clean() + return + h: 'git off clean\n internal filter\n dont use directly' + + 'pre-push': + f: -> + offCommands.prepush() + return + h: 'git off pre-push\n internal filter\n dont use directly' + + 'smudge': + f: -> + offCommands.smudge() + return + h: 'git off smudge\n internal filter\n dont use directly' + + 'clearAll': + f: -> + offCommands.clearAll() + return + h: 'git off clearAll\n delete store, cache and log' + + 'ca': + f: -> + offCommands.clearAll() + return + h: 'git off ca\n delete store, cache and log' + + 'clearCache': + f: -> + offCommands.clearCache() + return + h: 'git off clearCache\n delete cache in current git' + + 'cc': + f: -> + offCommands.clearCache() + return + h: 'git off cc\n delete cache in current git' + + 'defaults': + f: -> + offCommands.defaults() + return + h: 'git off defaults\n shows first time config' + + 'env': + f: -> + offCommands.env() + return + h: 'git off env\n shows config' + + 'help': + f: -> + offCommands.help() + return + h: 'git off help [cmd]\n git off help. Run git off help command to get help for a specific command.' + +if process.argv[2] == undefined + COMMAND_MAP.help.f() +else + if COMMAND_MAP[process.argv[2]] == undefined + COMMAND_MAP['help'].f() else - console.log 'Command help TODO' - # TODO option: thisrepo for local config + COMMAND_MAP[process.argv[2]].f() +