コード例 #1
0
ファイル: server_git.py プロジェクト: loqutus/blah2
 def post(self, filename):
     print(filename + ' upload')
     print(DATA_DIR + filename)
     git.repo(DATA_DIR)
     with open(DATA_DIR + filename, 'wb') as f:
         f.write(self.request.body)
     git.add(DATA_DIR + filename)
     git.commit(filename + ' added')
コード例 #2
0
def _git_downloader(url, local, config, opts):
    rlp = os.path.relpath(path.host(local))
    us = url.split('?')
    repo = git.repo(local, opts, config.macros)
    if not repo.valid():
        log.notice('git: clone: %s -> %s' % (us[0], rlp))
        if not opts.dry_run():
            repo.clone(us[0], local)
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'branch':
            log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
            if not opts.dry_run():
                repo.checkout(_as[1])
        elif _as[0] == 'pull':
            log.notice('git: pull: %s' % (us[0]))
            if not opts.dry_run():
                repo.pull()
        elif _as[0] == 'fetch':
            log.notice('git: fetch: %s -> %s' % (us[0], rlp))
            if not opts.dry_run():
                repo.fetch()
        elif _as[0] == 'reset':
            arg = []
            if len(_as) > 1:
                arg = ['--%s' % (_as[1])]
            log.notice('git: reset: %s' % (us[0]))
            if not opts.dry_run():
                repo.reset(arg)
    return True
コード例 #3
0
    def update_status_button(self):
        try:
            (txt,status) = gitconnector.get_status()
            self.text.config(state=NORMAL)
            self.text.delete("0.0",END)
            self.text.insert(END, txt )
            self.text.config(state=DISABLED)
            if status & git.repo().REBASE:
                self.commit.config(text = "Continue Rebase")
            elif status & git.repo().APPLY_MAILBOX:
                self.commit.config(text = "Continue am")
            else:
                self.commit.config(text = "Commit")

        except Exception as e:
            tkMessageBox.showwarning("error",e)
コード例 #4
0
def is_nice_branch(branch=None):
    if not branch:
        branch = git.repo().current_branch()
    if branch:
        return re.search( nice_branch_regex, branch )
    else:
        return False
コード例 #5
0
 def sb_git(self):
     repo = git.repo(self.defaults.expand('%{_sbdir}'), self)
     if repo.valid():
         repo_valid = '1'
         repo_head = repo.head()
         repo_clean = not repo.dirty()
         repo_remotes = '%{nil}'
         remotes = repo.remotes()
         if 'origin' in remotes:
             repo_remotes = '%s/origin' % (remotes['origin']['url'])
             repo_id = repo_head
         if not repo_clean:
             repo_id += '-modified'
             repo_mail = repo.email()
     else:
         repo_valid = '0'
         repo_head = '%{nil}'
         repo_clean = '%{nil}'
         repo_remotes = '%{nil}'
         repo_id = 'no-repo'
         repo_mail = None
     self.defaults['_sbgit_valid'] = repo_valid
     self.defaults['_sbgit_head']  = repo_head
     self.defaults['_sbgit_clean'] = str(repo_clean)
     self.defaults['_sbgit_remotes'] = str(repo_remotes)
     self.defaults['_sbgit_id']    = repo_id
     if repo_mail is not None:
         self.defaults['_sbgit_mail'] = repo_mail
コード例 #6
0
def _git_downloader(url, local, config, opts):
    rlp = os.path.relpath(path.host(local))
    us = url.split('?')
    repo = git.repo(local, opts, config.macros)
    if not repo.valid():
        log.notice('git: clone: %s -> %s' % (us[0], rlp))
        if not opts.dry_run():
            repo.clone(us[0], local)
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'branch':
            log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
            if not opts.dry_run():
                repo.checkout(_as[1])
        elif _as[0] == 'pull':
            log.notice('git: pull: %s' % (us[0]))
            if not opts.dry_run():
                repo.pull()
        elif _as[0] == 'fetch':
            log.notice('git: fetch: %s -> %s' % (us[0], rlp))
            if not opts.dry_run():
                repo.fetch()
        elif _as[0] == 'reset':
            arg = []
            if len(_as) > 1:
                arg = ['--%s' % (_as[1])]
            log.notice('git: reset: %s' % (us[0]))
            if not opts.dry_run():
                repo.reset(arg)
    return True
コード例 #7
0
 def sb_git(self):
     repo = git.repo(self.defaults.expand('%{_sbdir}'), self)
     if repo.valid():
         repo_valid = '1'
         repo_head = repo.head()
         repo_clean = not repo.dirty()
         repo_remotes = '%{nil}'
         remotes = repo.remotes()
         if 'origin' in remotes:
             repo_remotes = '%s/origin' % (remotes['origin']['url'])
         repo_id = repo_head
         if not repo_clean:
             repo_id += '-modified'
         repo_mail = repo.email()
     else:
         repo_valid = '0'
         repo_head = '%{nil}'
         repo_clean = '%{nil}'
         repo_remotes = '%{nil}'
         repo_id = 'no-repo'
         repo_mail = None
     self.defaults['_sbgit_valid'] = repo_valid
     self.defaults['_sbgit_head'] = repo_head
     self.defaults['_sbgit_clean'] = str(repo_clean)
     self.defaults['_sbgit_remotes'] = str(repo_remotes)
     self.defaults['_sbgit_id'] = repo_id
     if repo_mail is not None:
         self.defaults['_sbgit_mail'] = repo_mail
