Commit Diff


commit - eecfbcd1f57266e4d9f0d6a45e2cd968aa527630
commit + 144ad43a62dc0c19deba51bdf919dfc775155db9
blob - dd167105ba3b5b1500f5da9dd81752f9c0fea4de
blob + 0e4c7a09295cab79334a01739595d7d5ba886c58
--- lib/worktree.c
+++ lib/worktree.c
@@ -416,6 +416,12 @@ add_file_on_disk(struct got_worktree *worktree, struct
 	if (asprintf(&ondisk_path, "%s/%s", worktree->root_path,
 	    apply_path_prefix(worktree, path)) == -1)
 		return got_error_from_errno();
+
+	entry = got_fileindex_entry_get(fileindex,
+	    apply_path_prefix(worktree, path));
+	if (entry && memcmp(entry->commit_sha1, worktree->base_commit_id->sha1,
+	    SHA1_DIGEST_LENGTH) == 0)
+		return NULL;
 
 	fd = open(ondisk_path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW,
 	    GOT_DEFAULT_FILE_MODE);
@@ -462,8 +468,6 @@ add_file_on_disk(struct got_worktree *worktree, struct
 
 	fsync(fd);
 
-	entry = got_fileindex_entry_get(fileindex,
-	    apply_path_prefix(worktree, path));
 	if (entry)
 		err = got_fileindex_entry_update(entry, ondisk_path,
 		    blob->id.sha1, worktree->base_commit_id->sha1);