Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6ba6844
The project's initial commit
RuthMahallaMilano Jan 5, 2022
0040983
Delete branch_req.txt
RuthMahallaMilano Jan 5, 2022
4633d2b
Delete wit_checks.py
RuthMahallaMilano Jan 5, 2022
ff92db7
Delete .gitignore
RuthMahallaMilano Jan 5, 2022
56528cc
Delete .name
RuthMahallaMilano Jan 5, 2022
dc5a3f7
Delete .gitignore
RuthMahallaMilano Jan 5, 2022
9fd59cc
Delete profiles_settings.xml
RuthMahallaMilano Jan 5, 2022
eb37fe1
Delete misc.xml
RuthMahallaMilano Jan 5, 2022
4bad382
Delete add_171.py
RuthMahallaMilano Jan 5, 2022
f57cc01
Delete wit_project.iml
RuthMahallaMilano Jan 5, 2022
039dace
Delete vcs.xml
RuthMahallaMilano Jan 5, 2022
f1cdbe8
Delete modules.xml
RuthMahallaMilano Jan 5, 2022
c207687
Delete commit.py
RuthMahallaMilano Jan 5, 2022
36d1e90
Delete checkout.py
RuthMahallaMilano Jan 5, 2022
0b7910e
Delete init.py
RuthMahallaMilano Jan 5, 2022
559e3b1
Delete wit.py
RuthMahallaMilano Jan 5, 2022
16a2ab0
gitignore
RuthMahallaMilano Jan 9, 2022
37687c3
finish
RuthMahallaMilano Jan 10, 2022
5140b92
finish branch
RuthMahallaMilano Jan 10, 2022
b79d2a0
finish branch
RuthMahallaMilano Jan 10, 2022
e51e079
All wit files after changes
RuthMahallaMilano Jan 10, 2022
17531f7
All wit files after changes
RuthMahallaMilano Jan 10, 2022
38baf1a
finished conftest, test_init
RuthMahallaMilano Feb 23, 2022
33097b9
start test_add. not finished
RuthMahallaMilano Feb 23, 2022
6a78f96
add graph to wit file
RuthMahallaMilano Feb 23, 2022
6a833b3
fix bugs
RuthMahallaMilano Feb 25, 2022
3f9b4ff
status almost fixed. wrote problem in the file
RuthMahallaMilano Feb 27, 2022
02bb584
add status problem description
RuthMahallaMilano Feb 28, 2022
4a08aaa
problems in 2 functions
RuthMahallaMilano Feb 28, 2022
974bff1
commit before check. problems in status
RuthMahallaMilano Feb 28, 2022
1ec54f3
commit before check. problems in status
RuthMahallaMilano Feb 28, 2022
660cf90
add graph, fix commit and checkout
RuthMahallaMilano Mar 1, 2022
9d9d2a6
fix project files
RuthMahallaMilano Mar 9, 2022
2e20891
change init function - no arguments
RuthMahallaMilano Mar 9, 2022
5c33a6b
add merge file, add click function to wit file
RuthMahallaMilano Mar 10, 2022
75e1ffa
merge done. todo: two parents to a commit
RuthMahallaMilano Mar 14, 2022
a6b3a44
finished status. merge doesnt work correctly
RuthMahallaMilano Mar 14, 2022
7fe4fd5
almost finished. todo: merge- change files in repo
RuthMahallaMilano Mar 15, 2022
1d8af8b
finished
RuthMahallaMilano Mar 15, 2022
66c3466
isort & black
RuthMahallaMilano Mar 20, 2022
ad1b992
change to utils. add isort.cfg
RuthMahallaMilano Mar 20, 2022
5d53930
run isort
RuthMahallaMilano Mar 20, 2022
0ceab02
run black
RuthMahallaMilano Mar 20, 2022
5f1bd1e
fixed files
RuthMahallaMilano Mar 21, 2022
9461e0b
fix get_branches_commits
RuthMahallaMilano Mar 21, 2022
bca39e6
remove idea\.name, add .idea to gitignore
RuthMahallaMilano Mar 21, 2022
ea1eee4
change init.py- uses utils functions
RuthMahallaMilano Mar 21, 2022
b6da7f1
fix imports. done: conftest, test_init, test_add
RuthMahallaMilano Mar 22, 2022
900039e
done: test_commit
RuthMahallaMilano Mar 22, 2022
46fece9
gitignore
RuthMahallaMilano Mar 22, 2022
f1faea3
add tests
RuthMahallaMilano Mar 22, 2022
4370aea
.
RuthMahallaMilano Mar 22, 2022
ae8b826
done: test_graph. fix other tests and graph return
RuthMahallaMilano Mar 22, 2022
42bd93f
add test_branch
RuthMahallaMilano Mar 22, 2022
f0555d1
add test_checkout
RuthMahallaMilano Mar 22, 2022
484bd0c
finished tests: branch, checkout, commit, graph
RuthMahallaMilano Mar 23, 2022
fbdcc6d
add test_merge, fix raise-merge-error in merge
RuthMahallaMilano Mar 23, 2022
a3413de
delete no common commit error pessibility
RuthMahallaMilano Mar 23, 2022
629f796
done: test_merge
RuthMahallaMilano Mar 23, 2022
09ec3c5
done: test_status. adjust also other files
RuthMahallaMilano Mar 23, 2022
b34ad5f
isort & black
RuthMahallaMilano Mar 23, 2022
1dda30a
change test_folder
RuthMahallaMilano Mar 24, 2022
94df464
fix: merge, test_merge
RuthMahallaMilano Mar 24, 2022
01e9628
finished tests and fixed project files
RuthMahallaMilano Mar 25, 2022
d7a56c1
fix requirements
RuthMahallaMilano Mar 25, 2022
b87e7e2
Update project/checkout.py
RuthMahallaMilano Apr 12, 2022
c431268
Update project/utils.py
RuthMahallaMilano Apr 13, 2022
eed7d9c
fix files after review
RuthMahallaMilano Apr 25, 2022
c40949d
fix files
RuthMahallaMilano Apr 25, 2022
c70263a
conflicts resolved
RuthMahallaMilano Apr 25, 2022
f50cf1e
Create README.md
RuthMahallaMilano Apr 27, 2022
f8050b2
Update README.md
RuthMahallaMilano Apr 27, 2022
f48c2cf
Update README.md
RuthMahallaMilano Apr 27, 2022
b735ae5
Update README.md
RuthMahallaMilano May 15, 2022
3960fbc
Update README.md
RuthMahallaMilano May 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .coverage
Binary file not shown.
43 changes: 5 additions & 38 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
Expand All @@ -26,81 +22,52 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
Expand All @@ -109,21 +76,21 @@ venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