コード例 #8
0
 def git_status(self):
     r = git.repo('.', self.opts, self.macros)
     if self.sanitize:
         self.formatter.git_status(r.valid(), r.dirty(), r.head(), None)
     else:
         self.formatter.git_status(r.valid(), r.dirty(), r.head(),
                                   r.remotes())
コード例 #9
0
def pull(explicit=False):
    """Pulls from remote_branch. free_branch, if it exists, is merged.
    nice_branch, if it exists, is rebased."""
    repo = git.repo()
    check_detached_head()
    saved_current_branch = repo.current_branch()

    commit()
    remote = remote_branch() 

    # fetch. Dont use pull because we anyway have to local branches two deal
    # with: free and nice
    repo.fetch()

    # merge (updated) remote branch into free branch
    free = free_branch() 
    if free:
        repo.checkout(free)
        repo.merge(remote)

    # rebase nice branch onto (updated) remote branch
    # todo: what if the above pull fails? Then the nice_branch is not rebased which leads to troubles later
    # todo: should be done automatically within pull if nice-branch is setuped correctly
    nice = nice_branch() 
    if nice:
        repo.checkout(nice)
        repo.rebase(remote)

    if explicit:
        repo.checkout(saved_current_branch)
コード例 #10
0
ファイル: cmd-server.py プロジェクト: poswald/bup
def send_index(conn, name):
    git.check_repo_or_die()
    assert(name.find('/') < 0)
    assert(name.endswith('.idx'))
    idx = git.PackIndex(git.repo('objects/pack/%s' % name))
    conn.write(struct.pack('!I', len(idx.map)))
    conn.write(idx.map)
    conn.ok()
コード例 #11
0
def commit_or_continue(explicit=False):
    repo = git.repo()
    status = repo.get_status2()
    if status & repo.REBASE:
        repo.rebase_continue()
    elif status & repo.APPLY_MAILBOX:
        repo.am_continue()
    else: # inclues NORMAL, MERGE, BISECT
        commit(explicit)
コード例 #12
0
ファイル: __init__.py プロジェクト: gmcintire/blueprint
 def iter(cls):
     """
     Yield the name of each blueprint.
     """
     if not os.path.isdir(git.repo()):
         return
     status, stdout = git.git('branch')
     for line in stdout.splitlines():
         yield line.strip()
コード例 #13
0
 def git_status(self):
     text = "RTEMS Source Builder Repository Status"
     if self.is_asciidoc():
         self.output("")
         self.output("'''")
         self.output("")
         self.output(".%s" % (text))
     else:
         self.output("-" * self.line_len)
         self.output("%s" % (text))
     repo = git.repo(".", self.opts, self.macros)
     repo_valid = repo.valid()
     if repo_valid:
         if self.is_asciidoc():
             self.output("*Remotes*:;;")
         else:
             self.output(" Remotes:")
         repo_remotes = repo.remotes()
         rc = 0
         for r in repo_remotes:
             rc += 1
             if "url" in repo_remotes[r]:
                 text = repo_remotes[r]["url"]
             else:
                 text = "no URL found"
             text = "%s: %s" % (r, text)
             if self.is_asciidoc():
                 self.output(". %s" % (text))
             else:
                 self.output("  %2d: %s" % (rc, text))
         if self.is_asciidoc():
             self.output("*Status*:;;")
         else:
             self.output(" Status:")
         if repo.clean():
             if self.is_asciidoc():
                 self.output("Clean")
             else:
                 self.output("  Clean")
         else:
             if self.is_asciidoc():
                 self.output("_Repository is dirty_")
             else:
                 self.output("  Repository is dirty")
         repo_head = repo.head()
         if self.is_asciidoc():
             self.output("*Head*:;;")
             self.output("Commit: %s" % (repo_head))
         else:
             self.output(" Head:")
             self.output("  Commit: %s" % (repo_head))
     else:
         self.output("_Not a valid GIT repository_")
     if self.is_asciidoc():
         self.output("")
         self.output("'''")
         self.output("")
コード例 #14
0
 def iter(cls):
     """
     Yield the name of each blueprint.
     """
     if not os.path.isdir(git.repo()):
         return
     status, stdout = git.git('branch')
     for line in stdout.splitlines():
         yield line.strip()
コード例 #15
0
 def destroy(cls, name):
     """
     Destroy the named blueprint.
     """
     if not os.path.isdir(git.repo()):
         raise NotFoundError(name)
     try:
         git.git('branch', '-D', name)
     except:
         raise NotFoundError(name)
