forked from jreiner16/GitStage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitWrapper.java
More file actions
71 lines (65 loc) · 2.39 KB
/
GitWrapper.java
File metadata and controls
71 lines (65 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.IOException;
public class GitWrapper {
/**
* Initializes a new Git repository.
* This method creates the necessary directory structure
* and initial files (index, HEAD) required for a Git repository.
*/
public void init() {
try {
Git.initializeRepo("ProjectFolder");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Stages a file for the next commit.
* This method adds a file to the index file.
* If the file does not exist, it throws an IOException.
* If the file is a directory, it throws an IOException.
* If the file is already in the index, it does nothing.
* If the file is successfully staged, it creates a blob for the file.
* @param filePath The path to the file to be staged.
* @throws IOException
*/
public void add(String filePath) throws IOException {
if (Git.indexFile(filePath, "ProjectFolder"));
Git.makeBlob(filePath, "ProjectFolder");
};
/**
* Creates a commit with the given author and message.
* It should capture the current state of the repository by building trees based on the index file,
* writing the tree to the objects directory,
* writing the commit to the objects directory,
* updating the HEAD file,
* and returning the commit hash.
*
* The commit should be formatted as follows:
* tree: <tree_sha>
* parent: <parent_sha>
* author: <author>
* date: <date>
* summary: <summary>
*
* @param author The name of the author making the commit.
* @param message The commit message describing the changes.
* @return The SHA1 hash of the new commit.
* @throws IOException
*/
public String commit(String author, String message) throws IOException {
return Git.buildCommit("author", "message");
};
/**
* EXTRA CREDIT:
* Checks out a specific commit given its hash.
* This method should read the HEAD file to determine the "checked out" commit.
* Then it should update the working directory to match the
* state of the repository at that commit by tracing through the root tree and
* all its children.
*
* @param commitHash The SHA1 hash of the commit to check out.
*/
public void checkout(String commitHash) {
// to-do: implement functionality here
};
}