json
# Pyre type checker
.pyre/
.wit
/.idea/
wit_exercises
\__pycache__
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile=black
known_first_party=add,branch,checkout,commit,errors,graph,init,merge,status,utils,wit
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Wit

Wit is a version control system that simulates Git's behavior, which includes commands such as add, branch, commit, status, and checkout. I also implemented a basic merge and graph, which is a kind of graphical log.

In order to run Wit, follow the next steps:
1. git clone the repo
2. create a vitrual environnment
3. install the requirements fron requirenents.txt file
4. install the packeges of the project (using "pip install -e .")
5. go to the folder you want to beckup and set as a Wit repository
6. to start a repository, run "python <path>\wit\project\wit.py init"
7. you can always run "python <path>\wit\project\wit.py -- help" to see all possible commands
Empty file added project/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions project/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import shutil
from pathlib import Path
from typing import Union

from project.errors import WitError
from project.utils import get_repository_path, get_staging_area_path


def add_function(path_to_add: Union[str, Path]) -> None:
path = Path(path_to_add).resolve()
repository = get_repository_path(path)
if not repository:
raise WitError("<.wit> file not found")
copy_to_staging_area(path, repository)


def copy_to_staging_area(path: Path, repository: Path) -> None:
staging_area_path = get_staging_area_path(repository)
relative_path = path.relative_to(repository)
if path.is_dir():
copy_dir_to_staging_area(staging_area_path, path, relative_path)
else:
copy_file_to_staging_area(staging_area_path, path, relative_path)


def copy_file_to_staging_area(
staging_area_path: Path, path: Path, relative_path: Path
) -> None:
parents_path = relative_path.parents[0]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

