Skip to content

Commit

Permalink
fix bug in branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ffanyt authored Jan 26, 2023
1 parent 77e0b6e commit e5d96a8
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions proj2/gitlet/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void initHEAD() {
HEAD = currentCommit.getHashcode();
writeObject(HEAD_FILE, HEAD);
HEAD_BRANCH = "master";
writeContents(HEAD_BRANCH_FILE, HEAD_FILE);
writeContents(HEAD_BRANCH_FILE, HEAD_BRANCH);
}
public static void initCommit() {
currentCommit = new Commit();
Expand Down Expand Up @@ -157,29 +157,22 @@ public static void find(String ms) {
}
public static void status() {
HEAD = readHEAD();
//String temp = HEAD;
//System.out.println(temp);
HEAD_BRANCH = readContentsAsString(HEAD_BRANCH_FILE);
Commit curCommit = Commit.readCommit(HEAD);
System.out.println("=== Branches ===");
List branchList = plainFilenamesIn(BRANCH_DIR);
if (branchList.size() != 0) {
System.out.println("*" + HEAD_BRANCH);
for (Object i : branchList) {
String branchName = i.toString();
File branchDir = join(BRANCH_DIR, branchName);
String branchHeadHash = readContentsAsString(branchDir);
//String branchHeadHash = readObject(branchDir, String.class);
if (HEAD.equals(branchHeadHash)) {
System.out.println("*" + branchName);
break;
}
}
for (Object i : branchList) {
String branchName = i.toString();
File branchDir = join(BRANCH_DIR, branchName);
String branchHeadHash = readContentsAsString(branchDir);
if (!HEAD.equals(branchHeadHash)) {
if (!branchName.equals(HEAD_BRANCH)) {
System.out.println(branchName);
}
// if (!HEAD.equals(branchHeadHash)) {
// System.out.println(branchName);
// }
}
}
System.out.println();
Expand Down Expand Up @@ -214,7 +207,7 @@ public static void checkout(String cm, int select) {
File branchFILE = join(BRANCH_DIR, cm);
String branchInfo = readContentsAsString(branchFILE);
updateWorkingdirByCommit(branchInfo);
updateBranch(cm);
updateHeadBranch(cm);
} else {
Commit curCommit = Commit.readCommit(HEAD);
rewriteFileByCommit(curCommit, cm);
Expand Down

0 comments on commit e5d96a8

Please sign in to comment.