fab.tools.versioning module#

This file contains the base class for versioning tools like git and subversion. It also contains derived classes Git, Subversion, and Fcm.

class fab.tools.versioning.Versioning(name, exec_name, category)#

Bases: Tool

This is the base class for versioning tools like git and svn.

Parameters:
  • name (str) – the name of the tool.

  • exec_name (Union[str, Path]) – the name of the executable of this tool.

  • category (Category) – the category to which this tool belongs).

class fab.tools.versioning.Git#

Bases: Versioning

This is the base class for git.

current_commit(folder=None)#
Return type:

str

Returns:

the hash of the current commit.

Parameters:

folder (Union[Path, str, None]) – the folder for which to determine the current commitf (defaults to .). (default: None)

init(folder)#

Initialises a directory.

Parameters:

folder (Union[Path, str]) – the directory to initialise.

clean(folder)#

Removes all non versioned files in a directory.

Parameters:

folder (Union[Path, str]) – the directory to clean.

fetch(src, dst, revision)#

Runs git fetch in the specified directory

Parameters:
  • src (Union[str, Path]) – the source directory from which to fetch

  • revision (Optional[str]) – the revision to fetch (can be “” for latest revision)

  • dst (Union[str, Path]) – the directory in which to run fetch.

checkout(src, dst='', revision=None)#

Checkout or update a Git repo.

Parameters:
  • src (str) – the source directory from which to checkout.

  • dst (str) – the directory in which to run checkout. (default: '')

  • revision (Optional[str]) – the revision to check out (can be “” for latest revision). (default: None)

merge(dst, revision=None)#

Merge a git repo into a local working copy. If the merge fails, it will run git merge –abort to clean the directory.

Parameters:
  • dst (Union[str, Path]) – the directory to merge in.

  • revision (Optional[str]) – the revision number (only used for error message, it relies on git fetch running previously). (default: None)

class fab.tools.versioning.Subversion(name=None, exec_name=None, category=Category.SUBVERSION)#

Bases: Versioning

This is the base class for subversion. Note that this is also the base class for FCM, so it allows overwriting name, exec_name and category, but will default to use svn.

Parameters:
  • name (Optional[str]) – name of the tool, defaults to subversion. (default: None)

  • exec_name (Union[Path, str, None]) – name of the executable, defaults to “svn”. (default: None)

  • category (Category) – the category, FCM or SUBVERSION (the latter is the default) (default: <Category.SUBVERSION: 9>)

execute(pre_commands=None, revision=None, post_commands=None, env=None, cwd=None, capture_output=True)#

Executes a svn command.

Parameters:
  • pre_commands (Optional[List[str]]) – List of strings to be sent to subprocess.run() as the command. (default: None)

  • revision (Union[int, str, None]) – optional revision number as argument (default: None)

  • post_commands (Optional[List[str]]) – List of additional strings to be sent to subprocess.run() after the optional revision number. (default: None)

  • env (Optional[Dict[str, str]]) – Optional env for the command. By default it will use the current session’s environment. (default: None)

  • capture_output – If True, capture and return stdout. If False, the command will print its output directly to the console. (default: True)

Return type:

str

export(src, dst, revision=None)#

Runs svn export.

Parameters:
checkout(src, dst, revision=None)#

Runs svn checkout.

Parameters:
update(dst, revision=None)#

Runs svn checkout.

Parameters:
merge(src, dst, revision=None)#

Runs svn merge.

Parameters:
class fab.tools.versioning.Fcm#

Bases: Subversion

This is the base class for FCM. All commands will be mapped back to the corresponding subversion commands.