relax commit out-of-dateness check: consider file content only
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
diff --git a/lib/worktree.c b/lib/worktree.c
index d13a217..1103157 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3299,102 +3299,40 @@ check_ct_out_of_date(struct got_commitable *ct, struct got_repository *repo,
struct got_object_id *head_commit_id)
{
const struct got_error *err = NULL;
- struct got_object_id *id_in_head = NULL, *id = NULL;
+ struct got_object_id *id = NULL;
struct got_commit_object *commit = NULL;
- char *path = NULL;
const char *ct_path = ct->in_repo_path;
while (ct_path[0] == '/')
ct_path++;
- /*
- * Ensure that no modifications were made to files *and their parents*
- * in commits between the file's base commit and the branch head.
- *
- * Checking the parents is important for detecting conflicting tree
- * configurations (files or parent folders might have been moved,
- * deleted, added again, etc.). Such changes need to be merged with
- * local changes before a commit can occur.
- *
- * The implication is that the file's (parent) entry in the root
- * directory must have the same ID in all relevant commits.
- */
if (ct->status != GOT_STATUS_ADD) {
- struct got_object_qid *pid;
- char *slash;
- struct got_object_id *root_entry_id = NULL;
-
/* Trivial case: base commit == head commit */
if (got_object_id_cmp(ct->base_commit_id, head_commit_id) == 0)
return NULL;
-
- /* Compute the path to the root directory's entry. */
- path = strdup(ct_path);
- if (path == NULL) {
- err = got_error_from_errno("strdup");
- goto done;
- }
- slash = strchr(path, '/');
- if (slash)
- *slash = '\0';
-
- err = got_object_open_as_commit(&commit, repo, head_commit_id);
- if (err)
- goto done;
-
- err = got_object_id_by_path(&root_entry_id, repo,
- head_commit_id, path);
- if (err)
- goto done;
-
- pid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
- while (pid) {
- struct got_commit_object *pcommit;
-
- err = got_object_id_by_path(&id, repo, pid->id, path);
- if (err) {
- if (err->code != GOT_ERR_NO_TREE_ENTRY)
- goto done;
- err = NULL;
- break;
- }
-
- err = got_object_id_by_path(&id, repo, pid->id, path);
- if (err)
- goto done;
-
- if (got_object_id_cmp(id, root_entry_id) != 0) {
- err = got_error(GOT_ERR_COMMIT_OUT_OF_DATE);
- break;
- }
-
- if (got_object_id_cmp(pid->id, ct->base_commit_id) == 0)
- break; /* all relevant commits scanned */
-
- err = got_object_open_as_commit(&pcommit, repo,
- pid->id);
- if (err)
+ /*
+ * Ensure file content which local changes were based
+ * on matches file content in the branch head.
+ */
+ err = got_object_id_by_path(&id, repo, head_commit_id, ct_path);
+ if (err) {
+ if (err->code != GOT_ERR_NO_TREE_ENTRY)
goto done;
-
- got_object_commit_close(commit);
- commit = pcommit;
- pid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(
- commit));
- }
+ err = got_error(GOT_ERR_COMMIT_OUT_OF_DATE);
+ goto done;
+ } else if (got_object_id_cmp(id, ct->base_blob_id) != 0)
+ err = got_error(GOT_ERR_COMMIT_OUT_OF_DATE);
} else {
/* Require that added files don't exist in the branch head. */
- err = got_object_id_by_path(&id_in_head, repo, head_commit_id,
- ct_path);
+ err = got_object_id_by_path(&id, repo, head_commit_id, ct_path);
if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
goto done;
- err = id_in_head ? got_error(GOT_ERR_COMMIT_OUT_OF_DATE) : NULL;
+ err = id ? got_error(GOT_ERR_COMMIT_OUT_OF_DATE) : NULL;
}
done:
if (commit)
got_object_commit_close(commit);
- free(id_in_head);
free(id);
- free(path);
return err;
}
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 6764523..6eabac8 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -1459,6 +1459,10 @@ function test_update_bumps_base_commit_id {
return 1
fi
+ echo "psi changed zeta with git" > $testroot/repo/epsilon/zeta
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "changing zeta with git"
+
echo "modified zeta" > $testroot/wt/epsilon/zeta
(cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
2> $testroot/stderr)
@@ -1475,6 +1479,8 @@ function test_update_bumps_base_commit_id {
(cd $testroot/wt && got update > $testroot/stdout)
+ echo "U epsilon/psi" > $testroot/stdout.expected
+ echo "C epsilon/zeta" >> $testroot/stdout.expected
echo -n "Updated to commit " >> $testroot/stdout.expected
git_show_head $testroot/repo >> $testroot/stdout.expected
echo >> $testroot/stdout.expected
@@ -1486,6 +1492,9 @@ function test_update_bumps_base_commit_id {
return 1
fi
+ # resolve conflict
+ echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
+
(cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
local head_rev=`git_show_head $testroot/repo`