コード例 #16
0
ファイル: __init__.py プロジェクト: gmcintire/blueprint
 def destroy(cls, name):
     """
     Destroy the named blueprint.
     """
     if not os.path.isdir(git.repo()):
         raise NotFoundError(name)
     try:
         git.git('branch', '-D', name)
     except:
         raise NotFoundError(name)
コード例 #17
0
def sanitize(explicit=False):

    # - check_detached_head()
    # - if nice branch is current propose to switch to free branch
    # - give help if nice branch didn't pass the verification test during commit

    repo = git.repo()
    status = repo.get_status2()
    txt = ""
    title = ""
    if status == repo.NORMAL:
        if is_nice_branch( repo.current_branch() ):
            title = "current branch is the nice branch"
            txt = "Your current branch is the nice branch. Normally the current branch should be the free branch. "
            if not repo.has_local_changes():
                txt += "Shall I switch to the free branch?"
                if tkMessageBox.askyesno(title, txt )!=0:
                    repo.checkout(free_branch(allow_create=True))
                return # !!!!!!!!!!!!!!!!!!!!!
            else:
                txt += "Since you have changes to your working tree and/or index I can't offer to switch to the free branch. You first have either to commit your changes or reset them."
        else:    
            title = "Status normal"
            txt = "Currently everything seems normal, you don't need help. "
    else:    
        howto_resolve = \
          "or you resolved them but have not yet committed the result\n\n" +\
          "Use your favorite git front end (TortoiseGit, SmartGit, ...) to resolve the conflicts.\n\n"
        after_resolve1 = "After you resolved all conflicts press the "
        after_resolve2 = "Then you probably need to press again the button you started with in the beginning (e.g. relase, pull, ...).\n\n"
        if status & repo.REBASE:
            title = "MERGING WITHIN REBASING"
            txt += "A git rebase is running and you have to resolve manually merge conflicts,\n"
            txt += howto_resolve
            txt += after_resolve1 + 'continue rebase button. ' + after_resolve2
            txt += "If you are stuck, use abort button to abort the rebase.\n\n"
        elif status & repo.APPLY_MAILBOX:
            title = "MERGING WITHIN APPLING MAILBOX"
            txt += "A git am (apply mailbox) is running and you have to resolve manually merge conflicts,\n"
            txt += howto_resolve
            txt += after_resolve1 + 'continue am button. ' + after_resolve2
            txt += "If you are stuck, use abort button to abort the am.\n\n"
        elif status & repo.MERGE:
            title = "MERGING"
            txt += "You have merge conflicts which you need to resolve manually,\n"
            txt += howto_resolve
            txt += after_resolve1 + 'commit button. ' + after_resolve2
            txt += "If you are stuck, use abort button to abort the merge.\n\n"
        if status & repo.BISECT:
            title += " BISECTING"
            txt += "You are in the middle of a bisect. Use you're favorite git "
            txt += "frontend to continue or end the bisect."
            
    tkMessageBox.showinfo(title, txt )
コード例 #18
0
ファイル: BotInfo.py プロジェクト: Roxedus/MornBot
    async def version(self, ctx):
        """Viser versjonen som båtten kjører på"""

        githash = repo('.').head.commit
        embed = discord.Embed(
            color=ctx.me.color,
            title='Git Commit Hash',
            description=
            f'[{githash}]({self.bot.misc["source_code"]}/commit/{githash})')
        await Defaults.set_footer(ctx, embed)
        await ctx.send(embed=embed)
コード例 #19
0
def unique_branch_name(base_name):
    """Returns a uniq branch name which starts with the given base"""
    repo = git.repo()
    branches = repo.branches()
    collision = True
    count = 1
    while collision:
        new_branch = base_name + "-bak-" +str(count)
        collision = next((x for x in branches if x == new_branch), False)
        count += 1
    return new_branch
コード例 #20
0
def update(response):
    """ updates the repo """
    if request.method == 'POST':
        repo_loc = "manvall.pythonanywhere.com/"
        repo = git.repo(repo_loc)
        origin = repo.remotes.origin
        
        origin.pull() 
        
        return HttpResponse("Code Updated in %s" %repo_loc)
    else:
        return HttpResponse("Couldn't updates the code on %s" %repo_loc)     
コード例 #21
0
def _load_git_version():
    global _git
    global _version_str
    repo = git.repo(_top())
    if repo.valid():
        head = repo.head()
        if repo.dirty():
            modified = ' modified'
        else:
            modified = ''
        _version_str = '%s (%s%s)' % (_version, head[0:12], modified)
        _git = True
    return _git
コード例 #22
0
def _load_git_version():
    global _git
    global _version_str
    repo = git.repo(_top())
    if repo.valid():
        head = repo.head()
        if repo.dirty():
            modified = ' modified'
        else:
            modified = ''
        _version_str = '%s (%s%s)' % (_version, head[0:12], modified)
        _git = True
    return _git
