示例#1
0
def setRemoteURL(remote, url, path, logger):
  """
  Sets a git remote's url.

  :param str remote: Which git remote to alter

  :param str url: What to set the url to

  :param str path: git directory to reset

  :param logger: An initialized logger object

  :raises CommandFailedError: if git set-url fails
  """
  assert logger
  assert isinstance(path, basestring), (
    "path must be a string, but is %r" % path)
  assert isinstance(remote, basestring), (
    "remote must be a string, but is %r" % (remote))
  assert isinstance(url, basestring), "url must be a string, but is %r" % (url)

  logger.debug("* Setting url for %s to %s in %s", remote, url, path)
  with changeToWorkingDir(path):
    return executeCommand(command="git set-url %s %s" % (remote, url),
                          logger=logger)
示例#2
0
def getShaFromRemoteBranch(gitRemoteRepo, gitRemoteBranch, logger):
    """
  Get the actual SHA of the current HEAD of a remote repo / branch.

  :param str gitRemoteRepo: The URL of the remote repo,
    e.g., [email protected]:numenta/nupic.git
  :param str gitRemoteBranch: The name of the remote branch, e.g., master

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :returns: A `String` representing the SHA

  :rtype: str
  """
    command = ("git", "ls-remote", gitRemoteRepo)
    shaList = executeCommand(command=command, logger=logger)
    if gitRemoteBranch == "master":
        return shaList.split("\t")[0]
    else:
        formattedBranchName = "refs/heads/%s" % gitRemoteBranch
        for refShaPair in shaList.split("\n"):
            pair = refShaPair.split()
            if pair[1] == formattedBranchName:
                return pair[0]

    raise CommandFailedError(
        "Could not find the specified branch %s on %s" % gitRemoteBranch,
        gitRemoteRepo)
示例#3
0
def reset(sha, logger, **kwargs):
  """
  Resets the repository to a optional SHA. Optional argument for --hard

  :param logger: logger for additional debug info

  :param bool hard: Boolean. Defaults to False. If true, resets the index and
    working tree. Any changes to tracked files in the working tree since
    <commit> are discarded.

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :returns: The exit code

  :rtype: int
  """
  assert logger
  validKwargs = {"hard"}
  checkKwargs(kwargs=kwargs, validKwargs=validKwargs)
  command = ["git", "reset"]
  if checkIfOptionSet("hard", kwargs):
    command.append("--hard")
  command.append(sha)
  return executeCommand(command=command, logger=logger)
示例#4
0
def getShaFromRemoteBranch(gitRemoteRepo, gitRemoteBranch, logger):
  """
  Get the actual SHA of the current HEAD of a remote repo / branch.

  :param str gitRemoteRepo: The URL of the remote repo,
    e.g., [email protected]:numenta/nupic.git
  :param str gitRemoteBranch: The name of the remote branch, e.g., master

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :returns: A `String` representing the SHA

  :rtype: str
  """
  command = ("git", "ls-remote", gitRemoteRepo)
  shaList = executeCommand(command=command, logger=logger)
  if gitRemoteBranch == "master":
    return shaList.split("\t")[0]
  else:
    formattedBranchName = "refs/heads/%s" % gitRemoteBranch
    for refShaPair in shaList.split("\n"):
      pair = refShaPair.split()
      if pair[1] == formattedBranchName:
        return pair[0]

  raise CommandFailedError("Could not find the specified branch %s on %s" %
                           gitRemoteBranch, gitRemoteRepo)
示例#5
0
def pull(logger, arguments=None):
  """
  Do a git pull, with optional parameters.

  Example usage:

    pull(arguments=["origin", "next"])
    pull(arguments=["origin", "next", "--ff-only"])
    pull(arguments=["[email protected]:username/repo.git", "next"])

  :param str arguments: Any extra arguments you want to pass to git pull
  :param logger: An initialized logger object
  """
  if arguments:
    assert (isinstance(arguments, basestring) or
            isinstance(arguments, tuple) or
            isinstance(arguments, list)), (
              "arguments must be a string or list, but is %r" % arguments)
  assert logger
  gitCommand = ["git", "pull"]
  if arguments:
    if isinstance(arguments, list) or isinstance(arguments, tuple):
      gitCommand.extend(arguments)
    if isinstance(arguments, basestring):
      arguments.extend(str.split(arguments))
  return executeCommand(command=gitCommand, logger=logger)
