handle conflicted files passed to 'got stage'
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
diff --git a/include/got_error.h b/include/got_error.h
index 462aba4..e1049fa 100644
--- a/include/got_error.h
+++ b/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" },
};
/*
diff --git a/lib/worktree.c b/lib/worktree.c
index e5ed395..1536999 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -4979,6 +4979,9 @@ stage_path(const char *relpath, const char *ondisk_path,
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;
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index 2b77027..27af353 100755
--- a/regress/cmdline/stage.sh
+++ b/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