commit 3ae1d735fcac2e663e83f81df6d5de866d0ecb85
parent 55397deefe68a7e25065e5d62b1df4267b580910
Author: Remy Noulin (Spartatek) <remy.noulin@spartatek.se>
Date: Thu, 24 Nov 2016 08:57:15 +0100
add configAlways command
git off configAlways [thisrepo] [''|GIT_OFF_CONFIG|repo|global]
'' disable configAlways
GIT_OFF_CONFIG load all configurations from $GIT_OFF_CONFIG
repo load all configurations from current git repo
global load all configurations from global git config
README.md | 5 +++++
src/gitoff.coffee | 60 +++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 54 insertions(+), 11 deletions(-)
Diffstat:
2 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
@@ -135,6 +135,11 @@ git off track
example: git off track '*.bin'
without parameter, list git off attributes
calls git off install
+git off configAlways [thisrepo] [''|GIT_OFF_CONFIG|repo|global]
+ '' disable configAlways
+ GIT_OFF_CONFIG load all configurations from $GIT_OFF_CONFIG
+ repo load all configurations from current git repo
+ global load all configurations from global git config
git off clean
internal filter
dont use directly
diff --git a/src/gitoff.coffee b/src/gitoff.coffee
@@ -4,6 +4,7 @@
# handle wrong config like getLog
# add a command to copy stores
# check parameters from CLI
+# define an empty value that is not empty in config because when the value is empty it searches in other configs
#
# parse params
# use logger
@@ -20,6 +21,8 @@
#
# How to add a new transport
# add transport functions in offHelpers.setTransport
+# add transport in offHelpers.mkdirStore and offHelpers.rmAllStore
+# add transport in offCommands.clearAll
# update git off mode help
# if needed, add store creation in offCommands.install
#
@@ -118,6 +121,7 @@ runtimeConfig =
'offSshOptions': ''
'offScpOptions': ''
'log': ''
+ 'offConfigAlways': ''
# default configuration for first time install
# objectPath is git off cache in repo
@@ -130,6 +134,7 @@ offDEFAULTS =
'scpOptions': '-C -o StrictHostKeyChecking=no -o ConnectTimeout=3 -p'
'store': '~/.git-off/offStore'
'log': '~/.git-off/log'
+ 'configAlways': ''
'prePush': '#!/bin/sh\ncommand -v git-off >/dev/null 2>&1 || { echo >&2 "\\nThis repository is configured for Git off but \'git-off\' was not found on your path. If you no longer wish to use git off, remove this hook by deleting .git/hooks/pre-push.\\n"; exit 2; }\ngit off pre-push "$@"'
'offSignature': '### git-off v1 sha:'
'shaLength': 40
@@ -159,21 +164,32 @@ gitConfig =
return
'get': (key) ->
+ # use configAlways setting or
# return value from
# GIT_OFF_CONFIG if found
# repo config if found
# global config
+ if offHelpers.offConfigAlways() == 'GIT_OFF_CONFIG'
+ r = ''
+ if process.env.GIT_OFF_CONFIG != undefined and fs.existsSync(process.env.GIT_OFF_CONFIG) == true
+ r = exec('gitConfig', ['--file ' + process.env.GIT_OFF_CONFIG, key]).stdout.trim()
+ return r
+ if offHelpers.offConfigAlways() == 'repo'
+ r = ''
+ if fs.existsSync(offHelpers.gitRepoRoot(true) + '/.git-off') == true
+ r = exec('gitConfig', ['--file ' + offHelpers.gitRepoRoot() + '/.git-off', key]).stdout.trim()
+ return r
+ if offHelpers.offConfigAlways() == 'global'
+ return exec('gitConfig', [key]).stdout.trim()
if process.env.GIT_OFF_CONFIG != undefined and 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
- exec('gitConfig', [key]).stdout.trim()
- else
+ if fs.existsSync(offHelpers.gitRepoRoot(true) + '/.git-off') == true
r = exec('gitConfig', ['--file ' + offHelpers.gitRepoRoot() + '/.git-off', key]).stdout.trim()
if r != ''
return r
- exec('gitConfig', [key]).stdout.trim()
+ exec('gitConfig', [key]).stdout.trim()
'getSyncexec': (key) ->
@@ -310,8 +326,7 @@ offHelpers =
'offScpUser': ->
if runtimeConfig.offScpUser == ''
- r = gitConfig.get 'off.scpuser'
- runtimeConfig.offScpUser = expandHome r
+ runtimeConfig.offScpUser = gitConfig.get 'off.scpuser'
runtimeConfig.offScpUser
'log': ->
@@ -329,6 +344,13 @@ offHelpers =
process.exit(1)
runtimeConfig.log
+ 'offConfigAlways': ->
+ if runtimeConfig.offConfigAlways == ''
+ r = gitConfig.getSyncexec 'off.configAlways'
+ runtimeConfig.offConfigAlways = r.stdout.trim()
+ runtimeConfig.offConfigAlways
+
+
'userAt': ->
if offHelpers.offScpUser() != ''
user = offHelpers.offScpUser() + '@'
@@ -553,10 +575,8 @@ offCommands =
else
setCfg('filter.off.smudge','git off smudge %f')
if offHelpers.log() == '' or setCfg != gitConfig.set
- if setCfg == gitConfig.setThisRepo
- gitConfig.setLocal('off.log',offDEFAULTS.log)
- else
- setCfg('off.log',offDEFAULTS.log)
+ # log always in global config
+ gitConfig.set('off.log',offDEFAULTS.log)
if offHelpers.offMode() == '' or setCfg != gitConfig.set
setCfg('off.mode', offDEFAULTS.mode)
@@ -569,7 +589,9 @@ offCommands =
if offHelpers.offScpOptions() == '' or setCfg != gitConfig.set
setCfg('off.scpoptions', offDEFAULTS.scpOptions)
if offHelpers.offStore() == '' or setCfg != gitConfig.set
- setCfg('off.store',offDEFAULTS.store)
+ setCfg('off.store', offDEFAULTS.store)
+ if offHelpers.offConfigAlways() == '' or setCfg != gitConfig.set
+ setCfg('off.configAlways', offDEFAULTS.configAlways)
# create off.store
@@ -659,6 +681,15 @@ offCommands =
console.log l
return
+ 'configAlways': (setCfg) ->
+ len = process.argv.length
+ configAlways = process.argv[len-1]
+ if configAlways != 'configAlways' and configAlways != 'thisrepo'
+ setCfg('off.configAlways', configAlways)
+ else
+ console.log 'off.configAlways '.blue.bold + offHelpers.offConfigAlways()
+ return
+
'clean': ->
# replace files handled by git off with reference
# stdin is data from the working directory file
@@ -860,6 +891,7 @@ 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()
+ console.log 'off.configAlways '.blue.bold + offHelpers.offConfigAlways()
return
'help': ->
@@ -972,6 +1004,12 @@ COMMAND_MAP =
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"
+ 'configAlways':
+ f: ->
+ thisrepo offCommands['configAlways']
+ return
+ h: "git off configAlways [thisrepo] [''|GIT_OFF_CONFIG|repo|global]\n '' disable configAlways\n GIT_OFF_CONFIG load all configurations from $GIT_OFF_CONFIG\n repo load all configurations from current git repo\n global load all configurations from global git config"
+
'clean':
f: ->
offCommands.clean()