A robust, extensible version control system implementation in Java that provides core version control functionality including file tracking, versioning, diffing, and merge conflict resolution.
-
File Management
- Track and Untrack files
- Monitor file status changes (modified, deleted, staged)
- Support for binary and text files
- Automatic file hash calculation and verification
-
Version Control
- Create versions with commit messages
- Maintain version history
- Revert to previous versions
- Track version metadata (author, timestamp, file hashes)
-
Diff Generation
- Line-by-line diff analysis
- Support for additions, deletions, and modifications
- Efficient diff algorithm using dynamic programming
- Generate diffs between versions or working changes
-
Merge Handling
- Detect and resolve merge conflicts
- Multiple conflict resolution strategies (keep source, keep target, custom)
- Automatic merging for non-conflicting changes
- Detailed conflict information tracking
The system is built using a modular architecture with clear separation of concerns:
VersionControlSystem: Main entry point and coordinatorFileTracker: Handles file status monitoring and trackingVersionManager: Manages version creation and historyDiffGenerator: Generates and compares file differencesMergeHandler: Handles merge operations and conflict resolution
Trackable: File tracking operationsVersionable: Version management operationsDiffable: Diff generation operationsMergeable: Merge handling operationsUploadable: File upload operations
VersionInfo: Version metadata and file hashesFileMetadata: File tracking informationChangedLines: Diff informationConflictInfo: Merge conflict detailsLineChange: Individual line modifications
- Java 23 or higher
- IntelliJ IDEA (Community or Ultimate Edition)
- Clone the repository:
git clone https://github.com/yourusername/vcs.git-
Open the project in IntelliJ IDEA:
- Launch IntelliJ IDEA
- Select
File -> Open - Navigate to the cloned repository directory
- Click OK to open the project
- Wait for IntelliJ to finish importing and indexing the project
-
Configure Project SDK:
- Right-click the project root in the Project view
- Select
Module Settings(F4) - Under
Project, ensure the Project SDK is set to Java 17 or higher - Click OK to apply the changes
-
Build the project:
- Select
Build -> Build Projector press Ctrl+F9 (⌘F9 on macOS)
- Select
- Initialize a new VCS repository:
VersionControlSystem vcs = new VersionControlSystem("/path/to/repository");- Track files:
vcs.trackFile("myfile.txt");- Create a version:
String versionId = vcs.createVersion("Initial commit");- Generate diff:
DiffResult diff = vcs.getDiffGenerator().getDiff("oldVersion", "newVersion");- Handle merge conflicts:
boolean merged = vcs.getMergeHandler().merge("sourceVersion", "targetVersion");
if (!merged) {
List<ConflictInfo> conflicts = vcs.getMergeHandler().getConflicts();
// Handle conflicts
}The system uses a hierarchical exception system:
VCSException: Base exception classFileOperationException: File-related errorsVersionException: Version-related errorsMergeConflictException: Merge-related errors
Each exception type includes specific subclasses for detailed error handling.
The project includes comprehensive tests:
- Unit tests for all components
- Integration tests for workflows
- Concurrency tests
- Edge case handling
- Error condition testing
Run tests using:
- Right-click on the
testdirectory in the Project view - Select
Run 'All Tests' - Or use the keyboard shortcut Ctrl+Shift+F10 (⌘Shift+F10 on macOS)
- Observer Pattern: File change notifications
- Strategy Pattern: Diff algorithms and merge strategies
- Factory Pattern: Exception creation
- Builder Pattern: Version creation
- Command Pattern: File operations
- The diff algorithm is inspired by the Myers diff algorithm
- File hashing uses SHA-256 for content verification
- Conflict resolution approach based on modern VCS systems