コード例 #23
0
def abort(explicit=False):
    # maybe that button can be removed by putting its functionality into 'help (me out)'
    # or leave the abort button, and place the same functionality also in help me out
    repo = git.repo()
    status = repo.get_status2()
    if status == repo.NORMAL:
        tkMessageBox.showinfo("", "No merge, rebase, apply-mailbox, or bisect to abort.")
    else:    
        if tkMessageBox.askokcancel("Confirm abort","Aborting means you loose your changes to your working tree and your index. Working tree and index will be reset to the commit you started the merge/rebase with.")==0:
            raise Exception("Aborted by user")
        if status & repo.MERGE:
            repo.merge_abort()
        elif status & repo.REBASE:
            repo.rebase_abort()
        elif status & repo.APPLY_MAILBOX:
            repo.am_abort()
        elif status & repo.BISECT:
            repo.bisect_abort();
コード例 #24
0
def get_status():
    # todo: emphasize when in merge/rebase conflict
    # todo: use same color for same branch names everywhere, also in graph log
    context = 2
    repo = git.repo()
    txt = ""
    status = repo.get_status2()
    
    # todo: most gitconnector commands should bark if status is not normal
    if status != repo.NORMAL:
        # todo: being in a rebase/am does not necessarily mean that we have merge 
        # conflicts. that need to be an extra flag
        txt += "!!! "
        if status & repo.REBASE:
            txt += "Within a rebase. "
        elif status & repo.APPLY_MAILBOX:
            txt += "Within an apply mailbox. "
        elif status & repo.MERGE:
            txt += "Within a merge. "
        if status & repo.BISECT:
            txt += "Within a bisect. "            
        txt += "(Menu Help/Sanitize has more info)"    
        txt += " !!!\n\n"
    txt += "--- current branch's friends ---\n"
    txt += "current branch         : " + abbrev_ref(repo.current_branch(str_if_none=True)) + "\n"
    txt += "free branch            : " + abbrev_ref(free_branch(str_if_none=True)) + "\n"   # x commits nice-able
    txt += "nice branch            : " + abbrev_ref(nice_branch(str_if_none=True)) + "\n"   # x commits pushable into remote
    txt += "remote tracking branch : " + abbrev_ref(remote_branch(str_if_none=True)) + "\n" # x commits ahead
    txt += "\n"
    txt += "log extract:\n"
    txt += repo.get_log_graph(remote_branch(),nice_branch(),free_branch(),context)
    # txt += "\nnice-able commits:\n"
    # txt += repo.
    # txt += "\npushable nice commits:\n"
    # txt += repo.

    # comes last because it can be arbitrarily long
    txt += "\n"
    txt += "--- status of index and working tree ---\n" 
    txt += repo.get_status()
    txt += "\n"
    txt += "\n"
    return txt, status
コード例 #25
0
def free_branch(allow_create=False, str_if_none=False):
    """Returns the free branch associated with the current branch."""
    repo = git.repo()
    current_branch = repo.current_branch()
    result = None
    if current_branch:
        if not is_nice_branch(current_branch):
            result = current_branch
        else:
            proposed_branch = re.sub( nice_branch_regex, "", current_branch)
            if not repo.has_branch(proposed_branch):
                if allow_create:
                    result = proposed_branch
                    repo.create_branch(proposed_branch,startpoint=remote_branch())
            else:
                result = proposed_branch
    if not result and str_if_none:
        result = no_branch
    return result
コード例 #26
0
def nice_branch(allow_create=False, str_if_none=False):
    """Analogous to free_branch"""
    repo = git.repo()
    current_branch = repo.current_branch()
    result = None
    if current_branch:
        if is_nice_branch(current_branch):
            result = current_branch
        else:
            proposed_branch = current_branch + "-nice"
            if not repo.has_branch(proposed_branch):
                if allow_create:
                    result = proposed_branch
                    repo.create_branch(proposed_branch,startpoint=remote_branch())
            else:
                result = proposed_branch
    if not result and str_if_none:
        result = no_branch
    return result
コード例 #27
0
def _git_downloader(url, local, config, opts):
    rlp = os.path.relpath(path.host(local))
    us = url.split('?')
    repo = git.repo(local, opts, config.macros)
    if not repo.valid():
        log.notice('git: clone: %s -> %s' % (us[0], rlp))
        if not opts.dry_run():
            repo.clone(us[0], local)
    else:
        repo.clean(['-f', '-d'])
        repo.reset('--hard')
        repo.checkout('master')
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'branch' or _as[0] == 'checkout':
            if len(_as) != 2:
                raise error.general('invalid git branch/checkout: %s' % (_as))
            log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
            if not opts.dry_run():
                repo.checkout(_as[1])
        elif _as[0] == 'pull':
            log.notice('git: pull: %s' % (us[0]))
            if not opts.dry_run():
                repo.pull()
        elif _as[0] == 'submodule':
            if len(_as) != 2:
                raise error.general('invalid git submodule: %s' % (_as))
            log.notice('git: submodule: %s <= %s' % (us[0], _as[1]))
            if not opts.dry_run():
                repo.submodule(_as[1])
        elif _as[0] == 'fetch':
            log.notice('git: fetch: %s -> %s' % (us[0], rlp))
            if not opts.dry_run():
                repo.fetch()
        elif _as[0] == 'reset':
            arg = []
            if len(_as) > 1:
                arg = ['--%s' % (_as[1])]
            log.notice('git: reset: %s' % (us[0]))
            if not opts.dry_run():
                repo.reset(arg)
    return True
