Skip to content

Commit

Permalink
Optimize operations implementing async functions (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglaslassance authored Jan 26, 2025
1 parent eaf9b92 commit 82a890b
Show file tree
Hide file tree
Showing 27 changed files with 1,114 additions and 901 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9, "3.10", 3.11, 3.12]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", 3.11, 3.12]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -23,9 +24,12 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --editable ".[ci]"
- name: Lint with flake8
- name: Format with black
run: |
flake8 . --count --show-source --statistics
black . --check
- name: Lint with Pylint
run: |
pylint .
- name: Test with pytest
run: |
pytest --cov=gitalong
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ dmypy.json

# Visual Studio Code
*.code-workspace

# Test data files
/tests/*.json
12 changes: 7 additions & 5 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[MASTER]

ignore=docs, __pycache__
ignore=docs, __pycache__, .venv
disable=
cyclic-import,
fixme,
logging-format-interpolation,
missing-module-docstring,
no-member,
too-many-arguments,
too-few-public-methods,
logging-format-interpolation,
missing-module-docstring

too-many-arguments


[FORMAT]

Expand Down
3 changes: 0 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"ms-python.black-formatter",
"yardensachs.copy-python-path",
"benspaulding.python-manifest-template",
"hbenl.vscode-test-explorer",
"littlefoxteam.vscode-python-test-adapter",
"ms-python.flake8",
"njpwerner.autodocstring",
"stkb.rewrap",
"ms-python.pylint",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"python.testing.pytestArgs": ["."],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.autoImportCompletions": true
"python.analysis.autoImportCompletions": true,
"pylint.importStrategy": "fromEnvironment"
}
140 changes: 17 additions & 123 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ elsewhere.

## Pre-requisites

- [Python >=3.7](https://www.python.org/downloads/)
- [Python >=3.10](https://www.python.org/downloads/)
- [Git >=2.35.1](https://git-scm.com/downloads)

> [!TIP]
Expand Down Expand Up @@ -39,23 +39,24 @@ git init --bare store.git
# Setting up Gitalong in your project repository.
# This will clone the store repository in an ignored `.gitalong` folder.
# It will also start tracking a `.gitalong.json` configuration file.
gitalong -C project setup store.git --modify-permissions --tracked-extensions .jpg,.gif,.png --track-uncommitted --update-gitignore --update-hooks
gitalong -C project setup store.git --modify-permissions --tracked-extensions .jpg,.png --track-uncommitted --update-gitignore --update-hooks

# Creating some files.
touch project/untracked.txt
touch project/uncommitted.png
touch project/local.gif
touch project/local.png
touch project/current.jpg
touch project/remote.jpg
touch project/untracked.txt

# Spreading them across branches.
git -C project add untracked.txt
git -C project commit -m "Add untracked.txt"
git -C project add current.jpg
git -C project commit -m "Add current.jpg"
git -C project add remote.jpg
git -C project commit -m "Add remote.jpg"
git -C project push
git -C project reset --hard HEAD^
git -C project add local.gif
git -C project commit -m "Add local.gif"
git -C project add local.png
git -C project commit -m "Add local.png"

# Updating tracked commits with current local changes.
# Because we specified `track_uncommitted`. Uncommitted changes will be stored as sha-less commit.
Expand All @@ -68,119 +69,14 @@ gitalong -C project update
# Each status will show <spread> <filename> <commit> <local-branches> <remote-branches> <host> <author>.
# Spread flags represent where the commit live.
# It will be displayed in the following order:
# <local-uncommitted><local-active-branch><local-other-branch><remote-matching-branch><remote-other-branch><clone-other-branch><clone-matching-branch><clone-uncomitted>
# <mine-uncommitted><mine-active-branch><mine-other-branch><remote-matching-branch><remote-other-branch><other-other-branch><other-matching-branch><other-uncomitted>
# A `+` sign means is true, while a `-` sign means false or unknown.
gitalong -C project status uncommited.jpg local.gif remote.jpg untracked.txt

# If you installed with `--modify-permissions` this will try to make the files writable.
# The command will return and error code of 1 if one ore more of the files cannot be made writable.
gitalong -C project claim uncommited.jpg local.gif remote.jpg untracked.txt
gitalong -C project untracked.txt status uncommited.png local.png current.jpg remote.jpg
```

### Python

```python
import os
import tempfile
import logging

from git.repo import Repo
from gitalong import Repository, RepositoryNotSetup, CommitSpread


def test_example():
"""Testing example code featured in README.md."""
dirname = tempfile.mkdtemp()
logging.info(dirname)

# Creating a dummy project repository and its clone in temp directory.
project = Repo.init(path=os.path.join(dirname, "project.git"), bare=True)
project_clone = project.clone(os.path.join(dirname, "project"))

try:
# This will raise as we never setup that repository with Gitalong.
repository = Repository(project_clone.working_dir)

except RepositoryNotSetup:

# Creating a repository that Gitalong will use to store and share local changes.
# You would normally host this somewhere like GitHub so your entire team has
# access to it.
store = Repo.init(path=os.path.join(dirname, "store.git"), bare=True)

# Setting up Gitalong in your project repository.
# This will clone the registry repository in an ignored `.gitalong` folder.
# It will also start tracking a `.gitalong.json` configuration file.
repository = Repository.setup(
store_url=store.working_dir,
managed_repository=project_clone.working_dir,
modify_permissions=True,
tracked_extensions=[".jpg", ".gif", ".png"],
track_uncommitted=True,
update_gitignore=True,
# Skipping hook update for the test.
update_hooks=False,
)

# Creating some files.
open(os.path.join(project_clone.working_dir, "uncommitted.png"), "w").close()
open(os.path.join(project_clone.working_dir, "local.gif"), "w").close()
open(os.path.join(project_clone.working_dir, "remote.jpg"), "w").close()
open(os.path.join(project_clone.working_dir, "untracked.txt"), "w").close()

# Spreading them across branches.
project_clone.index.add("untracked.txt")
project_clone.index.commit(message="Add untracked.txt")
project_clone.index.add("remote.jpg")
project_clone.index.commit(message="Add remote.jpg")
project_clone.remote().push()
project_clone.git.reset("--hard", "HEAD^")
project_clone.index.add("local.gif")
project_clone.index.commit(message="Add local.gif")

# Updating tracked commits with current local changes. Because we specified
# `track_uncommitted`. Uncommitted changes will be stored as sha-less commit.
repository.update_tracked_commits()

# Update permissions of all files based on track commits. Because
# `modify_permssions` was passed this will update all permissions of tracked files.
# Permission updates currently comes at high performance cost and is not
# recommended.
locally_changed_files = repository.locally_changed_files
for filename in repository.files:
repository.update_file_permissions(filename, locally_changed_files)

# Now we'll get the last commit for our files.
# This could return a dummy commit representing uncommitted changes.
uncommitted_last_commit = repository.get_file_last_commit("uncommitted.png")
local_last_commit = repository.get_file_last_commit("local.gif")
remote_last_commit = repository.get_file_last_commit("remote.jpg")
untracked_last_commit = repository.get_file_last_commit("untracked.txt")

# Getting the commit spreads.
# Spread flags represent where the commit live.
uncommitted_spread = repository.get_commit_spread(uncommitted_last_commit)
local_spread = repository.get_commit_spread(local_last_commit)
remote_spread = repository.get_commit_spread(remote_last_commit)
untracked_spread = repository.get_commit_spread(untracked_last_commit)

assert uncommitted_spread == CommitSpread.MINE_UNCOMMITTED
assert local_spread == CommitSpread.MINE_ACTIVE_BRANCH
assert remote_spread == CommitSpread.REMOTE_MATCHING_BRANCH
assert untracked_spread == (
CommitSpread.REMOTE_MATCHING_BRANCH | CommitSpread.MINE_ACTIVE_BRANCH
)

# Trying to make the files writable.
assert bool(repository.make_file_writable("uncommitted.png")) is False
assert bool(repository.make_file_writable("local.gif")) is False
assert bool(repository.make_file_writable("remote.jpg")) is True
assert bool(repository.make_file_writable("untracked.txt")) is False


if __name__ == "__main__":
test_example()
```
You can find a usage example in [example.py](https://github.com/douglaslassance/gitalong/blob/main/tests/example.py).

## Stores

Expand Down Expand Up @@ -220,21 +116,19 @@ Worth noting that `<ACCESS_KEY>` can be an environment variable such as `$ACCESS

## Development

You can of course use your editor of choice, that said we provide a solid Visual Studio Code setup.

### Setting up

Before starting, you'll have to install all the Python dependencies using the following command.
Setup a Python virtual environment and run the following command.

```shell
pip install --editable .[ci]
python -m venv .venv
source .venv/bin/activate
pip install -e ".[ci]"
```

We recommand you do this in a virtual environment.

### Testing

```python
```shell
pytest - -cov - report = html - -cov = gitalong - -profile - svg
```

Expand Down
9 changes: 5 additions & 4 deletions gitalong/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .__info__ import __version__, __copyright__, __email__, __author__ # noqa: F401
from .enums import CommitSpread # noqa: F401
from .exceptions import RepositoryNotSetup # noqa: F401
from .repository import Repository # noqa: F401
from .__info__ import __version__, __copyright__, __email__, __author__
from .enums import CommitSpread
from .exceptions import RepositoryNotSetup
from .repository import Repository
from .commit import Commit
Loading

0 comments on commit 82a890b

Please sign in to comment.