Fossil

Check-in [b1026f20]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fail a "fossil commit" that contains a --branch option for an open branch unless there is also a --force option.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b1026f20ccc7f966dbb513f0582f97d354063466
User & Date: drh 2017-02-06 18:30:31
Context
2017-02-06
22:31
Add '--no-dir-symlinks' command line option, which prevents traversing into symlinked directories. Make the '--verily' option to 'clean' imply '--no-dir-symlinks'. check-in: 8e659df6 user: mistachkin tags: trunk
18:30
Fail a "fossil commit" that contains a --branch option for an open branch unless there is also a --force option. check-in: b1026f20 user: drh tags: trunk
2017-02-04
19:58
Improve help text for the pull/push/sync commands. check-in: 04c6e7ee user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/branch.c.

   237    237           TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
   238    238         );
   239    239         break;
   240    240       }
   241    241     }
   242    242   }
   243    243   
          244  +/*
          245  +** If the branch named in the argument is open, return a RID for one of
          246  +** the open leaves of that branch.  If the branch does not exists or is
          247  +** closed, return 0.
          248  +*/
          249  +int branch_is_open(const char *zBrName){
          250  +  return db_int(0,
          251  +    "SELECT rid FROM tagxref AS ox"
          252  +    " WHERE tagid=%d"
          253  +    "   AND tagtype=2"
          254  +    "   AND value=%Q"
          255  +    "   AND rid IN leaf"
          256  +    "   AND NOT EXISTS(SELECT 1 FROM tagxref AS ix"
          257  +                      " WHERE tagid=%d"
          258  +                      "   AND tagtype=1"
          259  +                      "   AND ox.rid=ix.rid)",
          260  +    TAG_BRANCH, zBrName, TAG_CLOSED
          261  +  );
          262  +}
          263  +
   244    264   
   245    265   /*
   246    266   ** COMMAND: branch
   247    267   **
   248    268   ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
   249    269   **
   250    270   ** Run various subcommands to manage branches of the open repository or
   251    271   ** of the repository identified by the -R or --repository option.
   252    272   **
   253         -**    %fossil branch new BRANCH-NAME BASIS ?OPTIONS?
          273  +**    fossil branch new BRANCH-NAME BASIS ?OPTIONS?
   254    274   **
   255    275   **        Create a new branch BRANCH-NAME off of check-in BASIS.
   256    276   **        Supported options for this subcommand include:
   257    277   **        --private             branch is private (i.e., remains local)
   258    278   **        --bgcolor COLOR       use COLOR instead of automatic background
   259    279   **        --nosign              do not sign contents on this branch
   260    280   **        --date-override DATE  DATE to use instead of 'now'
................................................................................
   262    282   **
   263    283   **        DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
   264    284   **        year-month-day form, it may be truncated, the "T" may be
   265    285   **        replaced by a space, and it may also name a timezone offset
   266    286   **        from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
   267    287   **        Either no timezone suffix or "Z" means UTC.
   268    288   **
   269         -**    %fossil branch list|ls ?-a|--all|-c|--closed?
          289  +**    fossil branch list|ls ?-a|--all|-c|--closed?
   270    290   **
   271    291   **        List all branches.  Use -a or --all to list all branches and
   272    292   **        -c or --closed to list all closed branches.  The default is to
   273    293   **        show only open branches.
   274    294   **
          295  +**    fossil branch info BRANCH-NAME
          296  +**
          297  +**        Print information about a branch
          298  +**
   275    299   ** Options:
   276    300   **    -R|--repository FILE       Run commands on repository FILE
   277    301   */
   278    302   void branch_cmd(void){
   279    303     int n;
   280    304     const char *zCmd = "list";
   281    305     db_find_and_open_repository(0, 0);
................................................................................
   299    323       branch_prepare_list_query(&q, brFlags);
   300    324       while( db_step(&q)==SQLITE_ROW ){
   301    325         const char *zBr = db_column_text(&q, 0);
   302    326         int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
   303    327         fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
   304    328       }
   305    329       db_finalize(&q);
          330  +  }else if( strncmp(zCmd,"info",n)==0 ){
          331  +    int i;
          332  +    for(i=3; i<g.argc; i++){
          333  +      const char *zBrName = g.argv[i];
          334  +      int rid = branch_is_open(zBrName);
          335  +      if( rid==0 ){
          336  +        fossil_print("%s: not an open branch\n", zBrName);
          337  +      }else{
          338  +        const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
          339  +        const char *zDate = db_text(0,
          340  +          "SELECT datetime(mtime,toLocal()) FROM event"
          341  +          " WHERE objid=%d", rid);
          342  +        fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
          343  +      }
          344  +    }
   306    345     }else{
   307    346       fossil_fatal("branch subcommand should be one of: "
   308         -                 "new list ls");
          347  +                 "info list ls new");
   309    348     }
   310    349   }
   311    350   
   312    351   static const char brlistQuery[] =
   313    352   @ SELECT
   314    353   @   tagxref.value,
   315    354   @   max(event.mtime),

Changes to src/checkin.c.

  2110   2110     sCiInfo.zUserOvrd = find_option("user-override",0,1);
  2111   2111     db_must_be_within_tree();
  2112   2112     noSign = db_get_boolean("omitsign", 0)|noSign;
  2113   2113     if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
  2114   2114     useCksum = db_get_boolean("repo-cksum", 1);
  2115   2115     outputManifest = db_get_manifest_setting();
  2116   2116     verify_all_options();
         2117  +
         2118  +  /* Do not allow the creation of a new branch using an existing open
         2119  +  ** branch name unless the --force flag is used */
         2120  +  if( sCiInfo.zBranch!=0 && !forceFlag && branch_is_open(sCiInfo.zBranch) ){
         2121  +    fossil_fatal("an open branch named \"%s\" already exists - use --force"
         2122  +                 " to override", sCiInfo.zBranch);
         2123  +  }
  2117   2124   
  2118   2125     /* Escape special characters in tags and put all tags in sorted order */
  2119   2126     if( nTag ){
  2120   2127       int i;
  2121   2128       for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
  2122   2129       qsort((void*)sCiInfo.azTag, nTag, sizeof(sCiInfo.azTag[0]), tagCmp);
  2123   2130     }