コード例 #28
0
def _git_downloader(url, local, config, opts):
    rlp = os.path.relpath(path.host(local))
    us = url.split("?")
    repo = git.repo(local, opts, config.macros)
    if not repo.valid():
        log.notice("git: clone: %s -> %s" % (us[0], rlp))
        if not opts.dry_run():
            repo.clone(us[0], local)
    else:
        repo.clean(["-f", "-d"])
        repo.reset("--hard")
        repo.checkout("master")
    for a in us[1:]:
        _as = a.split("=")
        if _as[0] == "branch" or _as[0] == "checkout":
            if len(_as) != 2:
                raise error.general("invalid git branch/checkout: %s" % (_as))
            log.notice("git: checkout: %s => %s" % (us[0], _as[1]))
            if not opts.dry_run():
                repo.checkout(_as[1])
        elif _as[0] == "pull":
            log.notice("git: pull: %s" % (us[0]))
            if not opts.dry_run():
                repo.pull()
        elif _as[0] == "submodule":
            if len(_as) != 2:
                raise error.general("invalid git submodule: %s" % (_as))
            log.notice("git: submodule: %s <= %s" % (us[0], _as[1]))
            if not opts.dry_run():
                repo.submodule(_as[1])
        elif _as[0] == "fetch":
            log.notice("git: fetch: %s -> %s" % (us[0], rlp))
            if not opts.dry_run():
                repo.fetch()
        elif _as[0] == "reset":
            arg = []
            if len(_as) > 1:
                arg = ["--%s" % (_as[1])]
            log.notice("git: reset: %s" % (us[0]))
            if not opts.dry_run():
                repo.reset(arg)
    return True
コード例 #29
0
def _git_downloader(url, local, config, opts):
    rlp = os.path.relpath(path.host(local))
    us = url.split('?')
    repo = git.repo(local, opts, config.macros)
    if not repo.valid():
        log.notice('git: clone: %s -> %s' % (us[0], rlp))
        if not opts.dry_run():
            repo.clone(us[0], local)
    else:
        repo.clean(['-f', '-d'])
        repo.reset('--hard')
        repo.checkout('master')
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'branch' or _as[0] == 'checkout':
            if len(_as) != 2:
                raise error.general('invalid git branch/checkout: %s' % (_as))
            log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
            if not opts.dry_run():
                repo.checkout(_as[1])
        elif _as[0] == 'pull':
            log.notice('git: pull: %s' % (us[0]))
            if not opts.dry_run():
                repo.pull()
        elif _as[0] == 'submodule':
            if len(_as) != 2:
                raise error.general('invalid git submodule: %s' % (_as))
            log.notice('git: submodule: %s <= %s' % (us[0], _as[1]))
            if not opts.dry_run():
                repo.submodule(_as[1])
        elif _as[0] == 'fetch':
            log.notice('git: fetch: %s -> %s' % (us[0], rlp))
            if not opts.dry_run():
                repo.fetch()
        elif _as[0] == 'reset':
            arg = []
            if len(_as) > 1:
                arg = ['--%s' % (_as[1])]
            log.notice('git: reset: %s' % (us[0]))
            if not opts.dry_run():
                repo.reset(arg)
    return True
コード例 #30
0
ファイル: client.py プロジェクト: dcoombs/bup
    def sync_indexes_del(self):
        self.check_busy()
        conn = self.conn
        conn.write("list-indexes\n")
        packdir = git.repo("objects/pack")
        all = {}
        needed = {}
        for line in linereader(conn):
            if not line:
                break
            all[line] = 1
            assert line.find("/") < 0
            if not os.path.exists(os.path.join(self.cachedir, line)):
                needed[line] = 1
        self.check_ok()

        mkdirp(self.cachedir)
        for f in os.listdir(self.cachedir):
            if f.endswith(".idx") and not f in all:
                log("pruning old index: %r\n" % f)
                os.unlink(os.path.join(self.cachedir, f))
コード例 #31
0
def commit(explicit=False, ask_when_nice=True):
    # if something is to commit, ask for message can be free if there are
    # already other commits, must be guideline conform if its the first

    # todo: tell user the user something like git status and ask what he wants to do
    # todo: if untracked files, add them
    # todo: inform user that now with DVCS, he could check in locally. But dont do it
    #       if he changed only a few files, or if preferences turn off that msg.
    repo = git.repo()
    if explicit:
        check_detached_head()
        
    has_changes = repo.has_local_changes()
    allow_empty = False
    if not has_changes and explicit:
        msg = "You don't have any local changes to commit. " +\
            "Do you want to force creating an empty commit?"
        if tkMessageBox.askokcancel("",msg)==0:
            raise Exception("Aborted by User")
        allow_empty = True
        
    if has_changes or allow_empty:
        if is_nice_branch() and ask_when_nice:
            if explicit:
                pre_msg = "You"
            else:
                pre_msg = "You have local changes which need to be commited first. But you"
            nice = abbrev_ref(nice_branch(str_if_none=True))
            free = abbrev_ref(free_branch(str_if_none=True))
            msg = pre_msg + " are on currently on a nice branch (" + nice + "). " +\
                  "Normally you want commit to the free branch (" + free + ") " +\
                  "and then use 'make branch nice'. " +\
                  "Continue committing to the nice branch?"
            if tkMessageBox.askyesno("", msg)==0:
                raise Exception("Aborted by user")
        elif not explicit:
            msg = "You have local changes which need to be commited first. I will commit them now."
            if tkMessageBox.askokcancel("", msg)==0:
                raise Exception("Aborted by user")
        repo.commit(allow_empty)
