def prompt_for_clone(): """ Present a GUI for cloning a repository. Returns the target directory and URL """ url, ok = qtutils.prompt(N_('Path or URL to clone (Env. $VARS okay)')) url = utils.expandpath(url) if not ok or not url: return None try: # Pick a suitable basename by parsing the URL newurl = url.replace('\\', '/').rstrip('/') default = newurl.rsplit('/', 1)[-1] if default == '.git': # The end of the URL is /.git, so assume it's a file path default = os.path.basename(os.path.dirname(newurl)) if default.endswith('.git'): # The URL points to a bare repo default = default[:-4] if url == '.': # The URL is the current repo default = os.path.basename(core.getcwd()) if not default: raise except: Interaction.information( N_('Error Cloning'), N_('Could not parse Git URL: "%s"') % url) Interaction.log(N_('Could not parse Git URL: "%s"') % url) return None # Prompt the user for a directory to use as the parent directory msg = N_('Select a parent directory for the new clone') dirname = qtutils.opendir_dialog(msg, main.model().getcwd()) if not dirname: return None count = 1 destdir = os.path.join(dirname, default) olddestdir = destdir if core.exists(destdir): # An existing path can be specified msg = (N_('"%s" already exists, cola will create a new directory') % destdir) Interaction.information(N_('Directory Exists'), msg) # Make sure the new destdir doesn't exist while core.exists(destdir): destdir = olddestdir + str(count) count += 1 return url, destdir
def add_bookmark(self): path, ok = qtutils.prompt(N_('Path to git repository'), title=N_('Enter Git Repository'), text=core.getcwd()) if not ok: return normpath = utils.expandpath(path) if git.is_git_worktree(normpath): self.settings.add_bookmark(normpath) self.settings.save() self.refresh() else: qtutils.critical(N_('Error'), N_('%s is not a Git repository.') % path)