האם בהכרח יש איבר 0? אם כן, אולי שווה להצהיר על זה שורה לפני: assert relative_path.parents או אפילו באופן מובהק יותר: assert len(relative_path.parents) > 0

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ממה שאני מבינה זה לפי ההגדרה של PurePath.parents - האיבר ה-0 נותן את כל האבות של הקובץ. אם אין- זה נותן פשוט ".", אז זה עדיין קיים בעצם. ואז השאלה אם יש parents_path.name (שורה אח"כ).
האם עדיין יש טעם ל- assert?

destination = staging_area_path
if parents_path.name:
destination = staging_area_path / parents_path
destination.mkdir(parents=True, exist_ok=True)
shutil.copy2(path, destination)


def copy_dir_to_staging_area(
staging_area_path: Path, path: Path, relative_path: Path
) -> None:
destination = staging_area_path / relative_path
if destination.exists():
shutil.rmtree(destination)
shutil.copytree(path, destination)
26 changes: 26 additions & 0 deletions project/branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pathlib import Path

from project.errors import BranchExistsError, BranchNotCreatedError, WitError
from project.utils import (
get_commits_by_branches,
get_head_reference,
get_references_path,
get_repository_path,
)


def branch_function(name: str) -> None:
repository = get_repository_path(Path.cwd())
if not repository:
raise WitError("<.wit> file not found")
references_file = get_references_path(repository)
if not references_file.exists():
raise BranchNotCreatedError(
"No commit was done yet. Can't create a new branch."
)
existing_branches = get_commits_by_branches(references_file)
if name in existing_branches:
raise BranchExistsError(f"Branch {name} already exists.")
commit_id = get_head_reference(repository)
with references_file.open("a") as ref_file:
ref_file.write(f"\n{name}={commit_id}")
79 changes: 79 additions & 0 deletions project/checkout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import shutil
from pathlib import Path
from typing import Union

from project.errors import BranchDoesntExistError, WitError
from project.utils import (
get_activated_path,
get_all_files_in_directory_and_subs,
get_commit_id_of_branch,
get_commit_path,
get_references_path,
get_repository_path,
get_staging_area_path,
raise_for_unsaved_work,
)


def checkout_function(commit_id_or_branch: str) -> None:
repository = get_repository_path(Path.cwd())
if not repository:
raise WitError("<.wit> file not found")
raise_for_unsaved_work(repository)
references_file = get_references_path(repository)
commit_id = get_commit_id_of_branch(
repository, commit_id_or_branch, references_file
)
if not commit_id:
raise BranchDoesntExistError("Branch doesn't exist.")
if commit_id != commit_id_or_branch:
write_activated(commit_id_or_branch, repository)
else:
write_activated("", repository)
Comment thread
RuthMahallaMilano marked this conversation as resolved.
commit_path = get_commit_path(repository, commit_id)
update_files_in_main_folder(commit_path, repository)
update_head_in_references_file(commit_id, references_file)
staging_area_path = get_staging_area_path(repository)
update_staging_area_folder(staging_area_path, commit_path)


def write_activated(commit_id_or_branch: str, repository: Path) -> None:
activated_path = get_activated_path(repository)
activated_path.write_text(commit_id_or_branch)


def update_head_in_references_file(commit_id: str, references_file: Path) -> None:
with references_file.open() as file:
file.readline()
branches_txt = file.read()
references_file.write_text(f"HEAD={commit_id}\n{branches_txt}")


def update_files_in_main_folder(
commit_path: Union[str, Path], repository: Path
) -> None:
files_committed = get_all_files_in_directory_and_subs(commit_path)
for committed_file in files_committed:
path_in_commit = commit_path / committed_file
path_in_repository = repository / committed_file
update_file_in_repository(path_in_commit, path_in_repository)


def update_file_in_repository(path_in_commit: Path, path_in_repository: Path) -> None:
if path_in_commit.is_file():
content = path_in_commit.read_text()
path_in_repository.write_text(content)


def update_staging_area_folder(staging_area_path: Path, commit_path: Path) -> None:
for file_or_dir in Path(staging_area_path).iterdir():
if file_or_dir.is_file():
file_or_dir.unlink()
else:
shutil.rmtree(file_or_dir)
for file in Path(commit_path).iterdir():
rel_path = Path(file).relative_to(commit_path)
if file.is_file():
shutil.copy2(file, staging_area_path / rel_path)
else:
shutil.copytree(file, staging_area_path / rel_path)
Loading