示例#6
0
文件: git.py 项目: bopopescu/what
def getShaFromRemoteBranch(YOMPRemoteRepo, YOMPRemoteBranch):
    """
  Get the actual SHA of the current HEAD of a remote repo / branch.

  @param YOMPRemoteRepo: The URL of the remote repo,
    e.g., [email protected]:numenta/nupic.YOMP
  @param YOMPRemoteBranch: The name of the remote branch, e.g., master

  @raises:

  @return: A `String` representing the SHA
  @rtype: String
  """
    shaList = executeCommand("YOMP ls-remote %s" % YOMPRemoteRepo)
    if YOMPRemoteBranch == "master":
        return shaList.split("\t")[0]
    else:
        formattedBranchName = "refs/heads/%s" % YOMPRemoteBranch
        for refShaPair in shaList.split("\n"):
            pair = refShaPair.split()
            if pair[1] == formattedBranchName:
                return pair[0]

    raise CommandFailedError(
        "Could not find the specified branch %s on %s" % YOMPRemoteBranch,
        YOMPRemoteRepo)
示例#7
0
文件: git.py 项目: bopopescu/what
def checkout(pathspec, **kwargs):
    """
  Switches to a given commit-ish

  @param pathspec: The name of the branch (commit-ish)

  @param kwargs:

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The text blob output of YOMP checkout
  @rtype: string
  """
    command = "YOMP checkout"
    if checkIfOptionSet("new", **kwargs):
        command += " -b "
    elif checkIfOptionSet("orphan", **kwargs):
        command += " --orphan"
    elif checkIfOptionSet("theirs", **kwargs):
        command += " --theirs"

    command += " %s" % pathspec
    return executeCommand(command)
示例#8
0
def reset(sha, logger, **kwargs):
    """
  Resets the repository to a optional SHA. Optional argument for --hard

  :param logger: logger for additional debug info

  :param bool hard: Boolean. Defaults to False. If true, resets the index and
    working tree. Any changes to tracked files in the working tree since
    <commit> are discarded.

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :returns: The exit code

  :rtype: int
  """
    assert logger
    validKwargs = {"hard"}
    checkKwargs(kwargs=kwargs, validKwargs=validKwargs)
    command = ["git", "reset"]
    if checkIfOptionSet("hard", kwargs):
        command.append("--hard")
    command.append(sha)
    return executeCommand(command=command, logger=logger)
示例#9
0
文件: git.py 项目: darian19/what
def checkout(pathspec, **kwargs):
  """
  Switches to a given commit-ish

  @param pathspec: The name of the branch (commit-ish)

  @param kwargs:

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The text blob output of YOMP checkout
  @rtype: string
  """
  command = "YOMP checkout"
  if checkIfOptionSet("new", **kwargs):
    command += " -b "
  elif checkIfOptionSet("orphan", **kwargs):
    command += " --orphan"
  elif checkIfOptionSet("theirs", **kwargs):
    command += " --theirs"

  command += " %s" % pathspec
  return executeCommand(command)
示例#10
0
文件: git.py 项目: darian19/what
def getShaFromRemoteBranch(YOMPRemoteRepo, YOMPRemoteBranch):
  """
  Get the actual SHA of the current HEAD of a remote repo / branch.

  @param YOMPRemoteRepo: The URL of the remote repo,
    e.g., [email protected]:numenta/nupic.YOMP
  @param YOMPRemoteBranch: The name of the remote branch, e.g., master

  @raises:

  @return: A `String` representing the SHA
  @rtype: String
  """
  shaList = executeCommand("YOMP ls-remote %s" % YOMPRemoteRepo)
  if YOMPRemoteBranch == "master":
    return shaList.split("\t")[0]
  else:
    formattedBranchName = "refs/heads/%s" % YOMPRemoteBranch
    for refShaPair in shaList.split("\n"):
      pair = refShaPair.split()
      if pair[1] == formattedBranchName:
        return pair[0]

  raise CommandFailedError("Could not find the specified branch %s on %s" %
                           YOMPRemoteBranch, YOMPRemoteRepo)
示例#11
0
def setRemoteURL(remote, url, path, logger):
    """
  Sets a git remote's url.

  :param str remote: Which git remote to alter

  :param str url: What to set the url to

  :param str path: git directory to reset

  :param logger: An initialized logger object

  :raises CommandFailedError: if git set-url fails
  """
    assert logger
    assert isinstance(path,
                      basestring), ("path must be a string, but is %r" % path)
    assert isinstance(
        remote, basestring), ("remote must be a string, but is %r" % (remote))
    assert isinstance(url,
                      basestring), "url must be a string, but is %r" % (url)

    logger.debug("* Setting url for %s to %s in %s", remote, url, path)
    with changeToWorkingDir(path):
        return executeCommand(command="git set-url %s %s" % (remote, url),
                              logger=logger)
