commit - 4f2494e6cd4d608eb7e5b673896c934480b92fca
commit + 8b13ce36c3571db545dcba7fe278009d7214dace
blob - 070abf5e70ee40678c56bbc774db1f203fa653db
blob + c04d60e4c5a3d302bd5b1d211fdc51cbcf5b21ed
--- lib/worktree.c
+++ lib/worktree.c
struct got_object_id base_commit_id;
struct got_object_id *base_commit_idp = NULL;
char *in_repo_path = NULL, *p;
+
+ if (status == GOT_STATUS_UNVERSIONED)
+ return NULL;
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
struct got_fileindex_entry *ie;
char *ondisk_path = NULL, *path_content = NULL;
uint32_t stage;
+
+ if (status == GOT_STATUS_UNVERSIONED)
+ return NULL;
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
- return got_error_path(relpath, GOT_ERR_BAD_PATH);
+ return got_error_path(relpath, GOT_ERR_FILE_STATUS);
if (asprintf(&ondisk_path, "%s/%s", a->worktree->root_path, relpath)
== -1)
blob - 9ef34a4c6457e4c828e91308a00f248632f7ef1d
blob + ee91795f5118fb2597cd411245f9a16513e8d572
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
test_done "$testroot" "$ret"
}
+function test_stage_unversioned {
+ local testroot=`test_init stage_unversioned`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified file" > $testroot/wt/alpha
+ touch $testroot/wt/unversioned-file
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+ echo "M alpha" > $testroot/stdout.expected
+ echo "? unversioned-file" >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got stage > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got stage command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo " M alpha" > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified file again" > $testroot/wt/alpha
+
+ (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
+ 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got stage command succeed unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo "got: no changes to stage" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ fi
+ test_done "$testroot" "$ret"
+
+}
+
function test_stage_list {
local testroot=`test_init stage_list`
run_test test_stage_basic
run_test test_stage_no_changes
+run_test test_stage_unversioned
run_test test_stage_list
run_test test_stage_conflict
run_test test_stage_out_of_date
blob - 9c6d712c170e967cce17f30f21f7152824868767
blob + 3d3129eb97ae9831e602fef7d3d3c52b2c78938e
--- regress/cmdline/unstage.sh
+++ regress/cmdline/unstage.sh
test_done "$testroot" "$ret"
}
+function test_unstage_unversioned {
+ local testroot=`test_init unstage_unversioned`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified file" > $testroot/wt/alpha
+ (cd $testroot/wt && got rm beta > /dev/null)
+ echo "new file" > $testroot/wt/foo
+ (cd $testroot/wt && got add foo > /dev/null)
+
+ echo ' M alpha' > $testroot/stdout.expected
+ echo ' D beta' >> $testroot/stdout.expected
+ echo ' A foo' >> $testroot/stdout.expected
+ (cd $testroot/wt && got stage > /dev/null)
+
+ touch $testroot/wt/unversioned-file
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+ echo ' M alpha' > $testroot/stdout.expected
+ echo ' D beta' >> $testroot/stdout.expected
+ echo ' A foo' >> $testroot/stdout.expected
+ echo "? unversioned-file" >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got unstage > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got unstage command failed unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo 'G alpha' > $testroot/stdout.expected
+ echo 'D beta' >> $testroot/stdout.expected
+ echo 'G foo' >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got stage > /dev/null)
+
+ # unstaging an unversioned path is a no-op
+ (cd $testroot/wt && got unstage unversioned > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got unstage command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo ' M alpha' > $testroot/stdout.expected
+ echo ' D beta' >> $testroot/stdout.expected
+ echo ' A foo' >> $testroot/stdout.expected
+ echo "? unversioned-file" >> $testroot/stdout.expected
+ (cd $testroot/wt && got status > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
function test_unstage_patch {
local testroot=`test_init unstage_patch`
}
run_test test_unstage_basic
+run_test test_unstage_unversioned
run_test test_unstage_patch
run_test test_unstage_patch_added
run_test test_unstage_patch_removed