-
Notifications
You must be signed in to change notification settings - Fork 0
Check wit 1 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RuthMahallaMilano
wants to merge
75
commits into
main
Choose a base branch
from
check-wit-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Check wit 1 #2
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 0040983
Delete branch_req.txt
RuthMahallaMilano 4633d2b
Delete wit_checks.py
RuthMahallaMilano ff92db7
Delete .gitignore
RuthMahallaMilano 56528cc
Delete .name
RuthMahallaMilano dc5a3f7
Delete .gitignore
RuthMahallaMilano 9fd59cc
Delete profiles_settings.xml
RuthMahallaMilano eb37fe1
Delete misc.xml
RuthMahallaMilano 4bad382
Delete add_171.py
RuthMahallaMilano f57cc01
Delete wit_project.iml
RuthMahallaMilano 039dace
Delete vcs.xml
RuthMahallaMilano f1cdbe8
Delete modules.xml
RuthMahallaMilano c207687
Delete commit.py
RuthMahallaMilano 36d1e90
Delete checkout.py
RuthMahallaMilano 0b7910e
Delete init.py
RuthMahallaMilano 559e3b1
Delete wit.py
RuthMahallaMilano 16a2ab0
gitignore
RuthMahallaMilano 37687c3
finish
RuthMahallaMilano 5140b92
finish branch
RuthMahallaMilano b79d2a0
finish branch
RuthMahallaMilano e51e079
All wit files after changes
RuthMahallaMilano 17531f7
All wit files after changes
RuthMahallaMilano 38baf1a
finished conftest, test_init
RuthMahallaMilano 33097b9
start test_add. not finished
RuthMahallaMilano 6a78f96
add graph to wit file
RuthMahallaMilano 6a833b3
fix bugs
RuthMahallaMilano 3f9b4ff
status almost fixed. wrote problem in the file
RuthMahallaMilano 02bb584
add status problem description
RuthMahallaMilano 4a08aaa
problems in 2 functions
RuthMahallaMilano 974bff1
commit before check. problems in status
RuthMahallaMilano 1ec54f3
commit before check. problems in status
RuthMahallaMilano 660cf90
add graph, fix commit and checkout
RuthMahallaMilano 9d9d2a6
fix project files
RuthMahallaMilano 2e20891
change init function - no arguments
RuthMahallaMilano 5c33a6b
add merge file, add click function to wit file
RuthMahallaMilano 75e1ffa
merge done. todo: two parents to a commit
RuthMahallaMilano a6b3a44
finished status. merge doesnt work correctly
RuthMahallaMilano 7fe4fd5
almost finished. todo: merge- change files in repo
RuthMahallaMilano 1d8af8b
finished
RuthMahallaMilano 66c3466
isort & black
RuthMahallaMilano ad1b992
change to utils. add isort.cfg
RuthMahallaMilano 5d53930
run isort
RuthMahallaMilano 0ceab02
run black
RuthMahallaMilano 5f1bd1e
fixed files
RuthMahallaMilano 9461e0b
fix get_branches_commits
RuthMahallaMilano bca39e6
remove idea\.name, add .idea to gitignore
RuthMahallaMilano ea1eee4
change init.py- uses utils functions
RuthMahallaMilano b6da7f1
fix imports. done: conftest, test_init, test_add
RuthMahallaMilano 900039e
done: test_commit
RuthMahallaMilano 46fece9
gitignore
RuthMahallaMilano f1faea3
add tests
RuthMahallaMilano 4370aea
.
RuthMahallaMilano ae8b826
done: test_graph. fix other tests and graph return
RuthMahallaMilano 42bd93f
add test_branch
RuthMahallaMilano f0555d1
add test_checkout
RuthMahallaMilano 484bd0c
finished tests: branch, checkout, commit, graph
RuthMahallaMilano fbdcc6d
add test_merge, fix raise-merge-error in merge
RuthMahallaMilano a3413de
delete no common commit error pessibility
RuthMahallaMilano 629f796
done: test_merge
RuthMahallaMilano 09ec3c5
done: test_status. adjust also other files
RuthMahallaMilano b34ad5f
isort & black
RuthMahallaMilano 1dda30a
change test_folder
RuthMahallaMilano 94df464
fix: merge, test_merge
RuthMahallaMilano 01e9628
finished tests and fixed project files
RuthMahallaMilano d7a56c1
fix requirements
RuthMahallaMilano b87e7e2
Update project/checkout.py
RuthMahallaMilano c431268
Update project/utils.py
RuthMahallaMilano eed7d9c
fix files after review
RuthMahallaMilano c40949d
fix files
RuthMahallaMilano c70263a
conflicts resolved
RuthMahallaMilano f50cf1e
Create README.md
RuthMahallaMilano f8050b2
Update README.md
RuthMahallaMilano f48c2cf
Update README.md
RuthMahallaMilano b735ae5
Update README.md
RuthMahallaMilano 3960fbc
Update README.md
RuthMahallaMilano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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) > 0There was a problem hiding this comment.
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?