示例#12
0
def clean(path, arguments, logger):
    """
  Changes to path, then runs git clean.

  :param str path: git directory to clean

  :param str arguments: str containing optional extra command line arguments
    for git clean, as you would type them on the command line. If you wanted
    to do `git clean -fd`, you'd set arguments to "-fd".

  :param logger: An initialized logger object

  :raises CommandFailedError: if git clean fails
  """
    assert logger
    assert isinstance(arguments,
                      basestring), ("arguments must be a string, but is %r" %
                                    arguments)
    assert isinstance(path,
                      basestring), "path must be a string, but is %r" % path

    command = ["git", "clean"]
    if arguments:
        command.append(arguments)
    logger.debug("* Running %s in %s", command, path)
    with changeToWorkingDir(path):
        return executeCommand(command=command, logger=logger)
示例#13
0
def clean(path, arguments, logger):
  """
  Changes to path, then runs git clean.

  :param str path: git directory to clean

  :param str arguments: str containing optional extra command line arguments
    for git clean, as you would type them on the command line. If you wanted
    to do `git clean -fd`, you'd set arguments to "-fd".

  :param logger: An initialized logger object

  :raises CommandFailedError: if git clean fails
  """
  assert logger
  assert isinstance(arguments, basestring), (
    "arguments must be a string, but is %r" % arguments)
  assert isinstance(path, basestring), "path must be a string, but is %r" % path

  command = ["git", "clean"]
  if arguments:
    command.append(arguments)
  logger.debug("* Running %s in %s", command, path)
  with changeToWorkingDir(path):
    return executeCommand(command=command, logger=logger)
def pull(logger, arguments=None):
    """
  Do a git pull, with optional parameters.

  Example usage:

    pull(arguments=["origin", "next"])
    pull(arguments=["origin", "next", "--ff-only"])
    pull(arguments=["[email protected]:username/repo.git", "next"])

  :param str arguments: Any extra arguments you want to pass to git pull
  :param logger: An initialized logger object
  """
    if arguments:
        assert (isinstance(arguments, basestring)
                or isinstance(arguments, tuple)
                or isinstance(arguments, list)), (
                    "arguments must be a string or list, but is %r" %
                    arguments)
    assert logger
    gitCommand = ["git", "pull"]
    if arguments:
        if isinstance(arguments, list) or isinstance(arguments, tuple):
            gitCommand.extend(arguments)
        if isinstance(arguments, basestring):
            arguments.extend(str.split(arguments))
    return executeCommand(command=gitCommand, logger=logger)
示例#15
0
文件: git.py 项目: darian19/what
def getGitRootFolder():
  """
  Return the root folder of the current YOMP repo

  @raises:
    infrastructure.utilities.exceptions.CommandFailedError if
    the command fails

  @returns: The full path of the root folder of the current YOMP repo
  @rtype: string
  """
  return executeCommand("YOMP rev-parse --show-toplevel")
示例#16
0
文件: git.py 项目: darian19/what
def add(pathspec):
  """
  Add file contents to the index

  @param pathspec: The file that is to be added to YOMP.

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
  command = "YOMP add %s" % pathspec
  return executeCommand(command)
示例#17
0
文件: git.py 项目: bopopescu/what
def getGitRootFolder():
    """
  Return the root folder of the current YOMP repo

  @raises:
    infrastructure.utilities.exceptions.CommandFailedError if
    the command fails

  @returns: The full path of the root folder of the current YOMP repo
  @rtype: string
  """
    return executeCommand("YOMP rev-parse --show-toplevel")
示例#18
0
文件: git.py 项目: bopopescu/what
def add(pathspec):
    """
  Add file contents to the index

  @param pathspec: The file that is to be added to YOMP.

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
    command = "YOMP add %s" % pathspec
    return executeCommand(command)