コード例 #32
0
ファイル: client.py プロジェクト: poswald/bup
    def sync_indexes(self):
        self.check_busy()
        conn = self.conn
        conn.write('list-indexes\n')
        packdir = git.repo('objects/pack')
        mkdirp(self.cachedir)
        all = {}
        needed = {}
        for line in linereader(conn):
            if not line:
                break
            all[line] = 1
            assert(line.find('/') < 0)
            if not os.path.exists(os.path.join(self.cachedir, line)):
                needed[line] = 1
        conn.check_ok()

        for f in os.listdir(self.cachedir):
            if f.endswith('.idx') and not f in all:
                log('pruning old index: %r\n' % f)
                os.unlink(os.path.join(self.cachedir, f))

        # FIXME this should be pipelined: request multiple indexes at a time, or
        # we waste lots of network turnarounds.
        for name in needed.keys():
            log('requesting %r\n' % name)
            conn.write('send-index %s\n' % name)
            n = struct.unpack('!I', conn.read(4))[0]
            assert(n)
            log('   expect %d bytes\n' % n)
            fn = os.path.join(self.cachedir, name)
            f = open(fn + '.tmp', 'w')
            for b in chunkyreader(conn, n):
                f.write(b)
            conn.check_ok()
            f.close()
            os.rename(fn + '.tmp', fn)

        self._indexes_synced = 1
コード例 #33
0
ファイル: options.py プロジェクト: tokencolour/rtems-tools
 def local_git(self):
     repo = git.repo(self.defaults.expand('%{_rtdir}'), self)
     if repo.valid():
         repo_valid = '1'
         repo_head = repo.head()
         repo_clean = not repo.dirty()
         repo_id = repo_head
         if not repo_clean:
             repo_id += '-modified'
         repo_mail = repo.email()
     else:
         repo_valid = '0'
         repo_head = '%{nil}'
         repo_clean = '%{nil}'
         repo_id = 'no-repo'
         repo_mail = None
     self.defaults['_local_git_valid'] = repo_valid
     self.defaults['_local_git_head'] = repo_head
     self.defaults['_local_git_clean'] = str(repo_clean)
     self.defaults['_local_git_id'] = repo_id
     if repo_mail is not None:
         self.defaults['_localgit_mail'] = repo_mail
コード例 #34
0
ファイル: options.py プロジェクト: RTEMS/rtems-tools
 def local_git(self):
     repo = git.repo(self.defaults.expand('%{_rtdir}'), self)
     if repo.valid():
         repo_valid = '1'
         repo_head = repo.head()
         repo_clean = not repo.dirty()
         repo_id = repo_head
         if not repo_clean:
             repo_id += '-modified'
         repo_mail = repo.email()
     else:
         repo_valid = '0'
         repo_head = '%{nil}'
         repo_clean = '%{nil}'
         repo_id = 'no-repo'
         repo_mail = None
     self.defaults['_local_git_valid'] = repo_valid
     self.defaults['_local_git_head']  = repo_head
     self.defaults['_local_git_clean'] = str(repo_clean)
     self.defaults['_local_git_id']    = repo_id
     if repo_mail is not None:
         self.defaults['_localgit_mail'] = repo_mail
コード例 #35
0
ファイル: client.py プロジェクト: dcoombs/bup
    def __init__(self, remote, create=False):
        self._busy = None
        self.p = None
        self.conn = None
        rs = remote.split(":", 1)
        nicedir = os.path.split(os.path.abspath(sys.argv[0]))[0]
        nicedir = re.sub(r":", "_", nicedir)
        if len(rs) == 1:
            (host, dir) = ("NONE", remote)

            def fixenv():
                os.environ["PATH"] = ":".join([nicedir, os.environ.get("PATH", "")])

            argv = ["bup", "server"]
        else:
            (host, dir) = rs
            fixenv = None
            # WARNING: shell quoting security holes are possible here, so we
            # have to be super careful.  We have to use 'sh -c' because
            # csh-derived shells can't handle PATH= notation.  We can't
            # set PATH in advance, because ssh probably replaces it.  We
            # can't exec *safely* using argv, because *both* ssh and 'sh -c'
            # allow shellquoting.  So we end up having to double-shellquote
            # stuff here.
            escapedir = re.sub(r"([^\w/])", r"\\\\\\\1", nicedir)
            cmd = (
                r"""
                       sh -c PATH=%s:'$PATH bup server'
                   """
                % escapedir
            )
            argv = ["ssh", host, "--", cmd.strip()]
            # log('argv is: %r\n' % argv)
        (self.host, self.dir) = (host, dir)
        self.cachedir = git.repo("index-cache/%s" % re.sub(r"[^@\w]", "_", "%s:%s" % (host, dir)))
        try:
            self.p = p = Popen(argv, stdin=PIPE, stdout=PIPE, preexec_fn=fixenv)
        except OSError, e:
            raise ClientError, "exec %r: %s" % (argv[0], e), sys.exc_info()[2]
