commit 5c99ca9fe447187c440a413772fb14201f30a1d2 from: Stefan Sperling date: Wed Mar 27 06:41:37 2019 UTC fix behaviour when 'got add' is used twice commit - 4dfb2f0f5fc9cda1a29a92fc304c67d15e269014 commit + 5c99ca9fe447187c440a413772fb14201f30a1d2 blob - 45ca7be94cdab1bb2773b7db0bd0c221c06b1516 blob + f03a291f54519d33c2b6fe8f0a15db38ae579f7f --- lib/worktree.c +++ lib/worktree.c @@ -1618,10 +1618,6 @@ got_worktree_schedule_add(struct got_worktree *worktre err = got_path_skip_common_ancestor(&relpath, got_worktree_get_root_path(worktree), ondisk_path); - if (err) - goto done; - - err = got_fileindex_entry_alloc(&ie, ondisk_path, relpath, NULL, NULL); if (err) goto done; @@ -1648,6 +1644,15 @@ got_worktree_schedule_add(struct got_worktree *worktre if (err) goto done; + if (got_fileindex_entry_get(fileindex, relpath) != NULL) { + err = got_error_set_errno(EEXIST); + goto done; + } + + err = got_fileindex_entry_alloc(&ie, ondisk_path, relpath, NULL, NULL); + if (err) + goto done; + err = got_fileindex_entry_add(fileindex, ie); if (err) goto done; @@ -1681,7 +1686,7 @@ done: err = got_error_from_errno(); free(new_fileindex_path); } - if (!ie_added) + if (ie && !ie_added) got_fileindex_entry_free(ie); if (fileindex) got_fileindex_free(fileindex); blob - 10641619c123c78416b7911a5d83d6a65a2b78e7 blob + 89d8177e1a437bbfc5b5f2c4146d7b266f1ffcbc --- regress/cmdline/add.sh +++ regress/cmdline/add.sh @@ -39,4 +39,34 @@ function test_add_basic { test_done "$testroot" "$ret" } +function test_double_add { + local testroot=`test_init double_add` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret="$?" + if [ "$ret" != "0" ]; then + test_done "$testroot" "$ret" + return 1 + fi + + echo "new file" > $testroot/wt/foo + (cd $testroot/wt && got add foo > /dev/null) + + echo "got: File exists" > $testroot/stderr.expected + (cd $testroot/wt && got add foo 2> $testroot/stderr) + ret="$?" + if [ "$ret" == "0" ]; then + echo "got add command succeeded unexpectedly" >&2 + test_done "$testroot" 1 + fi + + cmp $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi + test_done "$testroot" "$ret" +} + run_test test_add_basic +run_test test_double_add