示例#19
0
def revParse(commitish, logger, **kwargs):
  """
  Helper method to execute git rev-parse commands. Used to print the SHA1
  given a revision specifier (e.g HEAD). This function can return the output
  of the command executed or the exit code of the command executed if
  "exitcode" = True is passed as a keyword argument.

  :param str commitish: The commit-ish.

  :param logger: logger for additional debug info

  :param bool verify: Boolean. Defaults to False. If True, verify that exactly
    one parameter is provided, and that it can be turned into a raw
    20-byte SHA-1 that can be used to access the object database.

  :param bool quiet: Boolean. Defaults to False. Only valid with verify. If
    True, do not output an error message if the first argument is not a valid
    object name; instead exit with non-zero status silently. 'verify' must be
    True.

  :param bool abbrevRef: Boolean. Defaults to False. If True, a non-ambiguous
    short name of the objects name. 'TypeError' exception will be raised if
    'verify' and/or 'quiet' parameters are passed.

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :raises TypeError: Raised in following cases.
    - Invalid parameter is passed in **kwargs
    - "quiet" parameter is set without setting "verify" parameter
    - Both "verify" and "abbrevRef" parameters are set.

  :returns: A `string` representing a SHA or the exit code of the command.

  :rtype: str or int
  """
  validKwargs = {"verify", "quiet", "abbrevRef"}
  checkKwargs(kwargs=kwargs, validKwargs=validKwargs)
  if (("quiet" in kwargs and "verify" not in kwargs)
      or ("abbrevRef" in kwargs and "verify" in kwargs)):
    raise TypeError("Invalid parameters passed.")

  command = ["git", "rev-parse"]
  if checkIfOptionSet("verify", kwargs):
    command.append("--verify")
    if checkIfOptionSet("quiet", kwargs):
      command.append("--quiet")
  elif checkIfOptionSet("abbrevRef", kwargs):
    command.append("--abbrev-ref")

  command.append(commitish)
  return executeCommand(command=command, logger=logger)
示例#20
0
def revParse(commitish, logger, **kwargs):
    """
  Helper method to execute git rev-parse commands. Used to print the SHA1
  given a revision specifier (e.g HEAD). This function can return the output
  of the command executed or the exit code of the command executed if
  "exitcode" = True is passed as a keyword argument.

  :param str commitish: The commit-ish.

  :param logger: logger for additional debug info

  :param bool verify: Boolean. Defaults to False. If True, verify that exactly
    one parameter is provided, and that it can be turned into a raw
    20-byte SHA-1 that can be used to access the object database.

  :param bool quiet: Boolean. Defaults to False. Only valid with verify. If
    True, do not output an error message if the first argument is not a valid
    object name; instead exit with non-zero status silently. 'verify' must be
    True.

  :param bool abbrevRef: Boolean. Defaults to False. If True, a non-ambiguous
    short name of the objects name. 'TypeError' exception will be raised if
    'verify' and/or 'quiet' parameters are passed.

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :raises TypeError: Raised in following cases.
    - Invalid parameter is passed in **kwargs
    - "quiet" parameter is set without setting "verify" parameter
    - Both "verify" and "abbrevRef" parameters are set.

  :returns: A `string` representing a SHA or the exit code of the command.

  :rtype: str or int
  """
    validKwargs = {"verify", "quiet", "abbrevRef"}
    checkKwargs(kwargs=kwargs, validKwargs=validKwargs)
    if (("quiet" in kwargs and "verify" not in kwargs)
            or ("abbrevRef" in kwargs and "verify" in kwargs)):
        raise TypeError("Invalid parameters passed.")

    command = ["git", "rev-parse"]
    if checkIfOptionSet("verify", kwargs):
        command.append("--verify")
        if checkIfOptionSet("quiet", kwargs):
            command.append("--quiet")
    elif checkIfOptionSet("abbrevRef", kwargs):
        command.append("--abbrev-ref")

    command.append(commitish)
    return executeCommand(command=command, logger=logger)
示例#21
0
文件: git.py 项目: bopopescu/what
def getCurrentSha():
    """
  Get the current SHA of a given repo

  @raises:
    infrastructure.utilities.exceptions.CommandFailedError if
    the command fails; typically because you are not executing from within a
    YOMP repository

  @returns: The current SHA
  @rtype: string
  """
    return executeCommand("YOMP log -n1 --pretty=%H")
示例#22
0
文件: git.py 项目: darian19/what
def getCurrentSha():
  """
  Get the current SHA of a given repo

  @raises:
    infrastructure.utilities.exceptions.CommandFailedError if
    the command fails; typically because you are not executing from within a
    YOMP repository

  @returns: The current SHA
  @rtype: string
  """
  return executeCommand("YOMP log -n1 --pretty=%H")
示例#23
0
def add(pathspec, logger):
  """
  Add file contents to the index

  :param str pathspec: The file that is to be added to git.

  :param logger: logger for additional debug info

  :raises:
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
  command = ("git", "add", pathspec)
  return executeCommand(command=command, logger=logger)
示例#24
0
def add(pathspec, logger):
    """
  Add file contents to the index

  :param str pathspec: The file that is to be added to git.

  :param logger: logger for additional debug info

  :raises:
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
    command = ("git", "add", pathspec)
    return executeCommand(command=command, logger=logger)
