- for f in files:
- if force:
- print 'Removing file %s' % f
- if os.system('git-update-cache --force-remove -- %s' % f) != 0:
- raise GitException, 'Unable to remove %s' % f
- elif os.path.exists(f):
- raise GitException, '%s exists. Remove it first' %f
- else:
- print 'Removing file %s' % f
- if os.system('git-update-cache --remove -- %s' % f) != 0:
- raise GitException, 'Unable to remove %s' % f
+ if not force:
+ for f in files:
+ if os.path.exists(f):
+ raise GitException, '%s exists. Remove it first' %f
+ if files:
+ __run('git-update-cache --remove --', files)
+ else:
+ if files:
+ __run('git-update-cache --force-remove --', files)
+
+def update_cache(files = [], force = False):
+ """Update the cache information for the given files
+ """
+ cache_files = __tree_status(files)
+
+ # everything is up-to-date
+ if len(cache_files) == 0:
+ return False
+
+ # check for unresolved conflicts
+ if not force and [x for x in cache_files
+ if x[0] not in ['M', 'N', 'A', 'D']]:
+ raise GitException, 'Updating cache failed: unresolved conflicts'
+
+ # update the cache
+ add_files = [x[1] for x in cache_files if x[0] in ['N', 'A']]
+ rm_files = [x[1] for x in cache_files if x[0] in ['D']]
+ m_files = [x[1] for x in cache_files if x[0] in ['M']]
+
+ if add_files and __run('git-update-cache --add --', add_files) != 0:
+ raise GitException, 'Failed git-update-cache --add'
+ if rm_files and __run('git-update-cache --force-remove --', rm_files) != 0:
+ raise GitException, 'Failed git-update-cache --rm'
+ if m_files and __run('git-update-cache --', m_files) != 0:
+ raise GitException, 'Failed git-update-cache'
+
+ return True