-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHead.java
More file actions
41 lines (32 loc) · 1.13 KB
/
Head.java
File metadata and controls
41 lines (32 loc) · 1.13 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
import java.io.IOException;
public class Head extends KeyValue{
public final String key = "HEAD";
public static String getCommitKey() throws Exception {
String HEADvalue = new String(getValue("HEAD"));
if(HEADvalue.startsWith("C")){
return HEADvalue.substring(8);
}else{
return Branch.getCommitKey(HEADvalue);
}
}
public Head(String StringValue) throws IOException {
this.value = StringValue.getBytes();
setKVfileHard();
}
public static void checkoutBranch(String branchKey) throws Exception {
new Head(branchKey);
Checkout.checkCommit(Branch.getCommitKey(branchKey));
}
public static void checkoutCommit(String commitKey) throws Exception {
new Head(commitKey);
Checkout.checkCommit(commitKey);
}
public static void update(String newCommitKey) throws Exception {
String oldHeadValue = new String(getValue("HEAD"));
if(oldHeadValue.startsWith("C")){
new Head(newCommitKey);
}else{
new Branch(oldHeadValue.substring(1), newCommitKey);
}
}
}