Esempio n. 1
0
 def _add(self, file, version):
     if not cache.update(CCFile(file, version)):
         return
     if [e for e in cfg.getExclude() if fnmatch(file, e)]:
         return
     toFile = path(join(GIT_DIR, file))
     mkdirs(toFile)
     removeFile(toFile)
     try:
         cc_exec(['get','-to', toFile, cc_file(file, version)])
     except:
         if len(file) < 200:
             raise
         debug("Ignoring %s as it may be related to https://github.com/charleso/git-cc/issues/9" % file)
     if not exists(toFile):
         git_exec(['checkout', 'HEAD', toFile])
     else:
         os.chmod(toFile, os.stat(toFile).st_mode | stat.S_IWRITE)
     git_exec(['add', '-f', file], errors=False)
Esempio n. 2
0
    def _add(self, file, version):
        if not cache.update(CCFile(file, version)):
            return
        if [e for e in cfg.getExclude() if fnmatch(file, e)]:
            return
        toFile = path(join(GIT_DIR, file))
        mkdirs(toFile)
        removeFile(toFile)
        try:
            cc_exec(['get','-to', toFile, cc_file(file, version)])
        except:
            if len(file) < 200:
                raise
            debug("Ignoring %s as it may be related to https://github.com/charleso/git-cc/issues/9" % file)
        if not exists(toFile):
            git_exec(['checkout', 'HEAD', toFile])
        else:
            os.chmod(toFile, os.stat(toFile).st_mode | stat.S_IWRITE)
        git_exec(['add', '-f', file], errors=False)

        maxRetries = 10
        retries = maxRetries
        while not isPristine() and retries > 0:
            printStatus()
            time.sleep(1)
            try:
                #git_exec(['add', '-f', file], errors=False)
                git_exec(['add', '-A'], errors=False)
            except:
                print('failed to add '+file)

            retries -= 1
            if retries == 0:
                raw_input("Last retry, do you want to intervene before I fail?")

        if not isPristine() and retries == 0:
            raise Exception('Cannot add ' + file + ' after ' + str(maxRetries) + ' tries')
Esempio n. 3
0
 def testLoad(self):
     dir = tempfile.mkdtemp()
     f = open(join(dir, cache.FILE), 'w')
     f.write(TEMP1)
     f.close()
     try:
         c = Cache(dir)
         self.assertFalse(c.isChild(CCFile('file.py', '/main/a/1')))
         self.assertFalse(c.isChild(CCFile('file.py', r'\main\a\1')))
         self.assertTrue(c.isChild(CCFile('file.py', '/main/a/b/c/1')))
         self.assertFalse(c.isChild(CCFile('file.py', '/main/a/c/1')))
         c.update(CCFile('file.py', '/main/a/b/2'))
         c.update(CCFile('file2.py', '/main/c/2'))
         c.write()
         f = open(join(dir, cache.FILE), 'r')
         try:
             self.assertEqual(TEMP1_EXPECTED, f.read())
         finally:
             f.close()
     finally:
         shutil.rmtree(dir)
Esempio n. 4
0
 def list(self):
     values = []
     for file, version in self.map.items():
         values.append(CCFile(file, version.full))
     return values