Skip to content

Commit

Permalink
Only do backend checks for push and pull commands
Browse files Browse the repository at this point in the history
A lot of commands will work without a .gitfat file and so git-fat
shouldn't care whether or not it's there unless it's needed.
  • Loading branch information
abraithwaite committed Sep 27, 2014
1 parent e82a028 commit 7dd95b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
19 changes: 9 additions & 10 deletions git_fat/git_fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def pull_files(self, file_list):
try:
p = sub.Popen(rsync, stdin=sub.PIPE)
except OSError:
## re-raise with a more useful message
# re-raise with a more useful message
raise OSError('Error running "%s"' % " ".join(rsync))

p.communicate(input='\x00'.join(file_list))
Expand Down Expand Up @@ -912,14 +912,9 @@ def main():
help='prevent adding excluded to .gitattributes', action='store_false')
sp.set_defaults(func='index_filter')

try:
# Being lazy by not using argparse
if sys.argv[1] in [c + 'version' for c in '', '-', '--']:
print(__version__)
sys.exit(0)
except IndexError:
parser.print_help()
sys.exit(1)
if len(sys.argv) > 0 and sys.argv[1] in [c + 'version' for c in '', '-', '--']:
print(__version__)
sys.exit(0)

args = parser.parse_args()
kwargs = dict(vars(args))
Expand All @@ -932,10 +927,14 @@ def main():
log_level = logging.WARNING
_configure_logging(log_level)

require_backend = ('pull', 'push')

try:
backend_opt = kwargs.pop('backend', None)
config_file = kwargs.pop('config_file', None)
backend = _parse_config(backend=backend_opt, cfg_file_path=config_file)
backend = None
if kwargs['func'] in require_backend:
backend = _parse_config(backend=backend_opt, cfg_file_path=config_file)
run(backend, **kwargs)
except RuntimeError as err:
logging.error(str(err))
Expand Down
14 changes: 12 additions & 2 deletions tests/test_git_fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def tearDown(self):


class InitTestCase(Base):
""" Test cases which have not had git-fat initalized yet """

def test_git_fat_init(self):
with open('.gitfat', 'w') as f:
Expand All @@ -101,11 +102,20 @@ def test_git_fat_init(self):
out = git('config filter.fat.smudge')
self.assertEqual(out.strip(), 'git-fat filter-smudge %f')

def test_git_fat_noconfig(self):
out = git('fat status', stderr=sub.STDOUT)
def test_git_fat_no_dotgitfat(self):
out = git('fat push', stderr=sub.STDOUT)
self.assertTrue("Missing config" in out)
self.assertTrue("does not appear" in out)

def test_command_not_push(self):
""" Test that find works without a backend """
filename = 'somebin.png'
with open(filename, 'w') as f:
f.write('aa' * 9990)
commit('add file')
out = git('fat find 9000', stderr=sub.STDOUT)
self.assertTrue('somebin.png' in out)

def test_existing_files_pattern_match(self):
""" Don't convert existing files into git-fat files unless they get renamed """

Expand Down

0 comments on commit 7dd95b2

Please sign in to comment.