Skip to content

Commit

Permalink
Fix the checkout for files. Revise the format of toString() of Commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsrigo committed Oct 4, 2022
1 parent 3f87827 commit f3272c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gitlet/Commit.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public String getSha(){
}
@Override
public String toString() {
return "\n===\n"
return "===\n"
+ "commit " + this.getSha() + '\n'
+ "Date: " + this.timestamp + '\n'
+ this.message + '\n'
+ "Tracking Files: " + this.ids.keySet();
+ this.message + '\n';
// + "Tracking Files: " + this.ids.keySet();
}
}
8 changes: 4 additions & 4 deletions gitlet/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ public void checkoutFile(String commitId, String filename){
}

File cwdFile = join(CWD, filename);
String currentSha = getCurrentCommit().getFilesha(filename);
boolean HasCurrentFile = (currentSha != null);
String cwdSha = sha1((Object) readContents(cwdFile));
boolean HasCurrentFile = (sourceSha != null);
if (cwdFile.exists() && !HasCurrentFile){
System.out.println("There is an untracked file in the way; delete it, or add and commit it first.");
System.exit(0);
}
if (sourceSha != currentSha) {
if (!cwdSha.equals(sourceSha)) {
writeContents(cwdFile, (Object) readContents(sourceFile));
}
removeStage(join(STAGING_DIR, filename));
Expand Down Expand Up @@ -392,7 +392,7 @@ private void clearStagingArea(){
*/
private void removeStage(File filename) {
if (!stagingArea.contains(filename)) {
System.out.println(filename + " was already removed.");
// System.out.println(filename + " was already removed.");
return;
}
stagingArea.remove(filename);
Expand Down

0 comments on commit f3272c4

Please sign in to comment.