summaryrefslogtreecommitdiff
path: root/git-fat
diff options
context:
space:
mode:
authorJed Brown <jed@59A2.org>2012-11-26 15:18:05 +0100
committerJed Brown <jed@59A2.org>2012-11-26 15:18:05 +0100
commit8376a2b0c6eac4c1753350e357d3bb1c74e1cc3e (patch)
tree549fc12be49e1f4b17d8e7d66054614a55bfb84c /git-fat
parenta2b5d616de4172ea4b0089b9f42f0cb87491d20b (diff)
downloadgit-fat-8376a2b0c6eac4c1753350e357d3bb1c74e1cc3e.tar.gz
Improved use of git-config in git init and reading .gitfat
git fat init now checks whether the filter.fat section is already defined. Manage .gitfat using git-config instead of Python ConfigParser, which has different syntax support.
Diffstat (limited to 'git-fat')
-rwxr-xr-xgit-fat40
1 files changed, 26 insertions, 14 deletions
diff --git a/git-fat b/git-fat
index 878ac26..04a1466 100755
--- a/git-fat
+++ b/git-fat
@@ -39,6 +39,23 @@ def cat_iter(initer, outstream):
outstream.write(block)
def cat(instream, outstream):
return cat_iter(readblocks(instream), outstream)
+def gitconfig_get(name, file=None):
+ args = ['git', 'config', '--get']
+ if file is not None:
+ args += ['--file', file]
+ args.append(name)
+ p = subprocess.Popen(args, stdout=subprocess.PIPE)
+ output = p.communicate()[0].strip()
+ if p.returncode != 0:
+ return None
+ else:
+ return output
+def gitconfig_set(name, value, file=None):
+ args = ['git', 'config']
+ if file is not None:
+ args += ['--file', file]
+ args += [name, value]
+ p = subprocess.check_call(args)
class GitFat(object):
DecodeError = RuntimeError
@@ -50,17 +67,11 @@ class GitFat(object):
def setup(self):
mkdir_p(self.objdir)
def get_rsync(self):
- import ConfigParser
cfgpath = os.path.join(self.gitroot,'.gitfat')
- try:
- config = ConfigParser.RawConfigParser()
- config.read(cfgpath)
- remote = config.get('rsync', 'remote')
- if remote[0] in ['"', "'"] and remote[-1] in ['"', "'"]:
- remote = remote[1:-1]
- return remote
- except ConfigParser.NoSectionError:
+ remote = gitconfig_get('rsync.remote', file=cfgpath)
+ if remote is None:
raise RuntimeError('No rsync.remote in %s' % cfgpath)
+ return remote
def revparse(self, revname):
return subprocess.check_output(['git', 'rev-parse', revname]).strip()
def encode(self, digest):
@@ -246,11 +257,12 @@ class GitFat(object):
os.remove(fname)
def cmd_init(self):
self.setup()
- open(os.path.join(self.gitroot,'.git','config'), 'a').writelines([
- '[filter "fat"]\n',
- ' clean = git-fat filter-clean\n',
- ' smudge = git-fat filter-smudge\n',
- ])
+ if gitconfig_get('filter.fat.clean') or gitconfig_get('filter.fat.smudge'):
+ print('Git fat already configured, check configuration in .git/config')
+ else:
+ gitconfig_set('filter.fat.clean', 'git-fat filter-clean')
+ gitconfig_set('filter.fat.smudge', 'git-fat filter-smudge')
+ print('Initialized git fat')
if __name__ == '__main__':
fat = GitFat()