Skip to content

Commit

Permalink
fix reset about the nocommit problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ffanyt authored Jan 26, 2023
1 parent 6203f0a commit 5eb3d0d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions proj2/gitlet/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,16 @@ public static void rmBranch(String branchName) {
branchFile = join(BRANCH_DIR, branchName);
branchFile.delete();
}
public static void reset(String commitID) {
public static void reset(String commitID) {//要把对应的branch指示的头提前
HEAD = readHEAD();
updateBranch(commitID);
updateWorkingdirByCommit(commitID);
String fullCommitID = updateBranch(commitID);
updateWorkingdirByCommit(fullCommitID);
List stageList = plainFilenamesIn(STAGE_DIR);
for (Object i : stageList) {
File stageFile = join(STAGE_DIR, i.toString());
stageFile.delete();
}
updateHEAD(fullCommitID);
}
private static void checkCurrentBranch(String branchName) {
HEAD_BRANCH = readContentsAsString(HEAD_BRANCH_FILE);
Expand Down Expand Up @@ -388,8 +389,9 @@ public static boolean checkinilization() {
private static String readHEAD() {
return readObject(HEAD_FILE, String.class);
}
private static void updateBranch(String hashCode) {
private static String updateBranch(String hashCode) {
List branchList = plainFilenamesIn(BRANCH_DIR);
HEAD_BRANCH = readContentsAsString(HEAD_BRANCH_FILE);
for (Object i : branchList) {
String name = i.toString();
File branchFILE = join(BRANCH_DIR, name);
Expand All @@ -398,12 +400,15 @@ private static void updateBranch(String hashCode) {
Commit commit = checkCommitID(hashCode);
String fullHashCode = commit.getHashcode();
writeContents(branchFILE, fullHashCode);
return fullHashCode;
} else {
writeContents(branchFILE, hashCode);
return hashCode;
}

}
}
return "";
}
private static void updateHEAD(String hashCode) {
HEAD = hashCode;
Expand Down

0 comments on commit 5eb3d0d

Please sign in to comment.