gitalong.repository module¶
- class Repository(repository: str = '', use_cached_instances=False)[source]¶
Bases:
objectThe Gitalong class aggregates all the Gitalong actions that can happen on a repository.
- classmethod setup(store_repository: str, managed_repository: str = '', modify_permissions=False, pull_treshold: float = 60.0, track_binaries: bool = False, track_uncommitted: bool = False, tracked_extensions: Optional[list] = None, update_gitignore: bool = False, update_hooks: bool = False)[source]¶
Setup Gitalong in a repository.
- Parameters
store_repository (str) – The URL or path to the repository that Gitalong will use to store local changes.
managed_repository (str, optional) – The repository in which we install Gitalong. Defaults to current working directory. Current working directory if not passed.
modify_permissions (bool, optional) – Whether Gitalong should managed permissions of binary files.
track_binaries (bool, optional) – Track all binary files by automatically detecting them.
track_uncommitted (bool, optional) – Track uncommitted changes. Better for collaboration but requires to push tracked commits after each file system operation.
tracked_extensions (list, optional) – List of extensions to track.
pull_treshold (list, optional) – Time in seconds that need to pass before Gitalong pulls again. Defaults to 10 seconds. This is for optimization sake as pull and fetch operation are expensive. Defaults to 60 seconds.
update_gitignore (bool, optional) – Whether .gitignore should be modified in the managed repository to ignore Gitalong files.
update_hooks (bool, optional) – Whether hooks should be updated with Gitalong logic.
- Returns
Gitalong – The Gitalong management class corresponding to the repository in which we just installed.
- update_gitignore()[source]¶
Update the .gitignore of the managed repository with Gitalong directives.
TODO: Improve update by considering what is already ignored.
- property config_path: str¶
Returns: dict: The content of .gitalong.json as a dictionary.
- property config: dict¶
Returns: dict: The content of .gitalong.json as a dictionary.
- property hooks_path: str¶
Returns: str: The hook path of the managed repository.
- install_hooks()[source]¶
Installs Gitalong hooks in managed repository.
TODO: Implement non-destructive version of these hooks. Currently we don’t have any consideration for preexisting content.
- get_relative_path(filename: str) str[source]¶
- Parameters
filename (str) – The absolute path.
- Returns
str – The path relative to the managed repository.
- get_absolute_path(filename: str) str[source]¶
- Parameters
filename (str) – The path relative to the managed repository.
- Returns
str – The absolute path.
- get_file_last_commit(filename: str, prune: bool = True) dict[source]¶
- Parameters
filename (str) – Absolute or relative filename to get the last commit for.
prune (bool, optional) – Prune branches if a fetch is necessary.
- Returns
dict –
- The last commit for the provided filename across all branches local or
remote.
- property active_branch_commits: list¶
Returns: list: List of all local commits for active branch.
- get_commit_spread(commit: dict) dict[source]¶
- Parameters
commit (dict) – The commit to check for.
- Returns
dict – A dictionary of commit spread information containing all information about where this commit lives across branches and clones.
- static is_uncommitted_changes_commit(commit: dict) bool[source]¶
- Parameters
commit (dict) – The commit dictionary.
- Returns
bool – Whether the commit dictionary represents uncommitted changes.
- property uncommitted_changes_commit: dict¶
Returns: dict: Returns a commit dictionary representing uncommitted changes.
- is_issued_commit(commit: dict) bool[source]¶
- Parameters
commit (dict) – The commit dictionary to check for.
- Returns
bool – Whether the commit was issued by the current context.
- is_issued_uncommitted_changes_commit(commit: dict) bool[source]¶
- Parameters
commit (dict) – Description
- Returns
bool – Whether the commit represents uncommitted changes and is issued by the current context.
- accumulate_local_only_commits(start: git.objects.commit.Commit, local_commits: list)[source]¶
Accumulates a list of local only commit starting from the provided commit.
- Parameters
local_commits (list) – The accumulated local commits.
start (git.objects.Commit) – The commit that we start peeling from last commit.
- property context_dict: dict¶
Returns: dict: A dict of contextual values that we attached to tracked commits.
- property local_only_commits: list¶
Returns: list:
Commits that are not on remote branches. Includes a commit that represents uncommitted changes.
- property uncommitted_changes: list¶
Returns: list: A list of unique relative filenames that feature uncommitted changes.
- get_commit_dict(commit: git.objects.commit.Commit) dict[source]¶
- Parameters
commit (git.objects.Commit) – The commit to get as a dict.
- Returns
dict – A simplified JSON serializable dict that represents the commit.
- get_commit_branches(hexsha: str, remote: bool = False) list[source]¶
- Parameters
hexsha (str) – The hexsha of the commit to check for.
remote (bool, optional) – Whether we should return local or remote branches.
- Returns
list – A list of branch names that this commit is living on.
- is_ignored(filename: str) bool[source]¶
- Parameters
filename (str) – The filename to check for.
- Returns
bool – Whether a file is ignored by the managed repository .gitignore file.
- property submodules: list¶
Returns: TYPE: A list of submodule relative filenames.
- is_submodule_file(filename) bool[source]¶
- Parameters
filename (TYPE) – Description
- Returns
TYPE – Whether a an absolute or relative filename belongs to a submodule.
- property tracked_commits_json_path¶
Returns: TYPE: The path to the JSON file that tracks the local commits.
- property files: list¶
Returns: list:
The relative filenames that are tracked by the managed repository. Not to be confused with the files tracked by Gitalong.
- property locally_changed_files: list¶
Returns: list:
The relative filenames that have been changed by local commits or uncommitted changes.
- update_file_permissions(filename: str, locally_changed_files: Optional[list] = None) tuple[source]¶
Updates the permissions of a file based on whether or not it was locally changed.
- Parameters
filename (str) – The relative or absolute filename to update permissions for.
locally_changed_files (list, optional) – For optimization sake you can pass the locally changed files if you already have them. Default will compute them.
- Returns
tuple – A tuple featuring the permission and the filename.
- is_file_tracked(filename: str) bool[source]¶
- Parameters
filename (str) – The absolute or relative file or folder path to check for.
- Returns
bool – Whether the file is tracked by Gitalong.
- property updated_tracked_commits: list¶
Returns: list:
Local commits for all clones with local commits and uncommitted changes from this clone.
- update_tracked_commits(commits: Optional[list] = None, push: bool = True)[source]¶
Write and pushes JSON file that tracks the local commits from all clones using the passed commits.
- Parameters
commits (list, optional) – The tracked commits to update with. Default to evaluating updated tracked commits.
push (bool, optional) – Whether we are pushing the update JSON file to the Gitalong repository remote.
- property tracked_commits: List[dict]¶
Returns: typing.List[dict]:
A list of commits that haven’t been pushed to remote. Also includes commits representing uncommitted changes.
- make_file_writable(filename: str, prune: bool = True) dict[source]¶
Make a file writable if it’s not missing with other tracked commits that aren’t present locally.
- Parameters
filename (str) – The file to make writable. Takes a path that’s absolute or relative to the managed repository.
- Returns
dict – The missing commit that we are missing.
- property working_dir¶