clowder.git package¶
Submodules¶
clowder.git.project_repo module¶
Project Git utility class
-
class
clowder.git.project_repo.
ProjectRepo
(repo_path, remote, default_ref, parallel=False)¶ Bases:
clowder.git.project_repo_impl.ProjectRepoImpl
Class encapsulating git utilities for projects
Variables: - repo_path (str) – Absolute path to repo
- default_ref (str) – Default ref
- remote (str) – Default remote name
- parallel (bool) – Whether command is being run in parallel, affects output
- repo (Repo) – Repo instance
-
configure_remotes
(upstream_remote_name, upstream_remote_url, fork_remote_name, fork_remote_url)¶ Configure remotes names for fork and upstream
Parameters: - upstream_remote_name (str) – Upstream remote name
- upstream_remote_url (str) – Upstream remote url
- fork_remote_name (str) – Fork remote name
- fork_remote_url (str) – Fork remote url
-
create_clowder_repo
(url, branch, depth=0)¶ Clone clowder git repo from url at path
-
create_clowder_repo
(url, branch, depth=0)
Parameters: - url (str) – URL of repo
- branch (str) – Branch name
- depth (Optional[int]) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
-
-
herd
(url, **kwargs)¶ Herd ref
-
herd
(url, depth=0, fetch=True, rebase=False)
Parameters: url (str) – URL of repo
Keyword Arguments: - depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- fetch (bool) – Whether to fetch
- rebase (bool) – Whether to use rebase instead of pulling latest changes
-
-
herd_branch
(url, branch, **kwargs)¶ Herd branch
-
herd_branch
(url, branch, depth=0, fork_remote=None, rebase=False)
Parameters: - url (str) – URL of repo
- branch (str) – Branch name
Keyword Arguments: - depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- fork_remote (str) – Fork remote name
- rebase (bool) – Whether to use rebase instead of pulling latest changes
-
-
herd_remote
(url, remote, branch=None)¶ Herd remote repo
Parameters: - url (str) – URL of repo
- remote (str) – Remote name
- branch (Optional[str]) – Branch name
-
herd_tag
(url, tag, **kwargs)¶ Herd tag
-
herd_tag
(url, tag, depth=0, rebase=False)
Parameters: - url (str) – URL of repo
- tag (str) – Tag name
Keyword Arguments: - depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- rebase (bool) – Whether to use rebase instead of pulling latest changes
-
-
prune_branch_local
(branch, force)¶ Prune local branch
Parameters: - branch (str) – Branch name to delete
- force (bool) – Force delete branch
-
prune_branch_remote
(branch, remote)¶ Prune remote branch in repository
Parameters: - branch (str) – Branch name to delete
- remote (str) – Remote name
-
reset
(depth=0)¶ Reset branch to upstream or checkout tag/sha as detached HEAD
-
reset
(depth=0)
Parameters: depth (Optional[int]) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer -
-
reset_timestamp
(timestamp, author, ref)¶ Reset branch to upstream or checkout tag/sha as detached HEAD
Parameters: - timestamp (str) – Commit ref timestamp
- author (str) – Commit author
- ref (str) – Reference ref
-
start
(remote, branch, depth, tracking)¶ Start new branch in repository
Parameters: - remote (str) – Remote name
- branch (str) – Local branch name to create
- depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- tracking (bool) – Whether to create a remote branch with tracking relationship
-
sync
(fork_remote, rebase=False)¶ Sync fork with upstream remote
-
sync
(fork_remote, rebase=False)
Parameters: - fork_remote (str) – Fork remote name
- rebase (Optional[bool]) – Whether to use rebase instead of pulling latest changes.
-
clowder.git.project_repo_impl module¶
Project Git abstract utility class
-
class
clowder.git.project_repo_impl.
ProjectRepoImpl
(repo_path, remote, default_ref, parallel=False)¶ Bases:
clowder.git.repo.GitRepo
Abstract class encapsulating private git utilities for projects
Variables: - repo_path (str) – Absolute path to repo
- default_ref (str) – Default ref
- remote (str) – Default remote name
- parallel (bool) – Whether command is being run in parallel, affects output
- repo (Repo) – Repo instance
clowder.git.project_repo_recursive module¶
Project Git utility class with submodules
-
class
clowder.git.project_repo_recursive.
ProjectRepoRecursive
(repo_path, remote, default_ref, parallel=False)¶ Bases:
clowder.git.project_repo.ProjectRepo
Class encapsulating git utilities for projects with submodules
Variables: - repo_path (strt) – Absolute path to repo
- default_ref (strt) – Default ref
- remote (strt) – Default remote name
- parallel (bool) – Whether command is being run in parallel, affects output
- repo (Repo) – Repo instance
-
clean
(args='')¶ Discard changes for repo and submodules
Parameters: args (Optional[str]) – Git clean options - d
Remove untracked directories in addition to untracked files -f
Delete directories with .git sub directory or file -X
Remove only files ignored by git -x
Remove all untracked files
-
has_submodules
()¶ Repo has submodules
Returns: True, if repo has submodules Return type: bool
-
herd
(url, **kwargs)¶ Herd ref
-
herd
(url, depth=0, fetch=True, rebase=False)
Parameters: url (str) – URL of repo
Keyword Arguments: - depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- fetch (bool) – Whether to fetch
- rebase (bool) – Whether to use rebase instead of pulling latest changes
-
-
herd_branch
(url, branch, **kwargs)¶ Herd branch
-
herd
(url, branch, depth=0, fork_remote=None, rebase=False)
Parameters: - url (str) – URL of repo
- branch (str) – Branch name
Keyword Arguments: - depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- fork_remote (str) – Fork remote name
- rebase (bool) – Whether to use rebase instead of pulling latest changes
-
-
herd_tag
(url, tag, **kwargs)¶ Herd tag
-
herd_tag
(url, tag, depth=0, rebase=False)
Parameters: - url (str) – URL of repo
- tag (str) – Tag name
Keyword Arguments: - depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- rebase (bool) – Whether to use rebase instead of pulling latest changes
-
-
is_dirty_submodule
(path)¶ Check whether submodule repo is dirty
Parameters: path (str) – Submodule path Returns: True, if submodule at path is dirty Return type: bool
-
submodule_update_recursive
(depth=0)¶ Update submodules recursively and initialize if not present
-
submodule_update_recursive
(depth=0)
Parameters: depth (Optional[int]) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer -
-
sync
(fork_remote, rebase=False)¶ Sync fork with upstream remote
-
sync
(fork_remote, rebase=False)
Parameters: - fork_remote (str) – Fork remote name
- rebase (Optional[bool]) – Whether to use rebase instead of pulling latest changes
-
-
validate_repo
()¶ Validate repo state
Returns: True, if repo and submodules not dirty or repo doesn’t exist on disk Return type: bool
clowder.git.repo module¶
Base Git utility class
-
class
clowder.git.repo.
GitRepo
(repo_path, remote, default_ref, parallel=False)¶ Bases:
object
Class encapsulating base git utilities
Variables: - repo_path (str) – Absolute path to repo
- default_ref (str) – Default ref
- remote (str) – Default remote name
- parallel (bool) – Whether command is being run in parallel, affects output
- repo (Repo) – Repo instance
-
add
(files)¶ Add files to git index
Parameters: files (str) – Files to git add
-
checkout
(truncated_ref, allow_failure=False)¶ Checkout git ref
-
checkout
(truncated_ref, allow_failure=False)
Parameters: - truncated_ref (str) – Ref to git checkout
- allow_failure (Optional[bool]) – Whether to allow failing to checkout branch
-
-
clean
(args='')¶ Discard changes for repo
Parameters: args (Optional[str]) – Git clean options - d
Remove untracked directories in addition to untracked files -f
Delete directories with .git sub directory or file -X
Remove only files ignored by git -x
Remove all untracked files
-
commit
(message)¶ Commit current changes
Parameters: message (str) – Git commit message
-
current_branch
()¶ Return currently checked out branch of project
Returns: Name of currently checked out branch Return type: str
-
existing_local_branch
(branch)¶ Check if local branch exists
Parameters: branch (str) – Branch name Returns: True, if local branch exists Return type: bool
-
existing_remote_branch
(branch, remote)¶ Check if remote branch exists
Parameters: - branch (str) – Branch name
- remote (str) – Remote name
Returns: True, if remote branch exists
Return type: bool
-
fetch
(remote, **kwargs)¶ Fetch from a specific remote ref
-
fetch
(remote, ref=None, depth=0, remove_dir=False, allow_failure=False)
Parameters: remote (str) – Remote name
Keyword Arguments: - ref (str) – Ref to fetch
- depth (int) – Git clone depth. 0 indicates full clone, otherwise must be a positive integer
- remove_dir (bool) – Whether to remove the directory if commands fail
- allow_failure (bool) – Whether to allow failure
-
-
get_current_timestamp
()¶ Get current timestamp of HEAD commit
Returns: HEAD commit timestamp Return type: str
-
is_detached
(print_output=False)¶ Check if HEAD is detached
-
is_detached
(print_output=False)
Parameters: print_output (Optional[bool]) – Whether to print output Returns: True, if HEAD is detached Return type: bool -
-
is_dirty
()¶ Check whether repo is dirty
Returns: True, if repo is dirty Return type: bool
-
new_commits
(upstream=False)¶ Returns the number of new commits
-
new_commits
(upstream=False)
Parameters: upstream (Optional[bool]) – Whether to find number of new upstream or local commits Returns: Int number of new commits Return type: int -
-
print_branches
(local=False, remote=False)¶ Print branches
-
print_branches
(local=False, remote=False)
Parameters: - local (Optional[bool]) – Print local branches
- remote (Optional[bool]) – Print remote branches
-
-
pull
(**kwargs)¶ Wrapper
-
push
(**kwargs)¶ Wrapper
-
sha
(short=False)¶ Return sha for currently checked out commit
-
sha
(short=False)
Parameters: short (Optional[bool]) – Whether to return short or long commit sha Returns: Commit sha Return type: str -
-
sha_branch_remote
(remote, branch)¶ Return sha for remote branch
Parameters: - remote (str) – Remote name
- branch (str) – Remote branch name
Returns: Commit sha of remote branch
Return type: str
-
stash
()¶ Stash current changes in repository
-
status
()¶ Print git status
Equivalent to:
git status
-
status_verbose
()¶ Print git status
Equivalent to:
git status -vv
-
validate_repo
()¶ Validate repo state
Returns: True, if repo not dirty or doesn’t exist on disk Return type: bool
clowder.git.util module¶
Clowder git utilities
-
clowder.git.util.
existing_git_repository
(path)¶ Check if a git repository exists
Parameters: path (str) – Repo path Returns: True, if .git directory exists inside path Return type: bool
-
clowder.git.util.
existing_git_submodule
(path)¶ Check if a git submodule exists
Parameters: path (str) – Submodule path Returns: True, if .git file exists inside path Return type: bool
-
clowder.git.util.
format_project_ref_string
(repo)¶ Return formatted project ref string
Parameters: repo (GitRepo) – Git repo Returns: Formmatted repo ref Return type: str
-
clowder.git.util.
format_project_string
(repo, path)¶ Return formatted project name
Parameters: - repo (GitRepo) – Git repo
- path (str) – Relative project path
Returns: Formatted project name
Return type: str
-
clowder.git.util.
git_url
(protocol, url, name)¶ Return git url
Parameters: - protocol (str) – Git protocol (‘ssh’ or ‘https’)
- url (str) – Repo url
- name (str) – Repo name
Returns: Full git repo url for specified protocol
Return type: str
Raises:
-
clowder.git.util.
not_detached
(func)¶ If HEAD is detached, print error message and exit
-
clowder.git.util.
print_validation
(repo)¶ Print validation messages
Parameters: repo (GitRepo) – Git repo
-
clowder.git.util.
ref_type
(ref)¶ Return branch, tag, sha, or unknown ref type
Parameters: ref (str) – Full pathspec Returns: ‘branch’, ‘tag’, ‘sha’, or ‘unknown’ Return type: str
-
clowder.git.util.
truncate_ref
(ref)¶ Return bare branch, tag, or sha
Parameters: ref (str) – Full pathspec or short ref Returns: Ref with ‘refs/heads/’ and ‘refs/tags/’ prefix removed Return type: str