def _detect_submodules(verbose=False): if verbose: print("Detecting submodules", file=sys.stderr) (was_successful, output, errors) = call('git submodule status') if verbose: if not was_successful: print("No sumbodules detected", file=sys.stderr) else: print("Detected submodules", file=sys.stderr) return was_successful
def remote_url(): (was_successful, output, errors) = call("git remote show -n origin") if not was_successful: message = "Couldn't fetch remote info for origin: {}".format(errors) raise GitException(message) match = re.search(r'Fetch URL: ([^\s]+)', output) if match is None: message = "Couldn't find a fetch url for the current git repository" raise GitException(message) return match.group(1)
def _add_remote(remote_alias, remote_url, verbose=False): if verbose: message = "Adding remote for {} as {}".format(remote_url, remote_alias) print(message, file=sys.stderr) command = 'git config --get remote.{}.url'.format(remote_alias) (was_successful, output, errors) = call(command) if was_successful: current_url = output if current_url != remote_url: message = 'Remote already exists but refers to a different url' message += ' than target of {}'.format(remote_url) raise GitException(message) elif verbose: print("Remote already exists", file=sys.stderr) else: command_assert( 'git remote add %s %s' % (remote_alias, remote_url), "Couldn't add remote %s to %s" % (remote_alias, remote_url) )
def _branch_exists(target_branch): command = 'git show-ref refs/heads/{}'.format(target_branch) (success, output, errors) = call(command) return success
def is_git(directory=os.getcwd()): (success, output, errors) = call("git rev-parse --is-inside-work-tree") return success