示例#25
0
文件: git.py 项目: darian19/what
def fetch(repository, refspec):
  """
  Download objects and refs from another repository

  @param repository: Name of YOMP repository (e.g origin)

  @param refspec: Name of the refspec (e.g. master)

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
  command = "YOMP fetch %s %s" % (repository, refspec)
  return executeCommand(command)
示例#26
0
文件: git.py 项目: bopopescu/what
def fetch(repository, refspec):
    """
  Download objects and refs from another repository

  @param repository: Name of YOMP repository (e.g origin)

  @param refspec: Name of the refspec (e.g. master)

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
    command = "YOMP fetch %s %s" % (repository, refspec)
    return executeCommand(command)
示例#27
0
文件: git.py 项目: darian19/what
def getCommitCount(path):
  """
  Get the commit count from a YOMP directory tree

  @param: path to YOMP directory

  @raises: infrastructure.utilities.exceptions.CommandFailedError:
  if path isn't in a YOMP checkout

  @returns: total commit count for the YOMP directory

  @rtype: string
  """
  with changeToWorkingDir(path):
    return executeCommand("YOMP rev-list HEAD --count")
示例#28
0
def getGitRootFolder(logger):
  """
  Return the root folder of the current git repo

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails

  :returns: The full path of the root folder of the current git repo

  :rtype: str
  """
  command = ("git", "rev-parse", "--show-toplevel")
  return executeCommand(command=command, logger=logger)
示例#29
0
文件: git.py 项目: bopopescu/what
def getCommitCount(path):
    """
  Get the commit count from a YOMP directory tree

  @param: path to YOMP directory

  @raises: infrastructure.utilities.exceptions.CommandFailedError:
  if path isn't in a YOMP checkout

  @returns: total commit count for the YOMP directory

  @rtype: string
  """
    with changeToWorkingDir(path):
        return executeCommand("YOMP rev-list HEAD --count")
示例#30
0
def getGitRootFolder(logger):
    """
  Return the root folder of the current git repo

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails

  :returns: The full path of the root folder of the current git repo

  :rtype: str
  """
    command = ("git", "rev-parse", "--show-toplevel")
    return executeCommand(command=command, logger=logger)
示例#31
0
def fetch(repository, refspec, logger):
    """
  Download objects and refs from another repository

  :param str repository: Name of git repository (e.g origin)

  :param str refspec: Name of the refspec (e.g. master)

  :param logger: logger for additional debug info

  :raises:
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
    command = ("git", "fetch", repository, refspec)
    return executeCommand(command=command, logger=logger)
示例#32
0
def getCurrentSha(logger):
    """
  Get the current SHA of a given repo

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails; typically because you are not executing from within a
    git repository

  :returns: The current SHA

  :rtype: str
  """
    command = ("git", "log", "-n1", "--pretty=%H")
    return executeCommand(command=command, logger=logger)
示例#33
0
文件: git.py 项目: darian19/what
def removeFileFromGit(path):
  """
  Remove files from the working tree and from the index.

  @param path: The file or path that has to be removed.

  @raises:
  infrastructure.utilities.exceptions.CommandFailedError: if
  the command fails

  @returns output of YOMP rm

  @rtype: str
  """
  command = "YOMP rm -rf %s" % path
  return executeCommand(command)
示例#34
0
def fetch(repository, refspec, logger):
  """
  Download objects and refs from another repository

  :param str repository: Name of git repository (e.g origin)

  :param str refspec: Name of the refspec (e.g. master)

  :param logger: logger for additional debug info

  :raises:
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
  command = ("git", "fetch", repository, refspec)
  return executeCommand(command=command, logger=logger)
示例#35
0
文件: git.py 项目: bopopescu/what
def removeFileFromGit(path):
    """
  Remove files from the working tree and from the index.

  @param path: The file or path that has to be removed.

  @raises:
  infrastructure.utilities.exceptions.CommandFailedError: if
  the command fails

  @returns output of YOMP rm

  @rtype: str
  """
    command = "YOMP rm -rf %s" % path
    return executeCommand(command)
示例#36
0
def getCurrentSha(logger):
  """
  Get the current SHA of a given repo

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails; typically because you are not executing from within a
    git repository

  :returns: The current SHA

  :rtype: str
  """
  command = ("git", "log", "-n1", "--pretty=%H")
  return executeCommand(command=command, logger=logger)
示例#37
0
def removeFileFromGit(path, logger):
    """
  Remove files from the working tree and from the index.

  :param str path: The file or path that has to be removed.

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :returns: output of git rm

  :rtype: str
  """
    command = ("git", "rm", "-rf", path)
    return executeCommand(command=command, logger=logger)