コード例 #36
0
ファイル: client.py プロジェクト: poswald/bup
 def __init__(self, remote, create=False):
     self._busy = None
     self._indexes_synced = 0
     rs = remote.split(':', 1)
     if len(rs) == 1:
         (host, dir) = ('NONE', remote)
         argv = ['bup', 'server']
     else:
         (host, dir) = rs
         argv = ['ssh', host, '--', 'bup', 'server']
     (self.host, self.dir) = (host, dir)
     self.cachedir = git.repo('index-cache/%s'
                              % re.sub(r'[^@:\w]', '_', 
                                       "%s:%s" % (host, dir)))
     self.p = p = Popen(argv, stdin=PIPE, stdout=PIPE)
     self.conn = conn = Conn(p.stdout, p.stdin)
     if dir:
         dir = re.sub(r'[\r\n]', ' ', dir)
         if create:
             conn.write('init-dir %s\n' % dir)
         else:
             conn.write('set-dir %s\n' % dir)
         conn.check_ok()
コード例 #37
0
def _load_git_version():
    global _version
    global _revision
    global _git
    global _version_str
    global _is_loaded

    if not _is_loaded:
        repo = git.repo(_top())
        if repo.valid():
            head = repo.head()
            if repo.dirty():
                modified = 'modified'
                revision_sep = '-'
                sep = ' '
            else:
                modified = ''
                revision_sep = ''
                sep = ''
            _revision = '%s%s%s' % (head[0:12], revision_sep, modified)
            _version_str = '%s (%s%s%s)' % (_version, head[0:12], sep, modified)
            _git = True
            _is_loaded = True
    return _git
コード例 #38
0
import numpy as np
import git

another_test = git.repo("analytics/")
new_change = 1
コード例 #39
0
def clear_midxes(dir=None):
    dir = dir or git.repo('objects/pack')
    for midx in glob.glob(os.path.join(dir, '*.midx')):
        os.unlink(midx)
コード例 #40
0
def _git_downloader(url, local, config, opts):
    repo = git.repo(local, opts, config.macros)
    rlp = os.path.relpath(path.host(local))
    us = url.split('?')
    #
    # Handle the various git protocols.
    #
    # remove 'git' from 'git://xxxx/xxxx?protocol=...'
    #
    url_base = us[0][len('git'):]
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'protocol':
            if len(_as) != 2:
                raise error.general('invalid git protocol option: %s' % (_as))
            if _as[1] == 'none':
                # remove the rest of the protocol header leaving nothing.
                us[0] = url_base[len('://'):]
            else:
                if _as[1] not in ['ssh', 'git', 'http', 'https', 'ftp', 'ftps', 'rsync']:
                    raise error.general('unknown git protocol: %s' % (_as[1]))
                us[0] = _as[1] + url_base
    if not repo.valid():
        log.notice('git: clone: %s -> %s' % (us[0], rlp))
        if _do_download(opts):
            repo.clone(us[0], local)
    else:
        repo.clean(['-f', '-d'])
        repo.reset('--hard')
        repo.checkout('master')
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'branch' or _as[0] == 'checkout':
            if len(_as) != 2:
                raise error.general('invalid git branch/checkout: %s' % (_as))
            log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
            if _do_download(opts):
                repo.checkout(_as[1])
        elif _as[0] == 'submodule':
            if len(_as) != 2:
                raise error.general('invalid git submodule: %s' % (_as))
            log.notice('git: submodule: %s <= %s' % (us[0], _as[1]))
            if _do_download(opts):
                repo.submodule(_as[1])
        elif _as[0] == 'fetch':
            log.notice('git: fetch: %s -> %s' % (us[0], rlp))
            if _do_download(opts):
                repo.fetch()
        elif _as[0] == 'merge':
            log.notice('git: merge: %s' % (us[0]))
            if _do_download(opts):
                repo.merge()
        elif _as[0] == 'pull':
            log.notice('git: pull: %s' % (us[0]))
            if _do_download(opts):
                repo.pull()
        elif _as[0] == 'reset':
            arg = []
            if len(_as) > 1:
                arg = ['--%s' % (_as[1])]
            log.notice('git: reset: %s' % (us[0]))
            if _do_download(opts):
                repo.reset(arg)
        elif _as[0] == 'protocol':
            pass
        else:
            raise error.general('invalid git option: %s' % (_as))
    return True
