commit ebf48fd51b015826a4c8227d238ec8533b15476c from: Stefan Sperling date: Sat Aug 03 18:43:55 2019 UTC handle conflicted files passed to 'got stage' commit - 98eaaa123b96d372fccac64c43af97f4cf3676df commit + ebf48fd51b015826a4c8227d238ec8533b15476c blob - 462aba4ce38cf417465bd97d2f372b539d4aed41 blob + e1049fab7c3d44ba6648ace4bb8783554328583f --- include/got_error.h +++ include/got_error.h @@ -116,6 +116,7 @@ #define GOT_ERR_COMMIT_BRANCH 100 #define GOT_ERR_FILE_STAGED 101 #define GOT_ERR_STAGE_NO_CHANGE 102 +#define GOT_ERR_STAGE_CONFLICT 103 static const struct got_error { int code; @@ -234,6 +235,7 @@ static const struct got_error { "\"refs/heads/\" reference namespace" }, { GOT_ERR_FILE_STAGED, "file is staged" }, { GOT_ERR_STAGE_NO_CHANGE, "no changes to stage" }, + { GOT_ERR_STAGE_CONFLICT, "cannot stage file in conflicted status" }, }; /* blob - e5ed395553068e0546fac6b685633f812895d00a blob + 15369994a065683b34c7ca2682d55ed64c56881e --- lib/worktree.c +++ lib/worktree.c @@ -4979,6 +4979,9 @@ stage_path(const char *relpath, const char *ondisk_pat case GOT_STATUS_NO_CHANGE: err = got_error_path(relpath, GOT_ERR_STAGE_NO_CHANGE); break; + case GOT_STATUS_CONFLICT: + err = got_error_path(relpath, GOT_ERR_STAGE_CONFLICT); + break; default: err = got_error_path(relpath, GOT_ERR_FILE_STATUS); break; blob - 2b7702717e35aabfcd8ae0f8ad15a06e9576d4c1 blob + 27af353405089f86d0d9b8197dec61b931ccaf7e --- regress/cmdline/stage.sh +++ regress/cmdline/stage.sh @@ -44,6 +44,68 @@ function test_stage_basic { test_done "$testroot" "$ret" } +function test_stage_conflict { + local testroot=`test_init stage_conflict` + local initial_commit=`git_show_head $testroot/repo` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret="$?" + if [ "$ret" != "0" ]; then + test_done "$testroot" "$ret" + return 1 + fi + + echo "modified alpha" > $testroot/wt/alpha + (cd $testroot/wt && got commit -m "modified alpha" >/dev/null) + + (cd $testroot/wt && got update -c $initial_commit > /dev/null) + + echo "modified alpha, too" > $testroot/wt/alpha + + echo "C alpha" > $testroot/stdout.expected + echo -n "Updated to commit " >> $testroot/stdout.expected + git_show_head $testroot/repo >> $testroot/stdout.expected + echo >> $testroot/stdout.expected + + (cd $testroot/wt && got update > $testroot/stdout) + + 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 alpha > $testroot/stdout \ + 2> $testroot/stderr) + ret="$?" + if [ "$ret" == "0" ]; then + echo "got stage command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + echo -n > $testroot/stdout.expected + echo "got: alpha: cannot stage file in conflicted status" \ + > $testroot/stderr.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 + 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_double_stage { local testroot=`test_init double_stage` @@ -632,6 +694,7 @@ function test_stage_diff { } run_test test_stage_basic +run_test test_stage_conflict run_test test_double_stage run_test test_stage_status run_test test_stage_add_already_staged_file