示例#38
0
def getActiveBranch():
  """
  Get the active branch name for the repository

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The active branch name or the current SHA if in a detached head
    state
  @rtype: string
  """
  branch = executeCommand("git rev-parse --abbrev-ref HEAD")
  if branch == "HEAD":
    branch = getCurrentSha()

  return branch
示例#39
0
def removeFileFromGit(path, logger):
  """
  Remove files from the working tree and from the index.

  :param str path: The file or path that has to be removed.

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError: if the
    command fails

  :returns: output of git rm

  :rtype: str
  """
  command = ("git", "rm", "-rf", path)
  return executeCommand(command=command, logger=logger)
示例#40
0
文件: git.py 项目: bopopescu/what
def commit(message, **kwargs):
    """
  Record changes to the repository
  Current implementation is supporting options like --amend
  This could be extended for other options as when required

  @param message: Commit message.

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
    command = "YOMP commit "
    if checkIfOptionSet("amend", **kwargs):
        command += " --amend"
    command += " %s" % message
    return executeCommand(command)
示例#41
0
def getActiveBranch():
    """
  Get the active branch name for the repository

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The active branch name or the current SHA if in a detached head
    state
  @rtype: string
  """
    branch = executeCommand("git rev-parse --abbrev-ref HEAD")
    if branch == "HEAD":
        branch = getCurrentSha()

    return branch
示例#42
0
def getModifiedFilesBetweenRevisions(startSha, endSha):
    """
  Get a list of all files modified between revisions

  @param startSha: SHA to start searching from

  @param endSha: SHA to search until

  @raises:
    infrastructure.utilities.exceptions.CommandFailedError if
    the command fails; typically because you are not executing from within a
    git repository

  @returns: A `set` of modified files or None if the command fails
  @rtype: set
  """
    return set(executeCommand("git diff --name-only %s...%s" % (startSha, endSha)).split("\n"))
示例#43
0
文件: git.py 项目: darian19/what
def commit(message, **kwargs):
  """
  Record changes to the repository
  Current implementation is supporting options like --amend
  This could be extended for other options as when required

  @param message: Commit message.

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
  command = "YOMP commit "
  if checkIfOptionSet("amend", **kwargs):
    command += " --amend"
  command += " %s" % message
  return executeCommand(command)
示例#44
0
def getCommitCount(path, logger):
  """
  Get the commit count from a git directory tree

  :param str path: path to git directory

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if path isn't in a git checkout

  :returns: total commit count for the git directory

  :rtype: str
  """
  with changeToWorkingDir(path):
    command = ("git", "rev-list", "HEAD", "--count")
    return executeCommand(command=command, logger=logger)
示例#45
0
文件: git.py 项目: bopopescu/what
def reset(sha="", **kwargs):
    """
  Resets the repository to a optional SHA. Optional argument for --hard

  @param kwargs:

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The exit code
  @rtype: int
  """
    command = "YOMP reset "
    if checkIfOptionSet("hard", **kwargs):
        command += "--hard"
    command += " %s" % sha
    return executeCommand(command)
示例#46
0
def getCommitCount(path, logger):
    """
  Get the commit count from a git directory tree

  :param str path: path to git directory

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if path isn't in a git checkout

  :returns: total commit count for the git directory

  :rtype: str
  """
    with changeToWorkingDir(path):
        command = ("git", "rev-list", "HEAD", "--count")
        return executeCommand(command=command, logger=logger)
示例#47
0
文件: git.py 项目: darian19/what
def reset(sha="", **kwargs):
  """
  Resets the repository to a optional SHA. Optional argument for --hard

  @param kwargs:

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The exit code
  @rtype: int
  """
  command = "YOMP reset "
  if checkIfOptionSet("hard", **kwargs):
    command += "--hard"
  command += " %s" % sha
  return executeCommand(command)
示例#48
0
文件: git.py 项目: darian19/what
def getActiveBranch():
  """
  Get the active branch name for the repository

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
      the command fails
    infrastructure.utilities.exceptions.DetachedHeadError: if the YOMP checkout
      is in a detached head state

  @returns: The active branch name or the current SHA if in a detached head
    state
  @rtype: string
  """
  branch = executeCommand("YOMP rev-parse --abbrev-ref HEAD")
  if branch == "HEAD":
    raise DetachedHeadError("There is no active branch; the head is detached.")

  return branch
示例#49
0
文件: git.py 项目: bopopescu/what
def getModifiedFilesBetweenRevisions(startSha, endSha):
    """
  Get a list of all files modified between revisions

  @param startSha: SHA to start searching from

  @param endSha: SHA to search until

  @raises:
    infrastructure.utilities.exceptions.CommandFailedError if
    the command fails; typically because you are not executing from within a
    YOMP repository

  @returns: A `set` of modified files or None if the command fails
  @rtype: set
  """
    return set(
        executeCommand("YOMP diff --name-only %s...%s" %
                       (startSha, endSha)).split("\n"))