コード例 #41
0
def _git_downloader(url, local, config, opts):
    repo = git.repo(local, opts, config.macros)
    rlp = os.path.relpath(path.host(local))
    us = url.split('?')
    #
    # Handle the various git protocols.
    #
    # remove 'git' from 'git://xxxx/xxxx?protocol=...'
    #
    url_base = us[0][len('git'):]
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'protocol':
            if len(_as) != 2:
                raise error.general('invalid git protocol option: %s' % (_as))
            if _as[1] == 'none':
                # remove the rest of the protocol header leaving nothing.
                us[0] = url_base[len('://'):]
            else:
                if _as[1] not in ['ssh', 'git', 'http', 'https', 'ftp', 'ftps', 'rsync']:
                    raise error.general('unknown git protocol: %s' % (_as[1]))
                us[0] = _as[1] + url_base
    if not repo.valid():
        log.notice('git: clone: %s -> %s' % (us[0], rlp))
        if _do_download(opts):
            repo.clone(us[0], local)
    else:
        repo.clean(['-f', '-d'])
        repo.reset('--hard')
        repo.checkout('master')
    for a in us[1:]:
        _as = a.split('=')
        if _as[0] == 'branch' or _as[0] == 'checkout':
            if len(_as) != 2:
                raise error.general('invalid git branch/checkout: %s' % (_as))
            log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
            if _do_download(opts):
                repo.checkout(_as[1])
        elif _as[0] == 'submodule':
            if len(_as) != 2:
                raise error.general('invalid git submodule: %s' % (_as))
            log.notice('git: submodule: %s <= %s' % (us[0], _as[1]))
            if _do_download(opts):
                repo.submodule(_as[1])
        elif _as[0] == 'fetch':
            log.notice('git: fetch: %s -> %s' % (us[0], rlp))
            if _do_download(opts):
                repo.fetch()
        elif _as[0] == 'merge':
            log.notice('git: merge: %s' % (us[0]))
            if _do_download(opts):
                repo.merge()
        elif _as[0] == 'pull':
            log.notice('git: pull: %s' % (us[0]))
            if _do_download(opts):
                repo.pull()
        elif _as[0] == 'reset':
            arg = []
            if len(_as) > 1:
                arg = ['--%s' % (_as[1])]
            log.notice('git: reset: %s' % (us[0]))
            if _do_download(opts):
                repo.reset(arg)
        elif _as[0] == 'protocol':
            pass
        else:
            raise error.general('invalid git option: %s' % (_as))
    return True
コード例 #42
0
ファイル: cmd-save.py プロジェクト: dcoombs/bup
shalists = [[]]

def _push(part):
    assert(part)
    parts.append(part)
    shalists.append([])

def _pop():
    assert(len(parts) > 1)
    part = parts.pop()
    shalist = shalists.pop()
    tree = w.new_tree(shalist)
    shalists[-1].append(('40000', part, tree))


for (transname,ent) in index.Reader(git.repo('bupindex')).filter(extra):
    (dir, file) = os.path.split(ent.name)
    exists = (ent.flags & index.IX_EXISTS)
    hashvalid = (ent.flags & index.IX_HASHVALID) and w.exists(ent.sha)
    if opt.verbose:
        if not exists:
            status = 'D'
        elif not hashvalid:
            if ent.sha == index.EMPTY_SHA:
                status = 'A'
            else:
                status = 'M'
        else:
            status = ' '
        if opt.verbose >= 2 or (status in ['A','M'] 
                                and not stat.S_ISDIR(ent.mode)):
コード例 #43
0
ファイル: cmd-server.py プロジェクト: poswald/bup
def list_indexes(conn, junk):
    git.check_repo_or_die()
    for f in os.listdir(git.repo('objects/pack')):
        if f.endswith('.idx'):
            conn.write('%s\n' % f)
    conn.ok()
コード例 #44
0
 def git_status(self):
     r = git.repo('.', self.opts, self.macros)
     self.formatter.git_status(r.valid(), r.dirty(), r.head(), r.remotes())
コード例 #45
0
ファイル: cmd-index.py プロジェクト: dcoombs/bup
fake-valid    mark all index entries as up-to-date even if they aren't
f,indexfile=  the name of the index file (default 'index')
v,verbose  increase log output (can be used more than once)
"""
o = options.Options('bup index', optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])

if not (opt.modified or opt['print'] or opt.status or opt.update):
    log('bup index: you must supply one or more of -p, -s, -m, or -u\n')
    o.usage()
if opt.fake_valid and not opt.update:
    log('bup index: --fake-valid is meaningless without -u\n')
    o.usage()

git.check_repo_or_die()
indexfile = opt.indexfile or git.repo('bupindex')

paths = index.reduce_paths(extra)

if opt.update:
    if not paths:
        log('bup index: update (-u) requested but no paths given\n')
        o.usage()
    for (rp, path) in paths:
        update_index(rp)

if opt['print'] or opt.status or opt.modified:
    for (name, ent) in index.Reader(indexfile).filter(extra or ['']):
        if opt.modified and (ent.flags & index.IX_HASHVALID
                             or stat.S_ISDIR(ent.mode)):
            continue