commit - 88d0e355ca772bd1e7e957adbfb68c2cc8d42cbb
commit + c363b2c176847929422503bc59dede412e83f0ae
blob - 982c3c862a12ef541b601f25a5596bcc055fa219
blob + 37d1d68664b112530292c1107beaf2d6d59b2340
--- got/got.c
+++ got/got.c
const char *path, struct got_object_id *blob_id,
struct got_object_id *commit_id)
{
+ if (status == staged_status &&
+ (status == GOT_STATUS_ADD || status == GOT_STATUS_DELETE))
+ status = GOT_STATUS_NO_CHANGE;
printf("%c%c %s\n", status, staged_status, path);
return NULL;
}
blob - 9ca3668846a3c3c88f8d3f2b88205f1bb55ccc91
blob + eaffa11cd7493c261c0313a98f515371d10ebe42
--- lib/worktree.c
+++ lib/worktree.c
ie->mtime_sec == sb->st_mtime &&
ie->mtime_nsec == sb->st_mtimensec &&
ie->size == (sb->st_size & 0xffffffff));
+}
+
+static unsigned char
+get_staged_status(struct got_fileindex_entry *ie)
+{
+ switch (got_fileindex_entry_stage_get(ie)) {
+ case GOT_FILEIDX_STAGE_ADD:
+ return GOT_STATUS_ADD;
+ case GOT_FILEIDX_STAGE_DELETE:
+ return GOT_STATUS_DELETE;
+ case GOT_FILEIDX_STAGE_MODIFY:
+ return GOT_STATUS_MODIFY;
+ default:
+ return GOT_STATUS_NO_CHANGE;
+ }
}
static const struct got_error *
uint8_t fbuf[8192];
struct got_blob_object *blob = NULL;
size_t flen, blen;
+ unsigned char staged_status = get_staged_status(ie);
*status = GOT_STATUS_NO_CHANGE;
if (!stat_info_differs(ie, sb))
return NULL;
- memcpy(id.sha1, ie->blob_sha1, sizeof(id.sha1));
+ if (staged_status == GOT_STATUS_MODIFY ||
+ staged_status == GOT_STATUS_ADD)
+ memcpy(id.sha1, ie->staged_blob_sha1, sizeof(id.sha1));
+ else
+ memcpy(id.sha1, ie->blob_sha1, sizeof(id.sha1));
+
err = got_object_open_as_blob(&blob, repo, &id, sizeof(fbuf));
if (err)
return err;
void *cancel_arg;
};
-static unsigned char
-get_staged_status(struct got_fileindex_entry *ie)
-{
- switch (got_fileindex_entry_stage_get(ie)) {
- case GOT_FILEIDX_STAGE_ADD:
- return GOT_STATUS_ADD;
- case GOT_FILEIDX_STAGE_DELETE:
- return GOT_STATUS_DELETE;
- case GOT_FILEIDX_STAGE_MODIFY:
- return GOT_STATUS_MODIFY;
- default:
- return GOT_STATUS_NO_CHANGE;
- }
-}
-
static const struct got_error *
report_file_status(struct got_fileindex_entry *ie, const char *abspath,
got_worktree_status_cb status_cb, void *status_arg,
{
const struct got_error *err = NULL;
unsigned char status = GOT_STATUS_NO_CHANGE;
+ unsigned char staged_status = get_staged_status(ie);
struct stat sb;
struct got_object_id blob_id, commit_id;
err = get_file_status(&status, &sb, ie, abspath, repo);
- if (err == NULL && status != GOT_STATUS_NO_CHANGE) {
+ if (err == NULL && (status != GOT_STATUS_NO_CHANGE ||
+ staged_status != GOT_STATUS_NO_CHANGE)) {
memcpy(blob_id.sha1, ie->blob_sha1, SHA1_DIGEST_LENGTH);
memcpy(commit_id.sha1, ie->commit_sha1, SHA1_DIGEST_LENGTH);
- err = (*status_cb)(status_arg, status, get_staged_status(ie),
+ err = (*status_cb)(status_arg, status, staged_status,
ie->path, &blob_id, &commit_id);
}
return err;
blob - 0a71da3d883b97908fcb160560cf43325fa6676d
blob + 5aa544477117e7400db4bd3392d28c422359ba50
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
test_done "$testroot" "$ret"
}
+function test_stage_status {
+ local testroot=`test_init stage_status`
+
+ 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 "new file" > $testroot/wt/epsilon/new
+ (cd $testroot/wt && got add epsilon/new > /dev/null)
+ echo "modified file" > $testroot/wt/epsilon/zeta
+ (cd $testroot/wt && got rm gamma/delta > /dev/null)
+
+ echo ' M alpha' > $testroot/stdout.expected
+ echo ' D beta' >> $testroot/stdout.expected
+ echo 'A epsilon/new' >> $testroot/stdout.expected
+ echo 'M epsilon/zeta' >> $testroot/stdout.expected
+ echo ' A foo' >> $testroot/stdout.expected
+ echo 'D gamma/delta' >> $testroot/stdout.expected
+ (cd $testroot/wt && got stage alpha beta foo > /dev/null)
+
+ (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"
+}
+
run_test test_stage_basic
+run_test test_stage_status