示例#50
0
文件: git.py 项目: bopopescu/what
def merge(path, message, **kwargs):
    """
  Join two or more development histories together
  Current implementation supports --no-ff
  This could be extended for other options as when required.

  @param path:

  @param message: Merge commit message.

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
    command = "YOMP merge "
    if checkIfOptionSet("noFF", **kwargs):
        command += " --no-ff"
    command += " -m %s %s" % (message, path)
    return executeCommand(command)
示例#51
0
文件: git.py 项目: darian19/what
def merge(path, message, **kwargs):
  """
  Join two or more development histories together
  Current implementation supports --no-ff
  This could be extended for other options as when required.

  @param path:

  @param message: Merge commit message.

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails
  """
  command = "YOMP merge "
  if checkIfOptionSet("noFF", **kwargs):
    command += " --no-ff"
  command += " -m %s %s" % (message, path)
  return executeCommand(command)
示例#52
0
文件: git.py 项目: bopopescu/what
def getActiveBranch():
    """
  Get the active branch name for the repository

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
      the command fails
    infrastructure.utilities.exceptions.DetachedHeadError: if the YOMP checkout
      is in a detached head state

  @returns: The active branch name or the current SHA if in a detached head
    state
  @rtype: string
  """
    branch = executeCommand("YOMP rev-parse --abbrev-ref HEAD")
    if branch == "HEAD":
        raise DetachedHeadError(
            "There is no active branch; the head is detached.")

    return branch
示例#53
0
def getModifiedFilesBetweenRevisions(startSha, endSha, logger):
    """
  Get a list of all files modified between revisions

  :param str startSha: SHA to start searching from

  :param str endSha: SHA to search until

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails; typically because you are not executing from within a
    git repository

  :returns: A `set` of modified files or None if the command fails

  :rtype: set
  """
    command = ("git", "diff", "--name-only", "%s...%s" % (startSha, endSha))
    return set(executeCommand(command=command, logger=logger).split("\n"))
示例#54
0
def getModifiedFilesBetweenRevisions(startSha, endSha, logger):
    """
  Get a list of all files modified between revisions

  :param str startSha: SHA to start searching from

  :param str endSha: SHA to search until

  :param logger: logger for additional debug info

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails; typically because you are not executing from within a
    git repository

  :returns: A `set` of modified files or None if the command fails

  :rtype: set
  """
    command = ("git", "diff", "--name-only", "%s...%s" % (startSha, endSha))
    return set(executeCommand(command=command, logger=logger).split("\n"))
示例#55
0
def checkout(pathspec, logger, **kwargs):
    """
  Switches to a given commit-ish

  :param str pathspec: The name of the branch (commit-ish)

  :param logger: logger for additional debug info

  :param bool new: Boolean. Defaults to False. If True, create a new branch.

  :param bool orphan: Boolean. Defaults to False. If True, create a new orphan
    branch.

  :param bool theirs: Boolean. Defaults to False. If True, when checking out
    paths from the index, check out stage #3 (theirs) for unmerged paths.

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails

  :raises TypeError: Raised in following cases.
    - If invalid parameter is passed in **kwargs
    - More than one arguments are passed in **kwargs

  :returns: The text blob output of git checkout

  :rtype: str
  """
    validKwargs = {"new", "orphan", "theirs"}
    checkKwargs(kwargs=kwargs, validKwargs=validKwargs)
    command = ["git", "checkout"]
    if len(kwargs) > 1:
        raise TypeError("Invalid parameters passed.")
    if checkIfOptionSet("new", kwargs):
        command.append("-b")
    elif checkIfOptionSet("orphan", kwargs):
        command.append("--orphan")
    elif checkIfOptionSet("theirs", kwargs):
        command.append("--theirs")

    command.append(pathspec)
    return executeCommand(command=command, logger=logger)
示例#56
0
def checkout(pathspec, logger, **kwargs):
  """
  Switches to a given commit-ish

  :param str pathspec: The name of the branch (commit-ish)

  :param logger: logger for additional debug info

  :param bool new: Boolean. Defaults to False. If True, create a new branch.

  :param bool orphan: Boolean. Defaults to False. If True, create a new orphan
    branch.

  :param bool theirs: Boolean. Defaults to False. If True, when checking out
    paths from the index, check out stage #3 (theirs) for unmerged paths.

  :raises infrastructure.utilities.exceptions.CommandFailedError:
    if the command fails

  :raises TypeError: Raised in following cases.
    - If invalid parameter is passed in **kwargs
    - More than one arguments are passed in **kwargs

  :returns: The text blob output of git checkout

  :rtype: str
  """
  validKwargs = {"new", "orphan", "theirs"}
  checkKwargs(kwargs=kwargs, validKwargs=validKwargs)
  command = ["git", "checkout"]
  if len(kwargs) > 1:
    raise TypeError("Invalid parameters passed.")
  if checkIfOptionSet("new", kwargs):
    command.append("-b")
  elif checkIfOptionSet("orphan", kwargs):
    command.append("--orphan")
  elif checkIfOptionSet("theirs", kwargs):
    command.append("--theirs")

  command.append(pathspec)
  return executeCommand(command=command, logger=logger)
示例#57
0
文件: git.py 项目: darian19/what
def clone(YOMPURL, **kwargs):
  """
  Clones the given YOMP repository

  @param YOMPURL: The repository URL.
  @param kwargs: Various options to YOMP clone YOMPURL can be passed as keyword
    arguments. For now only directory option is handled.
  e.g.
  clone(YOMPURL, directory=nameOfDirectory)

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The blob output of YOMP clone
  @rtype: string
  """
  command = "YOMP clone %s" % YOMPURL
  if checkIfOptionSet("directory", **kwargs):
    command += " " + kwargs["directory"]
  return executeCommand(command)
示例#58
0
文件: git.py 项目: bopopescu/what
def clone(YOMPURL, **kwargs):
    """
  Clones the given YOMP repository

  @param YOMPURL: The repository URL.
  @param kwargs: Various options to YOMP clone YOMPURL can be passed as keyword
    arguments. For now only directory option is handled.
  e.g.
  clone(YOMPURL, directory=nameOfDirectory)

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: The blob output of YOMP clone
  @rtype: string
  """
    command = "YOMP clone %s" % YOMPURL
    if checkIfOptionSet("directory", **kwargs):
        command += " " + kwargs["directory"]
    return executeCommand(command)
示例#59
0
文件: git.py 项目: bopopescu/what
def revParse(commitish, **kwargs):
    """
  Helper method to execute YOMP rev-parse commands. Used to print the SHA1
  given a revision specifier (e.g HEAD). This function can return the output
  of the command executed or the exit code of the command executed if
  "exitcode" = True is passed as a keyword argument.

  @param commitish: The commit-ish.

  @param kwargs: Various options to YOMP rev-parse can be passed as keyword
  arguments. The following options are currently supported:

  verify: Verify that exactly one parameter is provided, and that it
  can be turned into a raw 20-byte SHA-1 that can be used to access the object
  database.

  quiet: Only valid with verify. Do not output an error message if the
  first argument is not a valid object name; instead exit with non-zero status
  silently.

  abbrevRef: A non-ambiguous short name of the objects name

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: A `string` representing a SHA or the exit code of the command.

  @rtype: string or int
  """
    command = "YOMP rev-parse"
    if checkIfOptionSet("verify", **kwargs):
        command += " --verify"
    elif checkIfOptionSet("quiet", **kwargs):
        command += " --quiet"
    elif checkIfOptionSet("abbrevRef", **kwargs):
        command += " --abbrev-ref"

    command += " %s" % commitish
    return executeCommand(command)
示例#60
0
文件: git.py 项目: darian19/what
def revParse(commitish, **kwargs):
  """
  Helper method to execute YOMP rev-parse commands. Used to print the SHA1
  given a revision specifier (e.g HEAD). This function can return the output
  of the command executed or the exit code of the command executed if
  "exitcode" = True is passed as a keyword argument.

  @param commitish: The commit-ish.

  @param kwargs: Various options to YOMP rev-parse can be passed as keyword
  arguments. The following options are currently supported:

  verify: Verify that exactly one parameter is provided, and that it
  can be turned into a raw 20-byte SHA-1 that can be used to access the object
  database.

  quiet: Only valid with verify. Do not output an error message if the
  first argument is not a valid object name; instead exit with non-zero status
  silently.

  abbrevRef: A non-ambiguous short name of the objects name

  @raises
    infrastructure.utilities.exceptions.CommandFailedError: if
    the command fails

  @returns: A `string` representing a SHA or the exit code of the command.

  @rtype: string or int
  """
  command = "YOMP rev-parse"
  if checkIfOptionSet("verify", **kwargs):
    command += " --verify"
  elif checkIfOptionSet("quiet", **kwargs):
    command += " --quiet"
  elif checkIfOptionSet("abbrevRef", **kwargs):
    command += " --abbrev-ref"

  command += " %s" % commitish
  return executeCommand(command)