Switch to edit worktree after staging an edit master
authorChristian Thaeter <ct@pipapo.org>
Thu, 20 Mar 2008 08:37:40 +0000 (09:37 +0100)
committerChristian Thaeter <ct@pipapo.org>
Thu, 20 Mar 2008 08:37:40 +0000 (09:37 +0100)
This presents the file a user edited for re-editing when he pushed
"Stage for commit". The old way presenting just the branch head was
confusing because he didn't seen his edits.

src/actions.c
src/worktree.c

index 7cd0956..107ea17 100644 (file)
@@ -654,10 +654,18 @@ webgit_edit_action (struct webgit_query* query)
 static Html
 webgit_stage_action (struct webgit_query* query)
 {
-  (void) query;
   query->current_repo =  webgit_repo_enter (query);
   webgit_worktree_stage (query->current_repo);
   /*TODO: what to show now? tree? object? head? worktree? */
+  if (strncmp ("worktrees/", query->head, 10))
+    {
+      query->current_repo = NULL;
+      TRACE (webgit, "edit worktree from now on, not original head");
+      char* buf = cwa_malloc (strlen (query->head) + 11);
+      sprintf (buf, "worktrees/%s", query->head);
+      free (query->head);
+      query->head = buf;
+    }
   return webgit_edit_action (query);
 }
 
index 243cfb5..106f34b 100644 (file)
@@ -444,10 +444,13 @@ webgit_worktree_stage (struct webgit_repo_info* repo)
     /* no data */
     return;
 
-  /* get original tree */
+  /* get original worktree */
   char* worktree = cwa_buffer_provide (PATH_MAX);
   unsigned char sha1_tree[20];
-  snprintf (worktree, PATH_MAX, "refs/worktrees/%s", repo->query->head);
+  snprintf (worktree, PATH_MAX, "refs/%s%s",
+            strncmp ("worktrees/",
+                     repo->query->head, 10) ? "worktrees/" : "",
+            repo->query->head);
   read_ref (worktree, sha1_tree);
 
   struct commit* commit = lookup_commit_reference (sha1_tree);